Skip to content

Commit

Permalink
Remove lookbehind from regex
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey committed Jan 10, 2024
1 parent 17a27ce commit 6512635
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
20 changes: 20 additions & 0 deletions packages/change-case/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
{
Expand Down
5 changes: 3 additions & 2 deletions packages/change-case/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6512635

Please sign in to comment.