@amritk/helpers 0.13.0 → 0.13.2
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 +21 -0
- package/dist/escape-regex-pattern.js +8 -0
- package/package.json +2 -2
- package/src/escape-regex-pattern.ts +9 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 amritk
|
|
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.
|
|
@@ -64,6 +64,14 @@ export const escapeRegexPattern = (pattern) => {
|
|
|
64
64
|
// An escape pair like `\/` or `\d`: keep exactly as authored.
|
|
65
65
|
return match;
|
|
66
66
|
});
|
|
67
|
+
// The empty pattern is valid JSON Schema (it matches everything), but an empty
|
|
68
|
+
// regex body would emit `//` \u2014 a line comment, not a literal \u2014 and break the
|
|
69
|
+
// generated file. Emit `(?:)` instead, exactly what `new RegExp('').source`
|
|
70
|
+
// yields: an empty non-capturing group that still matches everything.
|
|
71
|
+
if (escaped === '') {
|
|
72
|
+
escapeCache.set(pattern, '(?:)');
|
|
73
|
+
return '(?:)';
|
|
74
|
+
}
|
|
67
75
|
if (escapeCache.size >= ESCAPE_CACHE_LIMIT) {
|
|
68
76
|
// Evict the single oldest entry (Maps iterate in insertion order) instead
|
|
69
77
|
// of clearing wholesale — a corpus slightly over the limit keeps its hot
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amritk/helpers",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.2",
|
|
4
4
|
"description": "Shared utilities for the mjst code generation ecosystem.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"exports": {
|
|
39
39
|
"./package.json": "./package.json",
|
|
40
40
|
"./*": {
|
|
41
|
-
"import": "./dist/*.js",
|
|
42
41
|
"types": "./dist/*.d.ts",
|
|
42
|
+
"import": "./dist/*.js",
|
|
43
43
|
"default": "./dist/*.js"
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -67,6 +67,15 @@ export const escapeRegexPattern = (pattern: string): string => {
|
|
|
67
67
|
return match
|
|
68
68
|
})
|
|
69
69
|
|
|
70
|
+
// The empty pattern is valid JSON Schema (it matches everything), but an empty
|
|
71
|
+
// regex body would emit `//` \u2014 a line comment, not a literal \u2014 and break the
|
|
72
|
+
// generated file. Emit `(?:)` instead, exactly what `new RegExp('').source`
|
|
73
|
+
// yields: an empty non-capturing group that still matches everything.
|
|
74
|
+
if (escaped === '') {
|
|
75
|
+
escapeCache.set(pattern, '(?:)')
|
|
76
|
+
return '(?:)'
|
|
77
|
+
}
|
|
78
|
+
|
|
70
79
|
if (escapeCache.size >= ESCAPE_CACHE_LIMIT) {
|
|
71
80
|
// Evict the single oldest entry (Maps iterate in insertion order) instead
|
|
72
81
|
// of clearing wholesale — a corpus slightly over the limit keeps its hot
|