@rauschma/helpers
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -29,8 +29,12 @@ const { raw } = String; | ||
/** | ||
* - Based on {@link https://github.com/tc39/proposal-regex-escaping/blob/main/EscapedChars.md|this list} | ||
* - Based on | ||
* {@link https://github.com/tc39/proposal-regex-escaping/blob/main/EscapedChars.md this list} | ||
* - Ignored: escaping text for `eval()` | ||
* - Changes needed for upcoming `/v` flag: {@link https://github.com/tc39/proposal-regexp-v-flag/issues/71} | ||
* - Changes needed for upcoming `/v` flag: | ||
* {@link https://github.com/tc39/proposal-regexp-v-flag/issues/71} | ||
*/ | ||
const specialAnywhere = [ | ||
raw `\^`, raw `\$`, | ||
// We escape all characters even though they are put inside a character | ||
// class, to be ready for future changes. | ||
raw `\^`, raw `$`, | ||
raw `\\`, | ||
@@ -41,9 +45,12 @@ raw `\.`, | ||
raw `\|`, | ||
raw `\-`, // inside character classes (square brackets) | ||
// Omitted – not allowed by /u | ||
// raw`\-`, // inside character classes (square brackets) | ||
]; | ||
// Only first character of string needs to be escaped in these cases: | ||
const specialAtStart = [ | ||
// Alas, both cases have to be omitted because they are not allowed by /u | ||
// - Decimal digits: inserting after (e.g.) `\1` | ||
// - All (hex digits): inserting after (e.g.) `\u004` | ||
raw `0-9a-fA-F`, | ||
// - Hex digits: inserting after (e.g.) `\u004` | ||
// `0-9A-Za-z`, | ||
``, | ||
]; | ||
@@ -50,0 +57,0 @@ const re_specialCharacters = new RegExp(raw `[${specialAnywhere.join('')}]|^[${specialAtStart.join('')}]`, 'g'); |
{ | ||
"name": "@rauschma/helpers", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -31,8 +31,12 @@ const {raw} = String; | ||
/** | ||
* - Based on {@link https://github.com/tc39/proposal-regex-escaping/blob/main/EscapedChars.md|this list} | ||
* - Based on | ||
* {@link https://github.com/tc39/proposal-regex-escaping/blob/main/EscapedChars.md this list} | ||
* - Ignored: escaping text for `eval()` | ||
* - Changes needed for upcoming `/v` flag: {@link https://github.com/tc39/proposal-regexp-v-flag/issues/71} | ||
* - Changes needed for upcoming `/v` flag: | ||
* {@link https://github.com/tc39/proposal-regexp-v-flag/issues/71} | ||
*/ | ||
const specialAnywhere = [ | ||
raw`\^`, raw`\$`, | ||
// We escape all characters even though they are put inside a character | ||
// class, to be ready for future changes. | ||
raw`\^`, raw`$`, | ||
raw`\\`, | ||
@@ -43,9 +47,12 @@ raw`\.`, | ||
raw`\|`, | ||
raw`\-`, // inside character classes (square brackets) | ||
// Omitted – not allowed by /u | ||
// raw`\-`, // inside character classes (square brackets) | ||
]; | ||
// Only first character of string needs to be escaped in these cases: | ||
const specialAtStart = [ | ||
// Alas, both cases have to be omitted because they are not allowed by /u | ||
// - Decimal digits: inserting after (e.g.) `\1` | ||
// - All (hex digits): inserting after (e.g.) `\u004` | ||
raw`0-9a-fA-F`, | ||
// - Hex digits: inserting after (e.g.) `\u004` | ||
// `0-9A-Za-z`, | ||
``, | ||
]; | ||
@@ -52,0 +59,0 @@ const re_specialCharacters = new RegExp( |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
97506
1758