regex-partial-match 0.1.7 → 0.1.9

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.
Files changed (2) hide show
  1. package/README.md +51 -11
  2. package/package.json +2 -1
package/README.md CHANGED
@@ -101,12 +101,54 @@ The library is compiled to **ES5** for broad compatibility with older browsers a
101
101
 
102
102
  ## Caveats
103
103
 
104
+ ### [`.test()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test) behaviour and non-matching results from [`.exec()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec) and [`.match()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match)
105
+
106
+ The library produces an expression that always matches an empty string, at the end of the input.
107
+
108
+ Hence:
109
+
110
+ ```js
111
+ /x/.test("a") === false; /* what you'd expect */
112
+ /(?:x|$)/.test("a") === true; /* what's produced by the library */
113
+ ```
114
+
115
+ To mitigate, a start boundary anchor can prevent anything _but_ the empty string matching:
116
+
117
+ ```js
118
+ /^(?:x|$)/.test("") === true;
119
+ /^(?:x|$)/.test("a") === false;
120
+ /^(?:x|$)/.test("x") === true;
121
+ ```
122
+
123
+ On this basis, `.test()` should be used with caution, and a match of an empty string at the end of the input should instead be considered "no match".
124
+
125
+ i.e.
126
+
127
+ ```js
128
+ /(?:x|$)/.exec("a"); // ['', index: 1, input: "a", groups: undefined];
129
+ "a".match(/(?:x|$)/); // ['', index: 1, input: "a", groups: undefined];
130
+ ```
131
+
132
+ Since the library produces a native `RegExp` object, no attempt to proxy / translate this output to `null` has been attempted, but a helper could be produced in future, for clarity.
133
+
104
134
  ### Backreferences
105
135
 
106
136
  **Backreferences cannot be partially matched because they are atomic.** A backreference like `\1` must match the complete captured text or fail entirely, and cannot be split into individual characters for partial matching like regular atoms can.
107
137
 
108
138
  Fixed-length patterns like `/(abc)\1/` could theoretically become `/(?:(a)|$)(?:(b)|$)(?:(c)|$)(?:\1|$)(?:\2|$)(?:\3|$)/` (accepting polluted capture indexes as a side-effect), but this doesn't work for variable-length captures.
109
139
 
140
+ ### Positive Lookbehinds
141
+
142
+ Whilst forming a match, a positive lookbehind must match in entirety, for the pattern to match. This is inherent in the concept of non-matching groups, since they are not match-worthy themselves, but just qualify matching atoms.
143
+
144
+ e.g.
145
+
146
+ ```js
147
+ /(?<=foo)bar/;
148
+ ```
149
+
150
+ "f" through "foo" is not a match, but "foob" is.
151
+
110
152
  ### Surrogate Pair Matching
111
153
 
112
154
  In unicode-aware mode (`u` flag), **only whole astral characters are supported**. Partial matching of individual surrogate pairs is not supported. For example, `/😀/u` will match the complete emoji character, but not the first surrogate pair in isolation. Hence, if partially matching a byte stream, be sure to pipe via a [`TextDecoder`](https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder) first.
@@ -140,8 +182,6 @@ The global flag does not cause issues like the sticky flag, as partial patterns
140
182
  ### Form Validation
141
183
 
142
184
  ```javascript
143
- import createPartialMatchRegex from "regex-partial-match";
144
-
145
185
  const emailPattern = /^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$/i;
146
186
  const partial = createPartialMatchRegex(emailPattern);
147
187
 
@@ -175,8 +215,6 @@ getSuggestions("xyz"); // 'no suggestions'
175
215
  ### Stream Processing
176
216
 
177
217
  ```javascript
178
- import createPartialMatchRegex from "regex-partial-match";
179
-
180
218
  // Process streaming data with pattern matching at chunk boundaries
181
219
  const pattern = /\{"[^"]+":"[^"]+"\}/; // Match JSON objects
182
220
  const partial = createPartialMatchRegex(pattern);
@@ -246,11 +284,13 @@ Algorithm created by [Lucas Trzesniewski](https://github.com/ltrzesniewski).
246
284
 
247
285
  Contributions are welcome! Please open an issue or pull request on [GitHub](https://github.com/TomStrepsil/regex-partial-match).
248
286
 
249
- ## Related packages
287
+ ## Related projects
250
288
 
251
- - [`incr-regex-package`](https://www.npmjs.com/package/incr-regex-package)
252
- - Incremental regex matcher
253
- - [`dfa`](https://github.com/foliojs/dfa)
254
- - Compiles a regular expression like syntax to fast deterministic finite automata, which could be used to partial match?
255
- - [`refa`](https://github.com/RunDevelopment/refa)
256
- - Can [convert regular expressions to an Abstract Syntax Tree](https://rundevelopment.github.io/refa/docs/latest/classes/JS.Parser.html), which might afford partial-match capability?
289
+ | Project | Description |
290
+ | -------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
291
+ | [`incr-regex-package`](https://www.npmjs.com/package/incr-regex-package) | Incremental regex matcher |
292
+ | [`dfa`](https://github.com/foliojs/dfa) | Compiles a regular expression like syntax to fast deterministic finite automata, which could be used to partial match? |
293
+ | [`refa`](https://github.com/RunDevelopment/refa) | Can [convert regular expressions to an Abstract Syntax Tree](https://rundevelopment.github.io/refa/docs/latest/classes/JS.Parser.html), which might afford partial-match capability? |
294
+ | [`@eslint-community/regexpp`](https://github.com/eslint-community/regexpp) | A regular expression parser for ECMAScript with AST generation and visitor implementation |
295
+ | [`Regex+`](https://www.npmjs.com/package/regex) | template literal, transforming native regular expressions |
296
+ | [`Awesome Regex`](https://github.com/slevithan/awesome-regex) | Curated list of tools, tutorials, libraries, and other resources, covering all major regex flavours |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "regex-partial-match",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "A regular expression transform for partial matching",
5
5
  "engines": {
6
6
  "node": ">=23"
@@ -66,6 +66,7 @@
66
66
  },
67
67
  "devDependencies": {
68
68
  "@eslint/js": "^9.17.0",
69
+ "@eslint/markdown": "^7.5.1",
69
70
  "eslint": "^9.17.0",
70
71
  "jiti": "^2.6.1",
71
72
  "lint-staged": "^15.2.11",