diff --git a/packages/change-case/src/index.spec.ts b/packages/change-case/src/index.spec.ts index e4a5c905..14152e8a 100644 --- a/packages/change-case/src/index.spec.ts +++ b/packages/change-case/src/index.spec.ts @@ -208,6 +208,26 @@ const tests: [string, Result, Options?][] = [ separateNumbers: true, }, ], + [ + "𝒳123", + { + camelCase: "𝒳_123", + capitalCase: "𝒳 123", + constantCase: "𝒳_123", + dotCase: "𝒳.123", + kebabCase: "𝒳-123", + noCase: "𝒳 123", + pascalCase: "𝒳_123", + pascalSnakeCase: "𝒳_123", + pathCase: "𝒳/123", + sentenceCase: "𝒳 123", + snakeCase: "𝒳_123", + trainCase: "𝒳-123", + }, + { + separateNumbers: true, + }, + ], [ "1test", { diff --git a/packages/change-case/src/index.ts b/packages/change-case/src/index.ts index 6bee8053..a84701f2 100644 --- a/packages/change-case/src/index.ts +++ b/packages/change-case/src/index.ts @@ -3,7 +3,7 @@ const SPLIT_LOWER_UPPER_RE = /([\p{Ll}\d])(\p{Lu})/gu; const SPLIT_UPPER_UPPER_RE = /(\p{Lu})([\p{Lu}][\p{Ll}])/gu; // Used to iterate over the initial split result and separate numbers. -const SPLIT_SEPARATE_NUMBER_RE = /(?<=\d)(\p{Ll})|(?<=\p{L})(\d)/u; +const SPLIT_SEPARATE_NUMBER_RE = /(\d)\p{Ll}|(\p{L})\d/u; // Regexp involved with stripping non-word characters from the result. const DEFAULT_STRIP_REGEXP = /[^\p{L}\d]+/giu; @@ -72,7 +72,8 @@ export function splitSeparateNumbers(value: string) { const word = words[i]; const match = SPLIT_SEPARATE_NUMBER_RE.exec(word); if (match) { - words.splice(i, 1, word.slice(0, match.index), word.slice(match.index)); + const offset = match.index + (match[1] ?? match[2]).length; + words.splice(i, 1, word.slice(0, offset), word.slice(offset)); } } return words;