From 976fa360a5cd5f123dd73be7b818df9a74e35ab5 Mon Sep 17 00:00:00 2001 From: Victor Fernandez Date: Fri, 13 Sep 2024 19:50:37 -0300 Subject: [PATCH] Fix capitalizing words that start with numbers (#346) --- packages/title-case/src/index.spec.ts | 2 ++ packages/title-case/src/index.ts | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/title-case/src/index.spec.ts b/packages/title-case/src/index.spec.ts index df1fe328..152dd35f 100644 --- a/packages/title-case/src/index.spec.ts +++ b/packages/title-case/src/index.spec.ts @@ -144,6 +144,8 @@ const TEST_CASES: [string, string, Options?][] = [ 'An example. "I.e. test."', { sentenceCase: true }, ], + ["friday the 13th", "Friday the 13th"], + ["21st century", "21st Century"], ]; describe("swap case", () => { diff --git a/packages/title-case/src/index.ts b/packages/title-case/src/index.ts index f260ba82..d9dfdd09 100644 --- a/packages/title-case/src/index.ts +++ b/packages/title-case/src/index.ts @@ -1,7 +1,7 @@ const TOKENS = /(\S+)|(.)/g; const IS_SPECIAL_CASE = /[\.#]\p{Alphabetic}/u; // #tag, example.com, etc. const IS_MANUAL_CASE = /\p{Ll}(?=[\p{Lu}])/u; // iPhone, iOS, etc. -const ALPHANUMERIC_PATTERN = /\p{Alphabetic}+/gu; +const ALPHANUMERIC_PATTERN = /[\p{Alphabetic}\p{Nd}]+/gu; const IS_ACRONYM = /^(\P{Alphabetic})*(?:\p{Alphabetic}\.){2,}(\P{Alphabetic})*$/u;