diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..d36e1a8 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,21 @@ +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 + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + 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/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 387c561..9ce9323 100644 --- a/index.js +++ b/index.js @@ -1,13 +1,11 @@ -'use strict'; - -module.exports = string => { +export default function escapeStringRegexp(string) { if (typeof string !== 'string') { throw new TypeError('Expected a 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'); -}; +} 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..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", @@ -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 2945dfc..839df6e 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 @@ -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(