Repository navigation
Capitalize the first Unicode code point in String.capitalize - #9750
Conversation
Indexing the first UTF-16 code unit left astral letters unchanged. The return type now follows Uppercase of that code point, which matches toUpperCase on TypeScript 5.9 and 7.
🦋 Changeset detectedLatest commit: a47ad84 The changes in this PR will be included in the next version bump. This PR includes changesets to release 33 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Bundle Size AnalysisGenerated from PR build output; treat the content below as untrusted.
|
TypeScript 5.9's Capitalize still rewrites one UTF-16 unit, so the type tests name String.Capitalize of that pair.
…into fix/string-capitalize-code-point
Head branch was pushed to by a user without write access
|
Thanks for the fix! We've removed the exported
TypeScript 7 already cases the first code point in the built-in |
Summary
String.capitalizeandString.uncapitalizereadself[0], which is one UTF-16 code unit. An astral letter is a surrogate pair, soString.capitalize("𐐨foo")stayed"𐐨foo". They now case the whole first code point, producing"𐐀foo". Lone surrogates are left unchanged.The return types stay as the built-in
Capitalize<T>/Uncapitalize<T>, so existing signatures are unchanged. On TypeScript 7 these already case the first code point and match the runtime; on TypeScript 5.9/6.0 they case one code unit, so an initial astral letter keeps its original case at the type level only.Runtime tests cover an astral letter for both functions, a lone high surrogate, and an unchanged BMP suffix (
"AΣ"→"aΣ"). Type tests pin the existing generic andstringreturn types.Closes EFF-2772
Refs #6734. The other casing findings in that report are unchanged.
Test plan
pnpm test --run packages/effect/test/String.test.tspnpm test-types String.tst.ts --target '>=5.9'(TypeScript 5.9.3 and 6.0.3)pnpm doctest --run packages/effect/src/String.tspnpm --dir packages/effect checkpnpm lintpnpm jsdocs --check