Skip to content

Commit

Permalink
Require Node.js 12 and move to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Apr 17, 2021
1 parent 34ec4c6 commit aebb6e8
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 17 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/main.yml
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions index.d.ts
Expand Up @@ -5,14 +5,12 @@ 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 🦄\\?'
new RegExp(escapedString);
```
*/
declare const escapeStringRegexp: (string: string) => string;

export = escapeStringRegexp;
export default function escapeStringRegexp(string: string): string;
6 changes: 2 additions & 4 deletions 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');
}
Expand All @@ -10,4 +8,4 @@ module.exports = string => {
return string
.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&')
.replace(/-/g, '\\x2d');
};
}
2 changes: 1 addition & 1 deletion index.test-d.ts
@@ -1,4 +1,4 @@
import {expectType} from 'tsd';
import escapeStringRegexp = require('.');
import escapeStringRegexp from './index.js';

expectType<string>(escapeStringRegexp('how much $ for a 🦄?'));
10 changes: 6 additions & 4 deletions package.json
Expand Up @@ -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"
Expand All @@ -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"
}
}
2 changes: 1 addition & 1 deletion readme.md
Expand Up @@ -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 🦄\\?'
Expand Down
2 changes: 1 addition & 1 deletion test.js
@@ -1,5 +1,5 @@
import test from 'ava';
import escapeStringRegexp from '.';
import escapeStringRegexp from './index.js';

test('main', t => {
t.is(
Expand Down

0 comments on commit aebb6e8

Please sign in to comment.