Skip to content

Commit

Permalink
fix(titleCase): remove unexpected space
Browse files Browse the repository at this point in the history
  • Loading branch information
ntnyq committed Nov 20, 2024
1 parent 863bc75 commit 0a24e2d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ export function titleCase<
>(str?: T, opts?: UserCaseOptions) {
return (Array.isArray(str) ? str : splitByCase(str as string))
.filter(Boolean)
.map((p) => p.trim())
.map((p) =>
titleCaseExceptions.test(p)
? p.toLowerCase()
Expand Down
9 changes: 9 additions & 0 deletions test/scule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ describe("pascalCase", () => {
["foo_bar-baz/qux", "FooBarBazQux"],
["FOO_BAR", "FooBar"],
["foo--bar-Baz", "FooBarBaz"],
["FooBarBazQux", "FooBarBazQux"],
])("%s => %s", (input, expected) => {
expect(pascalCase(input, { normalize: true })).toMatchObject(expected);
});
Expand All @@ -59,6 +60,7 @@ describe("camelCase", () => {
test.each([
["FooBarBaz", "fooBarBaz"],
["FOO_BAR", "fooBar"],
["fooBarBaz", "fooBarBaz"],
])("%s => %s", (input, expected) => {
expect(camelCase(input, { normalize: true })).toMatchObject(expected);
});
Expand All @@ -74,6 +76,7 @@ describe("kebabCase", () => {
["FooBAR", "foo-bar"],
["ALink", "a-link"],
["FOO_BAR", "foo-bar"],
["foo-b-ar", "foo-b-ar"],
])("%s => %s", (input, expected) => {
expect(kebabCase(input)).toMatchObject(expected);
});
Expand All @@ -83,6 +86,7 @@ describe("snakeCase", () => {
test.each([
["FooBarBaz", "foo_bar_baz"],
["FOO_BAR", "foo_bar"],
["foo_bar_baz", "foo_bar_baz"],
])("%s => %s", (input, expected) => {
expect(snakeCase(input)).toMatchObject(expected);
});
Expand All @@ -93,6 +97,7 @@ describe("upperFirst", () => {
["", ""],
["foo", "Foo"],
["Foo", "Foo"],
["FooBarBaz", "FooBarBaz"],
])("%s => %s", (input, expected) => {
expect(upperFirst(input)).toMatchObject(expected);
});
Expand All @@ -103,6 +108,7 @@ describe("lowerFirst", () => {
["", ""],
["foo", "foo"],
["Foo", "foo"],
["fooBarBaz", "fooBarBaz"],
])("%s => %s", (input, expected) => {
expect(lowerFirst(input)).toMatchObject(expected);
});
Expand All @@ -120,6 +126,7 @@ describe("trainCase", () => {
["foo--bar-Baz", "Foo-Bar-Baz"],
["WWW-authenticate", "WWW-Authenticate"],
["WWWAuthenticate", "WWW-Authenticate"],
["Foo-B-Ar", "Foo-B-Ar"],
])("%s => %s", (input, expected) => {
expect(trainCase(input)).toMatchObject(expected);
});
Expand All @@ -140,6 +147,7 @@ describe("titleCase", () => {
["foo", "Foo"],
["foo-bar", "Foo Bar"],
["this-IS-aTitle", "This is a Title"],
["Foo Bar", "Foo Bar"],
])("%s => %s", (input, expected) => {
expect(titleCase(input)).toMatchObject(expected);
});
Expand All @@ -154,6 +162,7 @@ describe("flatCase", () => {
["foo_bar-baz/qux", "foobarbazqux"],
["FOO_BAR", "foobar"],
["foo--bar-Baz", "foobarbaz"],
["foobarbaz", "foobarbaz"],
])("%s => %s", (input, expected) => {
expect(flatCase(input)).toMatchObject(expected);
});
Expand Down

0 comments on commit 0a24e2d

Please sign in to comment.