hinted-tree-merger 6.3.0 → 6.4.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/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (C) 2019-2025 by arlac77
1
+ Copyright (C) 2019-2026 by arlac77
2
2
 
3
3
  Permission to use, copy, modify, and/or distribute this software for any
4
4
  purpose with or without fee is hereby granted.
package/README.md CHANGED
@@ -74,22 +74,24 @@ const r = merge( undefined, [ { k:1, e:2}, { k:3 }]);
74
74
  * [Parameters](#parameters-11)
75
75
  * [matchingIndex](#matchingindex)
76
76
  * [Parameters](#parameters-12)
77
+ * [toRegexp](#toregexp)
78
+ * [Parameters](#parameters-13)
77
79
  * [match](#match)
78
80
  * [cmp](#cmp)
79
- * [Parameters](#parameters-13)
80
- * [compareVersion](#compareversion)
81
81
  * [Parameters](#parameters-14)
82
- * [unionVersion](#unionversion)
82
+ * [compareVersion](#compareversion)
83
83
  * [Parameters](#parameters-15)
84
+ * [unionVersion](#unionversion)
85
+ * [Parameters](#parameters-16)
84
86
  * [VersionMapper](#versionmapper)
85
87
  * [mergeVersionsWithFilter](#mergeversionswithfilter)
86
- * [Parameters](#parameters-16)
87
- * [mergeVersions](#mergeversions)
88
88
  * [Parameters](#parameters-17)
89
- * [mergeVersionsPreferNumeric](#mergeversionsprefernumeric)
89
+ * [mergeVersions](#mergeversions)
90
90
  * [Parameters](#parameters-18)
91
- * [walk](#walk)
91
+ * [mergeVersionsPreferNumeric](#mergeversionsprefernumeric)
92
92
  * [Parameters](#parameters-19)
93
+ * [walk](#walk)
94
+ * [Parameters](#parameters-20)
93
95
 
94
96
  ## hintFor
95
97
 
@@ -125,8 +127,8 @@ Skip merging use left side always.
125
127
 
126
128
  ### Parameters
127
129
 
128
- * `a` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** 
129
- * `b` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** 
130
+ * `a` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)\<any>**&#x20;
131
+ * `b` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)\<any>**&#x20;
130
132
  * `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;
131
133
  * `actions` **[Actions](#actions)** (optional, default `nullAction`)
132
134
  * `hints` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**&#x20;
@@ -223,6 +225,17 @@ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G
223
225
 
224
226
  Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**&#x20;
225
227
 
228
+ ## toRegexp
229
+
230
+ try to from a regexp from str.
231
+ Str must start with '/' and end with '/<flags>'
232
+
233
+ ### Parameters
234
+
235
+ * `str` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;
236
+
237
+ Returns **([RegExp](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/RegExp) | [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String))**&#x20;
238
+
226
239
  ## match
227
240
 
228
241
  url means highest version
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hinted-tree-merger",
3
- "version": "6.3.0",
3
+ "version": "6.4.1",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
@@ -42,14 +42,14 @@
42
42
  },
43
43
  "devDependencies": {
44
44
  "ava": "^6.4.1",
45
- "browser-ava": "^2.3.47",
45
+ "browser-ava": "^2.3.50",
46
46
  "c8": "^10.1.3",
47
47
  "documentation": "^14.0.3",
48
48
  "semantic-release": "^25.0.2",
49
49
  "typescript": "^5.9.3"
50
50
  },
51
51
  "engines": {
52
- "node": ">=24.11.1"
52
+ "node": ">=24.13.0"
53
53
  },
54
54
  "repository": {
55
55
  "type": "git",
package/src/merger.mjs CHANGED
@@ -10,7 +10,8 @@ import {
10
10
  keyFor,
11
11
  hasDeleteHint,
12
12
  compareWithDefinedOrder,
13
- sortObjectsByKeys
13
+ sortObjectsByKeys,
14
+ toRegexp
14
15
  } from "./util.mjs";
15
16
  import { hintFor } from "./hint.mjs";
16
17
 
@@ -20,7 +21,6 @@ import { hintFor } from "./hint.mjs";
20
21
  * @param {Object} hints
21
22
  */
22
23
 
23
-
24
24
  function appendPath(path, suffix, separator = "") {
25
25
  return path === undefined || path.length === 0
26
26
  ? suffix
@@ -36,8 +36,8 @@ export function mergeSkip(a, b, path, actions, hints) {
36
36
 
37
37
  /**
38
38
  *
39
- * @param {Array} a
40
- * @param {Array} b
39
+ * @param {Array<any>} a
40
+ * @param {Array<any>} b
41
41
  * @param {string} path
42
42
  * @param {Actions} actions
43
43
  * @param {Object} hints
@@ -56,6 +56,16 @@ export function mergeArrays(a, b, path, actions = nullAction, hints) {
56
56
  return false;
57
57
  }
58
58
 
59
+ value = toRegexp(value);
60
+ if(value instanceof RegExp) {
61
+ for(let i = 0; i < a.length; i++) {
62
+ if(typeof a[i] === 'string' && a[i].match(value)) {
63
+ a.splice(i, 1);
64
+ actions({ remove: value, path: appendPath(path, `[${i}]`) }, h);
65
+ }
66
+ }
67
+ }
68
+
59
69
  const i = a.indexOf(value);
60
70
  if (i >= 0) {
61
71
  a.splice(i, 1);
@@ -7,6 +7,7 @@ import {
7
7
  } from "./versions.mjs";
8
8
  import { mergeExpressions } from "./string-expressions.mjs";
9
9
  import { mergeSkip } from "./merger.mjs";
10
+ import { toRegexp } from "./util.mjs";
10
11
 
11
12
  const mergeFunctions = [
12
13
  mergeVersions,
@@ -29,17 +30,11 @@ export function reanimateHints(hints) {
29
30
  }
30
31
  break;
31
32
  case "orderBy":
32
- parents[parents.length - 1].orderBy = value.map(v => {
33
- if (typeof v === "string" && v[0] === "/" && v.match(/\/[img]?$/)) {
34
- const m = v.match(/\/([a-z]*)$/)
35
- const inner = v.substring(1,v.length - m[0].length)
36
- return new RegExp(inner,m[1]);
37
- }
38
- return v;
39
- });
33
+ parents[parents.length - 1].orderBy = value.map(v => toRegexp(v));
40
34
  break;
41
35
  }
42
36
  }
43
37
 
44
38
  return hints;
45
39
  }
40
+
package/src/util.mjs CHANGED
@@ -379,3 +379,18 @@ export function compareWithDefinedOrder(a, b, definedOrder) {
379
379
 
380
380
  return ai - bi;
381
381
  }
382
+
383
+ /**
384
+ * try to from a regexp from str.
385
+ * Str must start with '/' and end with '/<flags>'
386
+ * @param {string} str
387
+ * @returns {RegExp|string}
388
+ */
389
+ export function toRegexp(str) {
390
+ if (typeof str === "string" && str[0] === "/" && str.match(/\/[a-z]*$/)) {
391
+ const m = str.match(/\/([a-z]*)$/);
392
+ const inner = str.substring(1, str.length - m[0].length);
393
+ return new RegExp(inner, m[1]);
394
+ }
395
+ return str;
396
+ }
@@ -4,13 +4,13 @@
4
4
  export function mergeSkip(a: any, b: any, path: any, actions: any, hints: any): any;
5
5
  /**
6
6
  *
7
- * @param {Array} a
8
- * @param {Array} b
7
+ * @param {Array<any>} a
8
+ * @param {Array<any>} b
9
9
  * @param {string} path
10
10
  * @param {Actions} actions
11
11
  * @param {Object} hints
12
12
  */
13
- export function mergeArrays(a: any[], b: any[], path: string, actions: Actions, hints: any): any[];
13
+ export function mergeArrays(a: Array<any>, b: Array<any>, path: string, actions: Actions, hints: any): any[];
14
14
  /**
15
15
  * Merge to values.
16
16
  * @param {any} a
package/types/util.d.mts CHANGED
@@ -53,3 +53,10 @@ export function sortObjectsByKeys(source: any, compare: any): any;
53
53
  * @param {Array<RegExp|string>} definedOrder
54
54
  */
55
55
  export function compareWithDefinedOrder(a: any, b: any, definedOrder: Array<RegExp | string>): number;
56
+ /**
57
+ * try to from a regexp from str.
58
+ * Str must start with '/' and end with '/<flags>'
59
+ * @param {string} str
60
+ * @returns {RegExp|string}
61
+ */
62
+ export function toRegexp(str: string): RegExp | string;