Skip to content

Commit ea98098

Browse files
BendingBendersindresorhus
authored andcommitted
Require Node.js 8, add TypeScript definition (#13)
1 parent db124a3 commit ea98098

12 files changed

+82
-75
lines changed

.editorconfig

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ charset = utf-8
77
trim_trailing_whitespace = true
88
insert_final_newline = true
99

10-
[{package.json,*.yml}]
10+
[*.yml]
1111
indent_style = space
1212
indent_size = 2
13-
14-
[*.md]
15-
trim_trailing_whitespace = false

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* text=auto
1+
* text=auto eol=lf

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules
2+
yarn.lock

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

.travis.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
sudo: false
21
language: node_js
32
node_js:
4-
- 'stable'
5-
- '0.12'
6-
- '0.10'
3+
- '10'
4+
- '8'

index.d.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
Escape RegExp special characters.
3+
4+
@example
5+
```
6+
import escapeStringRegexp = require('escape-string-regexp');
7+
8+
const escapedString = escapeStringRegexp('how much $ for a 🦄?');
9+
//=> 'how much \\$ for a 🦄\\?'
10+
11+
new RegExp(escapedString);
12+
```
13+
*/
14+
declare const escapeStringRegexp: (str: string) => string;
15+
16+
export = escapeStringRegexp;

index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'use strict';
22

3-
var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;
3+
const matchOperatorsRegex = /[|\\{}()[\]^$+*?.]/g;
44

5-
module.exports = function (str) {
6-
if (typeof str !== 'string') {
5+
module.exports = string => {
6+
if (typeof string !== 'string') {
77
throw new TypeError('Expected a string');
88
}
99

10-
return str.replace(matchOperatorsRe, '\\$&');
10+
return string.replace(matchOperatorsRegex, '\\$&');
1111
};

index.test-d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import {expectType} from 'tsd';
2+
import escapeStringRegexp = require('.');
3+
4+
expectType<string>(escapeStringRegexp('how much $ for a 🦄?'));

license

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
1-
The MIT License (MIT)
1+
MIT License
22

33
Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com)
44

5-
Permission is hereby granted, free of charge, to any person obtaining a copy
6-
of this software and associated documentation files (the "Software"), to deal
7-
in the Software without restriction, including without limitation the rights
8-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
copies of the Software, and to permit persons to whom the Software is
10-
furnished to do so, subject to the following conditions:
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
116

12-
The above copyright notice and this permission notice shall be included in
13-
all copies or substantial portions of the Software.
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
148

15-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21-
THE SOFTWARE.
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

package.json

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,43 @@
11
{
2-
"name": "escape-string-regexp",
3-
"version": "1.0.5",
4-
"description": "Escape RegExp special characters",
5-
"license": "MIT",
6-
"repository": "sindresorhus/escape-string-regexp",
7-
"author": {
8-
"name": "Sindre Sorhus",
9-
"email": "[email protected]",
10-
"url": "sindresorhus.com"
11-
},
12-
"maintainers": [
13-
"Sindre Sorhus <[email protected]> (sindresorhus.com)",
14-
"Joshua Boy Nicolai Appelman <[email protected]> (jbna.nl)"
15-
],
16-
"engines": {
17-
"node": ">=0.8.0"
18-
},
19-
"scripts": {
20-
"test": "xo && ava"
21-
},
22-
"files": [
23-
"index.js"
24-
],
25-
"keywords": [
26-
"escape",
27-
"regex",
28-
"regexp",
29-
"re",
30-
"regular",
31-
"expression",
32-
"string",
33-
"str",
34-
"special",
35-
"characters"
36-
],
37-
"devDependencies": {
38-
"ava": "*",
39-
"xo": "*"
40-
}
2+
"name": "escape-string-regexp",
3+
"version": "1.0.5",
4+
"description": "Escape RegExp special characters",
5+
"license": "MIT",
6+
"repository": "sindresorhus/escape-string-regexp",
7+
"author": {
8+
"name": "Sindre Sorhus",
9+
"email": "[email protected]",
10+
"url": "sindresorhus.com"
11+
},
12+
"maintainers": [
13+
"Sindre Sorhus <[email protected]> (sindresorhus.com)",
14+
"Joshua Boy Nicolai Appelman <[email protected]> (jbna.nl)"
15+
],
16+
"engines": {
17+
"node": ">=8"
18+
},
19+
"scripts": {
20+
"test": "xo && ava && tsd"
21+
},
22+
"files": [
23+
"index.js",
24+
"index.d.ts"
25+
],
26+
"keywords": [
27+
"escape",
28+
"regex",
29+
"regexp",
30+
"re",
31+
"regular",
32+
"expression",
33+
"string",
34+
"str",
35+
"special",
36+
"characters"
37+
],
38+
"devDependencies": {
39+
"ava": "^1.4.1",
40+
"tsd": "^0.7.2",
41+
"xo": "^0.24.0"
42+
}
4143
}

readme.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
## Install
77

88
```
9-
$ npm install --save escape-string-regexp
9+
$ npm install escape-string-regexp
1010
```
1111

1212

@@ -15,13 +15,13 @@ $ npm install --save escape-string-regexp
1515
```js
1616
const escapeStringRegexp = require('escape-string-regexp');
1717

18-
const escapedString = escapeStringRegexp('how much $ for a unicorn?');
19-
//=> 'how much \$ for a unicorn\?'
18+
const escapedString = escapeStringRegexp('how much $ for a 🦄?');
19+
//=> 'how much \\$ for a 🦄\\?'
2020

2121
new RegExp(escapedString);
2222
```
2323

2424

2525
## License
2626

27-
MIT © [Sindre Sorhus](http://sindresorhus.com)
27+
MIT © [Sindre Sorhus](https://sindresorhus.com)

test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import test from 'ava';
2-
import fn from './';
2+
import escapeStringRegexp from '.';
33

4-
test(t => {
4+
test('main', t => {
55
t.is(
6-
fn('\\ ^ $ * + ? . ( ) | { } [ ]'),
6+
escapeStringRegexp('\\ ^ $ * + ? . ( ) | { } [ ]'),
77
'\\\\ \\^ \\$ \\* \\+ \\? \\. \\( \\) \\| \\{ \\} \\[ \\]'
88
);
99
});

0 commit comments

Comments
 (0)