hinted-tree-merger 6.0.1 → 6.1.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 +1 -0
- package/package.json +14 -7
- package/src/merger.mjs +11 -4
- package/src/util.mjs +7 -4
- package/types/hint.d.mts +10 -0
- package/types/index.d.mts +6 -0
- package/types/merger.d.mts +23 -0
- package/types/reanimate-hints.d.mts +1 -0
- package/types/string-expressions.d.mts +15 -0
- package/types/util.d.mts +54 -0
- package/types/versions.d.mts +63 -0
- package/types/walker.d.mts +6 -0
package/README.md
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
[](https://www.npmjs.com/package/hinted-tree-merger)
|
|
2
2
|
[](https://opensource.org/licenses/BSD-3-Clause)
|
|
3
|
+
[](https://typescriptlang.org)
|
|
3
4
|
[](https://bundlejs.com/?q=hinted-tree-merger)
|
|
4
5
|
[](https://npmjs.org/package/hinted-tree-merger)
|
|
5
6
|
[](https://github.com/arlac77/hinted-tree-merger/issues)
|
package/package.json
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hinted-tree-merger",
|
|
3
|
-
"version": "6.0
|
|
3
|
+
"version": "6.1.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"provenance": true
|
|
7
7
|
},
|
|
8
|
+
"types": "./types/index.d.mts",
|
|
8
9
|
"exports": {
|
|
9
|
-
".":
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./types/index.d.mts",
|
|
12
|
+
"default": "./src/index.mjs"
|
|
13
|
+
}
|
|
10
14
|
},
|
|
11
15
|
"description": "merges two trees guided with hints",
|
|
12
16
|
"keywords": [
|
|
@@ -24,21 +28,23 @@
|
|
|
24
28
|
],
|
|
25
29
|
"license": "BSD-2-Clause",
|
|
26
30
|
"scripts": {
|
|
27
|
-
"prepare": "
|
|
31
|
+
"prepare": "tsc --allowJs --declaration --emitDeclarationOnly --declarationDir types -t esnext -m esnext --module nodenext --moduleResolution nodenext ./src**/*.mjs",
|
|
28
32
|
"test": "npm run test:browser-ava && npm run test:ava",
|
|
29
33
|
"test:ava": "ava --timeout 4m tests/*-ava.mjs tests/*-ava-node.mjs",
|
|
30
34
|
"test:browser-ava": "browser-ava --headless --no-keep-open tests/*-ava.mjs tests/*-ava-browser.mjs",
|
|
31
35
|
"cover": "c8 -x 'tests/**/*' --temp-directory build/tmp ava --timeout 4m tests/*-ava.mjs tests/*-ava-node.mjs && c8 report -r lcov -o build/coverage --temp-directory build/tmp",
|
|
32
36
|
"docs": "documentation readme --section=API ./src/**/*.mjs",
|
|
33
|
-
"lint": "npm run lint:docs",
|
|
34
|
-
"lint:docs": "documentation lint ./src/**/*.mjs"
|
|
37
|
+
"lint": "npm run lint:docs && npm run lint:tsc",
|
|
38
|
+
"lint:docs": "documentation lint ./src/**/*.mjs",
|
|
39
|
+
"lint:tsc": "tsc --allowJs --checkJs --noEmit -t esnext -m esnext --module nodenext --moduleResolution nodenext ./src**/*.mjs"
|
|
35
40
|
},
|
|
36
41
|
"devDependencies": {
|
|
37
42
|
"ava": "^6.1.1",
|
|
38
43
|
"browser-ava": "^2.2.0",
|
|
39
44
|
"c8": "^9.1.0",
|
|
40
45
|
"documentation": "^14.0.3",
|
|
41
|
-
"semantic-release": "^23.0.2"
|
|
46
|
+
"semantic-release": "^23.0.2",
|
|
47
|
+
"typescript": "^5.3.3"
|
|
42
48
|
},
|
|
43
49
|
"engines": {
|
|
44
50
|
"node": ">=20.11.0"
|
|
@@ -56,7 +62,8 @@
|
|
|
56
62
|
"arlac77/template-arlac77-github",
|
|
57
63
|
"arlac77/template-browser-ava",
|
|
58
64
|
"arlac77/template-javascript-component",
|
|
59
|
-
"arlac77/template-node-component"
|
|
65
|
+
"arlac77/template-node-component",
|
|
66
|
+
"arlac77/template-typescript"
|
|
60
67
|
]
|
|
61
68
|
}
|
|
62
69
|
}
|
package/src/merger.mjs
CHANGED
|
@@ -12,9 +12,16 @@ import {
|
|
|
12
12
|
compareWithDefinedOrder,
|
|
13
13
|
sortObjectsByKeys
|
|
14
14
|
} from "./util.mjs";
|
|
15
|
-
|
|
16
15
|
import { hintFor } from "./hint.mjs";
|
|
17
16
|
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @callback Actions
|
|
20
|
+
* @param {Object} options
|
|
21
|
+
* @param {Object} hints
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
|
|
18
25
|
function appendPath(path, suffix, separator = "") {
|
|
19
26
|
return path === undefined || path.length === 0
|
|
20
27
|
? suffix
|
|
@@ -33,7 +40,7 @@ export function mergeSkip(a, b, path, actions, hints) {
|
|
|
33
40
|
* @param {Array} a
|
|
34
41
|
* @param {Array} b
|
|
35
42
|
* @param {string} path
|
|
36
|
-
* @param {
|
|
43
|
+
* @param {Actions} actions
|
|
37
44
|
* @param {Object} hints
|
|
38
45
|
*/
|
|
39
46
|
export function mergeArrays(a, b, path, actions = nullAction, hints) {
|
|
@@ -116,13 +123,13 @@ export function mergeArrays(a, b, path, actions = nullAction, hints) {
|
|
|
116
123
|
* Merge to values.
|
|
117
124
|
* @param {any} a
|
|
118
125
|
* @param {any} b
|
|
119
|
-
* @param {
|
|
126
|
+
* @param {Actions} actions
|
|
120
127
|
* @param {any} hints
|
|
121
128
|
* @return {any} merged value
|
|
122
129
|
*/
|
|
123
130
|
export function merge(a, b, path, actions = nullAction, hints) {
|
|
124
131
|
if (isScalar(a)) {
|
|
125
|
-
if (b !== undefined && !isEqual(a, b)) {
|
|
132
|
+
if (b !== undefined && b !== null && !isEqual(a, b)) {
|
|
126
133
|
const hint = hintFor(hints, path);
|
|
127
134
|
b = hint.keepHints ? deepCopy(b) : removeHintedValues(b);
|
|
128
135
|
actions({ add: b, path }, hint);
|
package/src/util.mjs
CHANGED
|
@@ -53,7 +53,7 @@ export function hasDeleteHint(value, expected) {
|
|
|
53
53
|
* Should value be removed.
|
|
54
54
|
* @param {string} value
|
|
55
55
|
* @param {string} fromTemplate
|
|
56
|
-
* @return {
|
|
56
|
+
* @return {Object} true if fromTemplate tells is to delete value
|
|
57
57
|
*/
|
|
58
58
|
export function isToBeRemoved(value, fromTemplate) {
|
|
59
59
|
if (fromTemplate === undefined) {
|
|
@@ -301,7 +301,7 @@ function normalizeValue(value, hint) {
|
|
|
301
301
|
* Deliver key value to identify object.
|
|
302
302
|
* @param {any} object
|
|
303
303
|
* @param {Object} hint
|
|
304
|
-
* @return {string}
|
|
304
|
+
* @return {string|undefined}
|
|
305
305
|
*/
|
|
306
306
|
export function keyFor(object, hint) {
|
|
307
307
|
if (hint?.key) {
|
|
@@ -319,8 +319,6 @@ export function keyFor(object, hint) {
|
|
|
319
319
|
.map(k => normalizeValue(object[k], hint))
|
|
320
320
|
.find(v => v !== undefined);
|
|
321
321
|
}
|
|
322
|
-
|
|
323
|
-
return undefined;
|
|
324
322
|
}
|
|
325
323
|
|
|
326
324
|
/**
|
|
@@ -339,6 +337,11 @@ export function sortObjectsByKeys(source, compare) {
|
|
|
339
337
|
return sorted;
|
|
340
338
|
}
|
|
341
339
|
|
|
340
|
+
/**
|
|
341
|
+
*
|
|
342
|
+
* @param {any} a
|
|
343
|
+
* @param {any} b
|
|
344
|
+
*/
|
|
342
345
|
export function compareWithDefinedOrder(a, b, definedOrder) {
|
|
343
346
|
function matchingIndex(value) {
|
|
344
347
|
for (const i in definedOrder) {
|
package/types/hint.d.mts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Construct hint for a given path.
|
|
3
|
+
* @param {Object} hints
|
|
4
|
+
* @param {string} path
|
|
5
|
+
*/
|
|
6
|
+
export function hintFor(hints: any, path: string): any;
|
|
7
|
+
export const SHORT_DELETE_HINT_REGEX: RegExp;
|
|
8
|
+
export const DELETE_HINT_REGEX: RegExp;
|
|
9
|
+
export const OVERWRITE_HINT_REGEX: RegExp;
|
|
10
|
+
export const LIKE_HINT_REGEX: RegExp;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Skip merging use left side always.
|
|
3
|
+
*/
|
|
4
|
+
export function mergeSkip(a: any, b: any, path: any, actions: any, hints: any): any;
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param {Array} a
|
|
8
|
+
* @param {Array} b
|
|
9
|
+
* @param {string} path
|
|
10
|
+
* @param {Actions} actions
|
|
11
|
+
* @param {Object} hints
|
|
12
|
+
*/
|
|
13
|
+
export function mergeArrays(a: any[], b: any[], path: string, actions: Actions, hints: any): any[];
|
|
14
|
+
/**
|
|
15
|
+
* Merge to values.
|
|
16
|
+
* @param {any} a
|
|
17
|
+
* @param {any} b
|
|
18
|
+
* @param {Actions} actions
|
|
19
|
+
* @param {any} hints
|
|
20
|
+
* @return {any} merged value
|
|
21
|
+
*/
|
|
22
|
+
export function merge(a: any, b: any, path: any, actions: Actions, hints: any): any;
|
|
23
|
+
export type Actions = (options: any, hints: any) => any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function reanimateHints(hints: any): any;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function mergeExpressions(a: any, b: any, path: any, actions: typeof nullAction, hints: any): any;
|
|
2
|
+
export function decodeExpressions(script: any, hint: any): {
|
|
3
|
+
op: string;
|
|
4
|
+
args: any;
|
|
5
|
+
like?: undefined;
|
|
6
|
+
overwrite?: undefined;
|
|
7
|
+
} | {
|
|
8
|
+
like: boolean;
|
|
9
|
+
overwrite: boolean;
|
|
10
|
+
op: string;
|
|
11
|
+
args: any;
|
|
12
|
+
};
|
|
13
|
+
export function mergeDecodedExpressions(dest: any, source: any): any;
|
|
14
|
+
export function encodeExpressions(encoded: any): any;
|
|
15
|
+
import { nullAction } from "./util.mjs";
|
package/types/util.d.mts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export function nullAction(): void;
|
|
2
|
+
export function asArray(a: any): any[];
|
|
3
|
+
export function compare(a: any, b: any): 0 | 1 | -1;
|
|
4
|
+
/**
|
|
5
|
+
* @param {any} value
|
|
6
|
+
* @param {string|Function} expected
|
|
7
|
+
* @return {string|boolean}
|
|
8
|
+
*/
|
|
9
|
+
export function hasDeleteHint(value: any, expected: string | Function): string | boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Should value be removed.
|
|
12
|
+
* @param {string} value
|
|
13
|
+
* @param {string} fromTemplate
|
|
14
|
+
* @return {Object} true if fromTemplate tells is to delete value
|
|
15
|
+
*/
|
|
16
|
+
export function isToBeRemoved(value: string, fromTemplate: string): any;
|
|
17
|
+
/**
|
|
18
|
+
* Remove hint(s) form a value.
|
|
19
|
+
* @param {string|any} value
|
|
20
|
+
* @returns {any} value without hint
|
|
21
|
+
*/
|
|
22
|
+
export function hintFreeValue(value: string | any): any;
|
|
23
|
+
export function removeHintedValues(object: any, removeEmpty?: boolean): any;
|
|
24
|
+
export function deepCopy(object: any): any;
|
|
25
|
+
export function isEmpty(a: any): boolean;
|
|
26
|
+
export function isEqual(a: any, b: any, hints: any): boolean;
|
|
27
|
+
export function isScalar(a: any): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Find best insertion point for b[i] in a.
|
|
30
|
+
* @param {any[]} b
|
|
31
|
+
* @param {number} i
|
|
32
|
+
* @param {any[]} a
|
|
33
|
+
*/
|
|
34
|
+
export function indexFor(b: any[], i: number, a: any[]): number;
|
|
35
|
+
/**
|
|
36
|
+
* Deliver key value to identify object.
|
|
37
|
+
* @param {any} object
|
|
38
|
+
* @param {Object} hint
|
|
39
|
+
* @return {string|undefined}
|
|
40
|
+
*/
|
|
41
|
+
export function keyFor(object: any, hint: any): string | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Sort keys in source.
|
|
44
|
+
* @param {Object} source
|
|
45
|
+
* @param compare
|
|
46
|
+
* @return {Object} source with keys orderd by compare function
|
|
47
|
+
*/
|
|
48
|
+
export function sortObjectsByKeys(source: any, compare: any): any;
|
|
49
|
+
/**
|
|
50
|
+
*
|
|
51
|
+
* @param {any} a
|
|
52
|
+
* @param {any} b
|
|
53
|
+
*/
|
|
54
|
+
export function compareWithDefinedOrder(a: any, b: any, definedOrder: any): number;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export function decomposeVersion(value: any): {
|
|
2
|
+
lower: any;
|
|
3
|
+
upper: any;
|
|
4
|
+
};
|
|
5
|
+
export function composeVersion(decomposed: any): any;
|
|
6
|
+
/**
|
|
7
|
+
* Compare two versions.
|
|
8
|
+
*
|
|
9
|
+
* @param {string|number} a
|
|
10
|
+
* @param {string|number} b
|
|
11
|
+
* @return {number} -1 if a < b, 0 if a == b and 1 if a > b
|
|
12
|
+
*/
|
|
13
|
+
export function compareVersion(a: string | number, b: string | number): number;
|
|
14
|
+
/**
|
|
15
|
+
* Forms union of two versions.
|
|
16
|
+
* @param {string|number} a
|
|
17
|
+
* @param {string|number} b
|
|
18
|
+
* @return {string|number}
|
|
19
|
+
*/
|
|
20
|
+
export function unionVersion(a: string | number, b: string | number): string | number;
|
|
21
|
+
export function toBeRemoved(value: any): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* maps version values (to number)
|
|
24
|
+
* @typedef {Function} VersionMapper
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* Merge and filter two sets of version (expressions).
|
|
28
|
+
* @param {string|string[]|number|number[]} a
|
|
29
|
+
* @param {string|string[]|number|number[]} b
|
|
30
|
+
* @param {string} path location in the tree
|
|
31
|
+
* @param {Function} actions cb to notify about the actual selection
|
|
32
|
+
* @param {Object} hints
|
|
33
|
+
* @param {VersionMapper} filter
|
|
34
|
+
* @return {string|string[]|number|number[]} merged set of version expressions
|
|
35
|
+
*/
|
|
36
|
+
export function mergeVersionsWithFilter(a: string | string[] | number | number[], b: string | string[] | number | number[], path: string, actions: Function, hints: any, filter: VersionMapper): string | string[] | number | number[];
|
|
37
|
+
/**
|
|
38
|
+
* merge two sets of version (expressions)
|
|
39
|
+
* @param {string|string[]|number|number[]} a
|
|
40
|
+
* @param {string|string[]|number|number[]} b
|
|
41
|
+
* @param {string} path location in the tree
|
|
42
|
+
* @param {Function} actions cb to notify about the actual selection
|
|
43
|
+
* @param {Object} hints
|
|
44
|
+
* @return {string|string[]|number|number[]} merged set of version expressions
|
|
45
|
+
*/
|
|
46
|
+
export function mergeVersions(a: string | string[] | number | number[], b: string | string[] | number | number[], path: string, actions: Function, hints: any): string | string[] | number | number[];
|
|
47
|
+
export function mergeVersionsLargest(a: any, b: any, path: any, actions: any, hints: any): string | number | string[] | number[];
|
|
48
|
+
export function mergeVersionsSmallest(a: any, b: any, path: any, actions: any, hints: any): string | number | string[] | number[];
|
|
49
|
+
/**
|
|
50
|
+
* Same as mergeVersions but merge result are converted into
|
|
51
|
+
* numbers if possible
|
|
52
|
+
* @param {string|string[]|number|number[]} a
|
|
53
|
+
* @param {string|string[]|number|number[]} b
|
|
54
|
+
* @param {string} path location in the tree
|
|
55
|
+
* @param {Function} actions cb to notify about the actual selection
|
|
56
|
+
* @param {Object} hints
|
|
57
|
+
* @return {string|string[]|number|number[]} merged set of version expressions
|
|
58
|
+
*/
|
|
59
|
+
export function mergeVersionsPreferNumeric(a: string | string[] | number | number[], b: string | string[] | number | number[], path: string, actions: Function, hints: any): string | string[] | number | number[];
|
|
60
|
+
/**
|
|
61
|
+
* maps version values (to number)
|
|
62
|
+
*/
|
|
63
|
+
export type VersionMapper = Function;
|