hinted-tree-merger
v6.2.6
Published
merges two trees guided with hints
Downloads
712
Readme
hinted-tree-merger
merges two trees guided with hints
usage
merge array having entries identified by key
import { merge } from "hinted-tree-merger";
const r = merge(
[{ k:1, e:1}, { k:2}],
[{ k:1, e:2}, { k:3}], // 2nd. array has precedence
"",
undefined,
{
"": { key: "k" } // identify slots by property "k"
});
// r := [{ k:1 e:2 }, { k:2 }, { k:3 }]
deep copy
import { merge } from "hinted-tree-merger";
const r = merge( undefined, [ { k:1, e:2}, { k:3 }]);
// r := [{ k:1 e:2 }, { k:2 }, { k:3 }]
API
Table of Contents
- hintFor
- Actions
- mergeSkip
- mergeArrays
- merge
- hasDeleteHint
- isToBeRemoved
- hintFreeValue
- indexFor
- keyFor
- sortObjectsByKeys
- compareWithDefinedOrder
- matchingIndex
- match
- cmp
- compareVersion
- unionVersion
- VersionMapper
- mergeVersionsWithFilter
- mergeVersions
- mergeVersionsPreferNumeric
- walk
hintFor
Construct hint for a given path.
Parameters
Actions
Type: Function
Parameters
mergeSkip
Skip merging use left side always.
Parameters
a
b
path
actions
hints
mergeArrays
Parameters
merge
Merge to values.
Parameters
a
anyb
anypath
actions
Actions (optional, defaultnullAction
)hints
any
Returns any merged value
hasDeleteHint
Parameters
isToBeRemoved
Should value be removed.
Parameters
Returns Object true if fromTemplate tells is to delete value
hintFreeValue
Remove hint(s) form a value.
Parameters
value
(string | any)
Returns any value without hint
indexFor
Find best insertion point for b[i] in a.
Parameters
keyFor
Deliver key value to identify object.
Parameters
object
anyhint
Object
sortObjectsByKeys
Sort keys in source.
Parameters
source
Objectcompare
Returns Object source with keys orderd by compare function
compareWithDefinedOrder
Parameters
a
anyb
anydefinedOrder
matchingIndex
Parameters
value
any
Returns number
match
url means highest version
cmp
Parameters
Returns number
compareVersion
Compare two versions.
Parameters
Returns number -1 if a < b, 0 if a == b and 1 if a > b
unionVersion
Forms union of two versions.
Parameters
VersionMapper
maps version values (to number)
Type: Function
mergeVersionsWithFilter
Merge and filter two sets of version (expressions).
Parameters
a
(string | Array<string> | number | Array<number>)b
(string | Array<string> | number | Array<number>)path
string location in the treeactions
Function cb to notify about the actual selection (optional, defaultnullAction
)hints
Objectfilter
VersionMapper
Returns (string | Array<string> | number | Array<number>) merged set of version expressions
mergeVersions
merge two sets of version (expressions)
Parameters
a
(string | Array<string> | number | Array<number>)b
(string | Array<string> | number | Array<number>)path
string location in the treeactions
Function cb to notify about the actual selectionhints
Object
Returns (string | Array<string> | number | Array<number>) merged set of version expressions
mergeVersionsPreferNumeric
Same as mergeVersions but merge result are converted into numbers if possible
Parameters
a
(string | Array<string> | number | Array<number>)b
(string | Array<string> | number | Array<number>)path
string location in the treeactions
Function cb to notify about the actual selectionhints
Object
Returns (string | Array<string> | number | Array<number>) merged set of version expressions
walk
Iterates over all members.
Parameters
value
anypath
Array<any> (optional, default[]
)parents
(optional, default[]
)
install
With npm do:
npm install hinted-tree-merger
license
BSD-2-Clause