hinted-tree-merger 6.3.0 → 6.4.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/package.json +2 -2
- package/src/merger.mjs +14 -4
- package/src/reanimate-hints.mjs +3 -8
- package/src/util.mjs +15 -0
- package/types/merger.d.mts +3 -3
- package/types/util.d.mts +7 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hinted-tree-merger",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.4.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"provenance": true
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"typescript": "^5.9.3"
|
|
50
50
|
},
|
|
51
51
|
"engines": {
|
|
52
|
-
"node": ">=24.
|
|
52
|
+
"node": ">=24.12.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);
|
package/src/reanimate-hints.mjs
CHANGED
|
@@ -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
|
+
}
|
package/types/merger.d.mts
CHANGED
|
@@ -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
|
|
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;
|