Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 11 additions & 0 deletions src/compat/string/startCase.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,15 @@ describe('startCase', () => {
expect(startCase('top10th')).toBe('Top 10th');
expect(startCase('1st place 2nd 3rd 4th')).toBe('1st Place 2nd 3rd 4th');
});

it('should only uppercase the first letter of each word', () => {
expect(startCase('ПриветМир')).toBe('ПриветМир');
expect(startCase('αβγΔεζ')).toBe('ΑβγΔεζ');
expect(startCase('fooBAR')).toBe('Foo BAR');
expect(startCase('mIxEd CaSe')).toBe('M Ix Ed Ca Se');
});

it('should uppercase a first letter outside the Basic Multilingual Plane', () => {
expect(startCase('𐐨𐐩 deseret')).toBe('𐐀 𐐁 Deseret');
});
});
10 changes: 6 additions & 4 deletions src/compat/string/startCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ export function startCase(str?: string): string {
result += ' ';
}

if (word === word.toUpperCase()) {
result += word;
} else {
result += word[0].toUpperCase() + word.slice(1).toLowerCase();
let firstLength = 1;

if (word.codePointAt(0)! > 0xffff) {
firstLength = 2;
}

result += word.slice(0, firstLength).toUpperCase() + word.slice(firstLength);
}

return result;
Expand Down
Loading