Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Split by case should take space into account #98

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
} from "./types";

const NUMBER_CHAR_RE = /\d/;
const STR_SPLITTERS = ["-", "_", "/", "."] as const;
const STR_SPLITTERS = ["-", "_", "/", ".", " "] as const;

export function isUppercase(char = ""): boolean | undefined {
if (NUMBER_CHAR_RE.test(char)) {
Expand Down Expand Up @@ -186,8 +186,8 @@ export function titleCase<
>(str?: T, opts?: UserCaseOptions) {
return (Array.isArray(str) ? str : splitByCase(str as string))
.filter(Boolean)
.map((p) =>
titleCaseExceptions.test(p)
.map((p, i) =>
i && titleCaseExceptions.test(p)
noootwo marked this conversation as resolved.
Show resolved Hide resolved
? p.toLowerCase()
: upperFirst(opts?.normalize ? p.toLowerCase() : p),
)
Expand Down
2 changes: 2 additions & 0 deletions test/scule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ describe("titleCase", () => {
["foo", "Foo"],
["foo-bar", "Foo Bar"],
["this-IS-aTitle", "This is a Title"],
["is_this ATitle", "Is This a Title"],
["hello, world!", "Hello, World!"],
])("%s => %s", (input, expected) => {
expect(titleCase(input)).toMatchObject(expected);
});
Expand Down