From b3eb767656fe6dbb8c8dbf31746171cfb7b23b78 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Tue, 9 Jun 2020 16:22:44 +0800 Subject: [PATCH 1/4] Fix code comment --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 387c561..b8c4d38 100644 --- a/index.js +++ b/index.js @@ -6,7 +6,7 @@ module.exports = string => { } // Escape characters with special meaning either inside or outside character sets. - // Use a simple backslash escape when it’s always valid, and a \unnnn escape when the simpler form would be disallowed by Unicode patterns’ stricter grammar. + // Use a simple backslash escape when it’s always valid, and a `\xnn` escape when the simpler form would be disallowed by Unicode patterns’ stricter grammar. return string .replace(/[|\\{}()[\]^$+*?.]/g, '\\$&') .replace(/-/g, '\\x2d'); From 34ec4c63f8719f585c7a61d7cf41e825fb3c8cb3 Mon Sep 17 00:00:00 2001 From: Richie Bendall Date: Sat, 2 Jan 2021 04:27:06 +1300 Subject: [PATCH 2/4] Move to GitHub Actions (#31) --- .github/workflows/main.yml | 22 ++++++++++++++++++++++ .travis.yml | 4 ---- readme.md | 2 +- 3 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/main.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..c1870cf --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,22 @@ +name: CI +on: + - push + - pull_request +jobs: + test: + name: Node.js ${{ matrix.node-version }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + node-version: + - 14 + - 12 + - 10 + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - run: npm install + - run: npm test diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 94ab01f..0000000 --- a/.travis.yml +++ /dev/null @@ -1,4 +0,0 @@ -language: node_js -node_js: - - '12' - - '10' diff --git a/readme.md b/readme.md index 2945dfc..b5e172f 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -# escape-string-regexp [![Build Status](https://travis-ci.org/sindresorhus/escape-string-regexp.svg?branch=master)](https://travis-ci.org/sindresorhus/escape-string-regexp) +# escape-string-regexp > Escape RegExp special characters From aebb6e8e5cc904e7f8db20445ff0879c40d34db0 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sat, 17 Apr 2021 22:44:54 +0700 Subject: [PATCH 3/4] Require Node.js 12 and move to ESM --- .github/workflows/main.yml | 3 +-- index.d.ts | 6 ++---- index.js | 6 ++---- index.test-d.ts | 2 +- package.json | 10 ++++++---- readme.md | 2 +- test.js | 2 +- 7 files changed, 14 insertions(+), 17 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c1870cf..d36e1a8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,10 +12,9 @@ jobs: node-version: - 14 - 12 - - 10 steps: - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 + - uses: actions/setup-node@v2 with: node-version: ${{ matrix.node-version }} - run: npm install diff --git a/index.d.ts b/index.d.ts index 7d34edc..e8f9288 100644 --- a/index.d.ts +++ b/index.d.ts @@ -5,7 +5,7 @@ You can also use this to escape a string that is inserted into the middle of a r @example ``` -import escapeStringRegexp = require('escape-string-regexp'); +import escapeStringRegexp from 'escape-string-regexp'; const escapedString = escapeStringRegexp('How much $ for a 🦄?'); //=> 'How much \\$ for a 🦄\\?' @@ -13,6 +13,4 @@ const escapedString = escapeStringRegexp('How much $ for a 🦄?'); new RegExp(escapedString); ``` */ -declare const escapeStringRegexp: (string: string) => string; - -export = escapeStringRegexp; +export default function escapeStringRegexp(string: string): string; diff --git a/index.js b/index.js index b8c4d38..9ce9323 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,4 @@ -'use strict'; - -module.exports = string => { +export default function escapeStringRegexp(string) { if (typeof string !== 'string') { throw new TypeError('Expected a string'); } @@ -10,4 +8,4 @@ module.exports = string => { return string .replace(/[|\\{}()[\]^$+*?.]/g, '\\$&') .replace(/-/g, '\\x2d'); -}; +} diff --git a/index.test-d.ts b/index.test-d.ts index 2915492..ed10b00 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,4 +1,4 @@ import {expectType} from 'tsd'; -import escapeStringRegexp = require('.'); +import escapeStringRegexp from './index.js'; expectType(escapeStringRegexp('how much $ for a 🦄?')); diff --git a/package.json b/package.json index c6eb4a9..797209f 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,10 @@ "email": "sindresorhus@gmail.com", "url": "https://sindresorhus.com" }, + "type": "module", + "exports": "./index.js", "engines": { - "node": ">=10" + "node": ">=12" }, "scripts": { "test": "xo && ava && tsd" @@ -31,8 +33,8 @@ "characters" ], "devDependencies": { - "ava": "^1.4.1", - "tsd": "^0.11.0", - "xo": "^0.28.3" + "ava": "^3.15.0", + "tsd": "^0.14.0", + "xo": "^0.38.2" } } diff --git a/readme.md b/readme.md index b5e172f..839df6e 100644 --- a/readme.md +++ b/readme.md @@ -11,7 +11,7 @@ $ npm install escape-string-regexp ## Usage ```js -const escapeStringRegexp = require('escape-string-regexp'); +import escapeStringRegexp from 'escape-string-regexp'; const escapedString = escapeStringRegexp('How much $ for a 🦄?'); //=> 'How much \\$ for a 🦄\\?' diff --git a/test.js b/test.js index e50f40b..453e8dd 100644 --- a/test.js +++ b/test.js @@ -1,5 +1,5 @@ import test from 'ava'; -import escapeStringRegexp from '.'; +import escapeStringRegexp from './index.js'; test('main', t => { t.is( From ba9a4473850cb367936417e97f1f2191b7cc67dd Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sat, 17 Apr 2021 22:45:39 +0700 Subject: [PATCH 4/4] 5.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 797209f..9390a6b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "escape-string-regexp", - "version": "4.0.0", + "version": "5.0.0", "description": "Escape RegExp special characters", "license": "MIT", "repository": "sindresorhus/escape-string-regexp",