regex-partial-match 0.1.12 → 0.2.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/README.md CHANGED
@@ -72,6 +72,7 @@ Such combinations have not been tested.
72
72
  - 📋 [Character classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Character_class) (`[abc]`, `[^abc]`, `[a-z]`)
73
73
  - 🔣 [Character escapes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Character_escape) (`\n`, `\t`, `\x61`, `\u0061`, `\u{1F600}`)
74
74
  - 🌐 [Unicode character class escape](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Unicode_character_class_escape) (`\p{Letter}`, `\P{Letter}`)
75
+ - 🧮 [Unicode sets (`v` flag)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicodeSets) (`/[\p{Lowercase}&&\p{Script=Greek}]/v`)
75
76
  - 🔢 [Quantifiers](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Quantifier) (`*`, `+`, `?`, `{n}`, `{n,}`, `{n,m}`)
76
77
  - 🔀 [Disjunction](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Disjunction) (`a|b`)
77
78
  - 👥 [Groups](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Capturing_group) (capturing and non-capturing) (`(?:abc)`, `(abc)`, `(?<named>abc)`)
@@ -86,7 +87,6 @@ Such combinations have not been tested.
86
87
  The following regex features are **not currently supported**:
87
88
 
88
89
  - ⚠️ [Backreferences](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Backreference) (`\1`, `\k<name>`) - Can be included, but can't partially match. See [caveats](#caveats).
89
- - ❌ [Unicode sets (`v` flag)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicodeSets) - ES2024+. See [issue](https://github.com/TomStrepsil/regex-partial-match/issues/1).
90
90
  - ❌ [Modifiers](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Modifier) (`(?ims:...)`, `(?-ims:...)`) - ES2025+. See [issue](https://github.com/TomStrepsil/regex-partial-match/issues/2).
91
91
 
92
92
  ## Browser Compatibility
package/lib/index.js CHANGED
@@ -1,7 +1,7 @@
1
- var characterClassGlobalRegex = /\[(?:\\.|.)*?\]/g;
2
1
  var occurrencesRegex = /\{\d+,?\d*\}/g;
3
2
  var createPartialMatchRegex = function (regex) {
4
3
  var source = regex.source;
4
+ var isUnicode = regex.unicode || regex.unicodeSets;
5
5
  var i = 0;
6
6
  function extractSubstring(length) {
7
7
  return source.substring(i, (i += length));
@@ -25,7 +25,7 @@ var createPartialMatchRegex = function (regex) {
25
25
  appendOptional(source.indexOf(">", i) - i + 1);
26
26
  break;
27
27
  case "u":
28
- if (regex.unicode && source[i + 2] === "{") {
28
+ if (isUnicode && source[i + 2] === "{") {
29
29
  appendOptional(source.indexOf("}", i) - i + 1);
30
30
  }
31
31
  else {
@@ -34,7 +34,7 @@ var createPartialMatchRegex = function (regex) {
34
34
  break;
35
35
  case "p":
36
36
  case "P":
37
- if (regex.unicode) {
37
+ if (isUnicode) {
38
38
  appendOptional(source.indexOf("}", i) - i + 1);
39
39
  }
40
40
  else {
@@ -50,10 +50,24 @@ var createPartialMatchRegex = function (regex) {
50
50
  }
51
51
  break;
52
52
  case "[": {
53
- characterClassGlobalRegex.lastIndex = i;
54
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- must match, since otherwise an invalid regex
55
- var match = characterClassGlobalRegex.exec(source)[0];
56
- appendOptional(match.length);
53
+ var depth = 1, escaped = false, j = i + 1;
54
+ while (depth) {
55
+ switch (source[j++]) {
56
+ case "\\":
57
+ escaped = !escaped;
58
+ continue;
59
+ case "[":
60
+ if (!escaped)
61
+ depth++;
62
+ break;
63
+ case "]":
64
+ if (!escaped)
65
+ depth--;
66
+ break;
67
+ }
68
+ escaped = false;
69
+ }
70
+ appendOptional(j - i);
57
71
  break;
58
72
  }
59
73
  case "|":
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "regex-partial-match",
3
- "version": "0.1.12",
3
+ "version": "0.2.0",
4
4
  "description": "A regular expression transform for partial matching",
5
5
  "devEngines": {
6
6
  "runtime": {
@@ -35,12 +35,14 @@
35
35
  "main": "lib/index.js",
36
36
  "exports": {
37
37
  ".": {
38
+ "types": "./lib/index.d.ts",
38
39
  "import": "./lib/index.js",
39
- "types": "./lib/index.d.ts"
40
+ "default": "./lib/index.js"
40
41
  },
41
42
  "./extend": {
43
+ "types": "./lib/extend.d.ts",
42
44
  "import": "./lib/extend.js",
43
- "types": "./lib/extend.d.ts"
45
+ "default": "./lib/extend.js"
44
46
  }
45
47
  },
46
48
  "files": [
@@ -64,7 +66,7 @@
64
66
  },
65
67
  "lint-staged": {
66
68
  "*.{ts,js}": [
67
- "npm run lint:fix"
69
+ "eslint --fix"
68
70
  ]
69
71
  },
70
72
  "publishConfig": {