From 6fe67c0db0a50c3ef292c96ed92f40bac3735cb2 Mon Sep 17 00:00:00 2001 From: Steven Levithan Date: Fri, 14 Jun 2024 20:27:48 +0200 Subject: [PATCH 1/3] Clarify that minimal escaping is done and describe edge cases (#40) --- readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/readme.md b/readme.md index 839df6e..4a49190 100644 --- a/readme.md +++ b/readme.md @@ -21,6 +21,8 @@ new RegExp(escapedString); You can also use this to escape a string that is inserted into the middle of a regex, for example, into a character class. +Only the minimal amount of escaping is done, and developers are expected to insert escaped strings at safe positions in a `RegExp`. This keeps the output simple and gives you the best results in most cases. For edge case placements of escaped strings (such as immediately following `\0` or `\c`), the escaped value can change the meaning of the preceding or following token. If fully context-aware escaping is needed, consider interpolating a string using the [`regex`](https://github.com/slevithan/regex#interpolating-escaped-strings) package. + ---
From 6ced614edea7cabc72a8973108659b3cdb75e30e Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Fri, 14 Jun 2024 20:29:27 +0200 Subject: [PATCH 2/3] Meta tweaks --- .github/funding.yml | 4 ---- .github/workflows/main.yml | 4 ++-- package.json | 2 ++ readme.md | 16 ++-------------- 4 files changed, 6 insertions(+), 20 deletions(-) delete mode 100644 .github/funding.yml diff --git a/.github/funding.yml b/.github/funding.yml deleted file mode 100644 index 5bc8a3d..0000000 --- a/.github/funding.yml +++ /dev/null @@ -1,4 +0,0 @@ -github: sindresorhus -open_collective: sindresorhus -tidelift: npm/escape-string-regexp -custom: https://sindresorhus.com/donate diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d36e1a8..087b412 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,8 +13,8 @@ jobs: - 14 - 12 steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - run: npm install diff --git a/package.json b/package.json index 9390a6b..168e9a6 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,8 @@ }, "type": "module", "exports": "./index.js", + "types": "./index.d.ts", + "sideEffects": false, "engines": { "node": ">=12" }, diff --git a/readme.md b/readme.md index 4a49190..786601c 100644 --- a/readme.md +++ b/readme.md @@ -4,8 +4,8 @@ ## Install -``` -$ npm install escape-string-regexp +```sh +npm install escape-string-regexp ``` ## Usage @@ -22,15 +22,3 @@ new RegExp(escapedString); You can also use this to escape a string that is inserted into the middle of a regex, for example, into a character class. Only the minimal amount of escaping is done, and developers are expected to insert escaped strings at safe positions in a `RegExp`. This keeps the output simple and gives you the best results in most cases. For edge case placements of escaped strings (such as immediately following `\0` or `\c`), the escaped value can change the meaning of the preceding or following token. If fully context-aware escaping is needed, consider interpolating a string using the [`regex`](https://github.com/slevithan/regex#interpolating-escaped-strings) package. - ---- - -
- - Get professional support for this package with a Tidelift subscription - -
- - Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies. -
-
From cbc42403142c96923b482604e1f3d627b1956aff Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Tue, 6 May 2025 22:42:06 +0700 Subject: [PATCH 3/3] Document native API --- readme.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/readme.md b/readme.md index 786601c..8b7890f 100644 --- a/readme.md +++ b/readme.md @@ -2,6 +2,9 @@ > Escape RegExp special characters +> [!TIP] +> This is now available natively as [`RegExp.escape()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/escape). + ## Install ```sh