tiny-escape 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -28
- package/package.json +38 -11
package/README.md
CHANGED
|
@@ -5,31 +5,19 @@
|
|
|
5
5
|
[](https://github.com/ofershap/tiny-escape/actions/workflows/ci.yml)
|
|
6
6
|
[](https://www.typescriptlang.org/)
|
|
7
7
|
[](https://opensource.org/licenses/MIT)
|
|
8
|
-
[](https://github.com/ofershap/tiny-escape)
|
|
9
|
-
[](https://github.com/ofershap/tiny-escape)
|
|
10
8
|
|
|
11
|
-
Escape special characters in a string for use in a regular expression.
|
|
9
|
+
Escape special characters in a string for use in a regular expression. Same behavior as [`escape-string-regexp`](https://github.com/sindresorhus/escape-string-regexp), but ships both ESM and CJS.
|
|
12
10
|
|
|
13
11
|
```ts
|
|
14
12
|
import { escapeRegExp } from "tiny-escape";
|
|
15
13
|
|
|
16
14
|
const input = "price is $5.00 (USD)";
|
|
17
|
-
|
|
18
|
-
re.test(input); // true
|
|
15
|
+
new RegExp(escapeRegExp(input)).test(input); // true
|
|
19
16
|
```
|
|
20
17
|
|
|
21
|
-
>
|
|
18
|
+
> 201 bytes gzipped. Zero dependencies.
|
|
22
19
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
[`escape-string-regexp`](https://github.com/sindresorhus/escape-string-regexp) has 163M weekly downloads but hasn't been updated in 3 years. Version 5 went ESM-only, breaking CommonJS consumers and forcing many projects to pin v4. `tiny-escape` ships both ESM and CJS with native TypeScript types.
|
|
26
|
-
|
|
27
|
-
| | `escape-string-regexp` | `tiny-escape` |
|
|
28
|
-
|---|---|---|
|
|
29
|
-
| CJS support | v4 only (v5 ESM-only) | ESM + CJS |
|
|
30
|
-
| TypeScript | native (v5) | native |
|
|
31
|
-
| Maintenance | inactive (3 years) | active |
|
|
32
|
-
| API | default export | named export |
|
|
20
|
+

|
|
33
21
|
|
|
34
22
|
## Install
|
|
35
23
|
|
|
@@ -42,24 +30,23 @@ npm install tiny-escape
|
|
|
42
30
|
```ts
|
|
43
31
|
import { escapeRegExp } from "tiny-escape";
|
|
44
32
|
|
|
45
|
-
escapeRegExp("hello.world");
|
|
46
|
-
escapeRegExp("[test] (1+1)");
|
|
47
|
-
escapeRegExp("foo|bar");
|
|
48
|
-
escapeRegExp("a-b");
|
|
33
|
+
escapeRegExp("hello.world"); // "hello\\.world"
|
|
34
|
+
escapeRegExp("[test] (1+1)"); // "\\[test\\] \\(1\\+1\\)"
|
|
35
|
+
escapeRegExp("foo|bar"); // "foo\\|bar"
|
|
36
|
+
escapeRegExp("a-b"); // "a\\x2db"
|
|
49
37
|
|
|
50
|
-
// Use in RegExp constructor
|
|
51
38
|
const userInput = "How much $ for mass?";
|
|
52
39
|
const re = new RegExp(escapeRegExp(userInput), "i");
|
|
53
40
|
re.test(userInput); // true
|
|
54
41
|
```
|
|
55
42
|
|
|
56
|
-
##
|
|
43
|
+
## Differences from `escape-string-regexp`
|
|
57
44
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
45
|
+
| | `escape-string-regexp` | `tiny-escape` |
|
|
46
|
+
| ----------- | ---------------------- | ------------- |
|
|
47
|
+
| CJS support | v4 only (v5 ESM-only) | ESM + CJS |
|
|
48
|
+
| TypeScript | native (v5) | native |
|
|
49
|
+
| Export | default | named |
|
|
63
50
|
|
|
64
51
|
## Migrating from escape-string-regexp
|
|
65
52
|
|
|
@@ -70,6 +57,14 @@ Throws `TypeError` if the input is not a string.
|
|
|
70
57
|
+ const escaped = escapeRegExp(input);
|
|
71
58
|
```
|
|
72
59
|
|
|
60
|
+
## API
|
|
61
|
+
|
|
62
|
+
### `escapeRegExp(string: string): string`
|
|
63
|
+
|
|
64
|
+
Escapes `| \ { } ( ) [ ] ^ $ + * ? .` and `-`.
|
|
65
|
+
|
|
66
|
+
Throws `TypeError` if the input is not a string.
|
|
67
|
+
|
|
73
68
|
## Author
|
|
74
69
|
|
|
75
70
|
[](https://gitshow.dev/ofershap)
|
|
@@ -79,4 +74,4 @@ Throws `TypeError` if the input is not a string.
|
|
|
79
74
|
|
|
80
75
|
## License
|
|
81
76
|
|
|
82
|
-
MIT
|
|
77
|
+
[MIT](LICENSE) © [Ofer Shapira](https://github.com/ofershap)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tiny-escape",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Escape special characters for use in regular expressions. Like escape-string-regexp, ships ESM + CJS.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
@@ -18,7 +18,9 @@
|
|
|
18
18
|
"main": "./dist/index.cjs",
|
|
19
19
|
"module": "./dist/index.js",
|
|
20
20
|
"types": "./dist/index.d.ts",
|
|
21
|
-
"files": [
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
22
24
|
"scripts": {
|
|
23
25
|
"build": "tsup",
|
|
24
26
|
"typecheck": "tsc --noEmit",
|
|
@@ -30,24 +32,49 @@
|
|
|
30
32
|
"prepare": "husky"
|
|
31
33
|
},
|
|
32
34
|
"lint-staged": {
|
|
33
|
-
"*.{ts,js}": [
|
|
34
|
-
|
|
35
|
+
"*.{ts,js}": [
|
|
36
|
+
"eslint --fix",
|
|
37
|
+
"prettier --write"
|
|
38
|
+
],
|
|
39
|
+
"*.{json,md,yml,yaml}": [
|
|
40
|
+
"prettier --write"
|
|
41
|
+
]
|
|
35
42
|
},
|
|
36
43
|
"release": {
|
|
37
|
-
"branches": [
|
|
44
|
+
"branches": [
|
|
45
|
+
"main"
|
|
46
|
+
],
|
|
38
47
|
"plugins": [
|
|
39
48
|
"@semantic-release/commit-analyzer",
|
|
40
49
|
"@semantic-release/release-notes-generator",
|
|
41
50
|
"@semantic-release/changelog",
|
|
42
51
|
"@semantic-release/npm",
|
|
43
52
|
"@semantic-release/github",
|
|
44
|
-
[
|
|
45
|
-
"
|
|
46
|
-
|
|
47
|
-
|
|
53
|
+
[
|
|
54
|
+
"@semantic-release/git",
|
|
55
|
+
{
|
|
56
|
+
"assets": [
|
|
57
|
+
"CHANGELOG.md",
|
|
58
|
+
"package.json"
|
|
59
|
+
],
|
|
60
|
+
"message": "chore(release): ${nextRelease.version} [skip ci]"
|
|
61
|
+
}
|
|
62
|
+
]
|
|
48
63
|
]
|
|
49
64
|
},
|
|
50
|
-
"keywords": [
|
|
65
|
+
"keywords": [
|
|
66
|
+
"escape",
|
|
67
|
+
"regex",
|
|
68
|
+
"regexp",
|
|
69
|
+
"regular-expression",
|
|
70
|
+
"escape-string-regexp",
|
|
71
|
+
"string",
|
|
72
|
+
"sanitize",
|
|
73
|
+
"drop-in-replacement",
|
|
74
|
+
"typescript",
|
|
75
|
+
"esm",
|
|
76
|
+
"zero-dependency"
|
|
77
|
+
],
|
|
51
78
|
"author": "Ofer Shapira <ofer@ofershap.dev>",
|
|
52
79
|
"license": "MIT",
|
|
53
80
|
"repository": {
|