tiny-escape 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ofer Shapira
4
+
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:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
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 THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # tiny-escape
2
+
3
+ [![npm version](https://img.shields.io/npm/v/tiny-escape.svg)](https://www.npmjs.com/package/tiny-escape)
4
+ [![npm downloads](https://img.shields.io/npm/dm/tiny-escape.svg)](https://www.npmjs.com/package/tiny-escape)
5
+ [![CI](https://github.com/ofershap/tiny-escape/actions/workflows/ci.yml/badge.svg)](https://github.com/ofershap/tiny-escape/actions/workflows/ci.yml)
6
+ [![TypeScript](https://img.shields.io/badge/TypeScript-strict-blue.svg)](https://www.typescriptlang.org/)
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
8
+ [![Bundle size](https://img.shields.io/badge/gzip-201_B-brightgreen)](https://github.com/ofershap/tiny-escape)
9
+ [![Zero dependencies](https://img.shields.io/badge/dependencies-0-brightgreen)](https://github.com/ofershap/tiny-escape)
10
+
11
+ Escape special characters in a string for use in a regular expression. A modern, type-safe replacement for [`escape-string-regexp`](https://github.com/sindresorhus/escape-string-regexp).
12
+
13
+ ```ts
14
+ import { escapeRegExp } from "tiny-escape";
15
+
16
+ const input = "price is $5.00 (USD)";
17
+ const re = new RegExp(escapeRegExp(input));
18
+ re.test(input); // true
19
+ ```
20
+
21
+ > Native TypeScript. ESM + CJS dual export. Zero dependencies. 201 bytes gzipped.
22
+
23
+ ## Why tiny-escape?
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 |
33
+
34
+ ## Install
35
+
36
+ ```bash
37
+ npm install tiny-escape
38
+ ```
39
+
40
+ ## Usage
41
+
42
+ ```ts
43
+ import { escapeRegExp } from "tiny-escape";
44
+
45
+ escapeRegExp("hello.world"); // "hello\\.world"
46
+ escapeRegExp("[test] (1+1)"); // "\\[test\\] \\(1\\+1\\)"
47
+ escapeRegExp("foo|bar"); // "foo\\|bar"
48
+ escapeRegExp("a-b"); // "a\\x2db"
49
+
50
+ // Use in RegExp constructor
51
+ const userInput = "How much $ for mass?";
52
+ const re = new RegExp(escapeRegExp(userInput), "i");
53
+ re.test(userInput); // true
54
+ ```
55
+
56
+ ## API
57
+
58
+ ### `escapeRegExp(string: string): string`
59
+
60
+ Escapes all characters with special meaning in regular expressions: `| \ { } ( ) [ ] ^ $ + * ? .` and `-`.
61
+
62
+ Throws `TypeError` if the input is not a string.
63
+
64
+ ## Migrating from escape-string-regexp
65
+
66
+ ```diff
67
+ - import escapeStringRegexp from "escape-string-regexp";
68
+ - const escaped = escapeStringRegexp(input);
69
+ + import { escapeRegExp } from "tiny-escape";
70
+ + const escaped = escapeRegExp(input);
71
+ ```
72
+
73
+ ## Author
74
+
75
+ [![Made by ofershap](https://gitshow.dev/api/card/ofershap)](https://gitshow.dev/ofershap)
76
+
77
+ [![LinkedIn](https://img.shields.io/badge/LinkedIn-Connect-0A66C2?style=flat&logo=linkedin&logoColor=white)](https://linkedin.com/in/ofershap)
78
+ [![GitHub](https://img.shields.io/badge/GitHub-Follow-181717?style=flat&logo=github&logoColor=white)](https://github.com/ofershap)
79
+
80
+ ## License
81
+
82
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,2 @@
1
+ 'use strict';function r(e){if(typeof e!="string")throw new TypeError("Expected a string");return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}exports.escapeRegExp=r;//# sourceMappingURL=index.cjs.map
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":["escapeRegExp","string"],"mappings":"aAAO,SAASA,CAAAA,CAAaC,EAAwB,CACnD,GAAI,OAAOA,CAAAA,EAAW,QAAA,CACpB,MAAM,IAAI,SAAA,CAAU,mBAAmB,CAAA,CAGzC,OAAOA,EAAO,OAAA,CAAQ,qBAAA,CAAuB,MAAM,CAAA,CAAE,OAAA,CAAQ,IAAA,CAAM,OAAO,CAC5E","file":"index.cjs","sourcesContent":["export function escapeRegExp(string: string): string {\n if (typeof string !== \"string\") {\n throw new TypeError(\"Expected a string\");\n }\n\n return string.replace(/[|\\\\{}()[\\]^$+*?.]/g, \"\\\\$&\").replace(/-/g, \"\\\\x2d\");\n}\n"]}
@@ -0,0 +1,3 @@
1
+ declare function escapeRegExp(string: string): string;
2
+
3
+ export { escapeRegExp };
@@ -0,0 +1,3 @@
1
+ declare function escapeRegExp(string: string): string;
2
+
3
+ export { escapeRegExp };
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ function r(e){if(typeof e!="string")throw new TypeError("Expected a string");return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}export{r as escapeRegExp};//# sourceMappingURL=index.js.map
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":["escapeRegExp","string"],"mappings":"AAAO,SAASA,CAAAA,CAAaC,EAAwB,CACnD,GAAI,OAAOA,CAAAA,EAAW,QAAA,CACpB,MAAM,IAAI,SAAA,CAAU,mBAAmB,CAAA,CAGzC,OAAOA,EAAO,OAAA,CAAQ,qBAAA,CAAuB,MAAM,CAAA,CAAE,OAAA,CAAQ,IAAA,CAAM,OAAO,CAC5E","file":"index.js","sourcesContent":["export function escapeRegExp(string: string): string {\n if (typeof string !== \"string\") {\n throw new TypeError(\"Expected a string\");\n }\n\n return string.replace(/[|\\\\{}()[\\]^$+*?.]/g, \"\\\\$&\").replace(/-/g, \"\\\\x2d\");\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,75 @@
1
+ {
2
+ "name": "tiny-escape",
3
+ "version": "1.0.0",
4
+ "description": "Modern escape-string-regexp replacement — escape special regex characters. TypeScript, ESM + CJS, zero dependencies, ~120B.",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "import": {
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ },
12
+ "require": {
13
+ "types": "./dist/index.d.cts",
14
+ "default": "./dist/index.cjs"
15
+ }
16
+ }
17
+ },
18
+ "main": "./dist/index.cjs",
19
+ "module": "./dist/index.js",
20
+ "types": "./dist/index.d.ts",
21
+ "files": ["dist"],
22
+ "scripts": {
23
+ "build": "tsup",
24
+ "typecheck": "tsc --noEmit",
25
+ "test": "vitest run",
26
+ "test:watch": "vitest",
27
+ "test:coverage": "vitest run --coverage",
28
+ "lint": "eslint . && prettier --check .",
29
+ "format": "prettier --write .",
30
+ "prepare": "husky"
31
+ },
32
+ "lint-staged": {
33
+ "*.{ts,js}": ["eslint --fix", "prettier --write"],
34
+ "*.{json,md,yml,yaml}": ["prettier --write"]
35
+ },
36
+ "release": {
37
+ "branches": ["main"],
38
+ "plugins": [
39
+ "@semantic-release/commit-analyzer",
40
+ "@semantic-release/release-notes-generator",
41
+ "@semantic-release/changelog",
42
+ "@semantic-release/npm",
43
+ "@semantic-release/github",
44
+ ["@semantic-release/git", {
45
+ "assets": ["CHANGELOG.md", "package.json"],
46
+ "message": "chore(release): ${nextRelease.version} [skip ci]"
47
+ }]
48
+ ]
49
+ },
50
+ "keywords": ["escape", "regex", "regexp", "regular-expression", "string", "sanitize", "tiny", "typescript", "esm", "zero-dependency"],
51
+ "author": "Ofer Shapira <ofer@ofershap.dev>",
52
+ "license": "MIT",
53
+ "repository": {
54
+ "type": "git",
55
+ "url": "https://github.com/ofershap/tiny-escape.git"
56
+ },
57
+ "bugs": {
58
+ "url": "https://github.com/ofershap/tiny-escape/issues"
59
+ },
60
+ "homepage": "https://github.com/ofershap/tiny-escape#readme",
61
+ "devDependencies": {
62
+ "@eslint/js": "^9.21.0",
63
+ "@semantic-release/changelog": "^6.0.3",
64
+ "@semantic-release/git": "^10.0.1",
65
+ "eslint": "^9.21.0",
66
+ "husky": "^9.1.7",
67
+ "lint-staged": "^15.4.3",
68
+ "prettier": "^3.5.3",
69
+ "semantic-release": "^24.2.3",
70
+ "tsup": "^8.4.0",
71
+ "typescript": "^5.7.3",
72
+ "typescript-eslint": "^8.25.0",
73
+ "vitest": "^3.0.7"
74
+ }
75
+ }