From aebb6e8e5cc904e7f8db20445ff0879c40d34db0 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sat, 17 Apr 2021 22:44:54 +0700 Subject: [PATCH] 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(