Data structure manipulation tools.
- Copyright:
- Mat. 2018-present
- License:
- Apache-2.0
- Source:
Methods
(inner) access(input, pathopt, defopt) → {OutputType|undefined}
Apply path to an object o. Return element reachable through
that path or def value.
Example:
access({ a: { b: [10, { c: 42 }] } }, ["a", "b", 1, "c"]) === 42
- Source:
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
input |
InputType
|
|||
path |
<optional> |
[] | ||
def |
<optional> |
Returns:
- Type:
-
OutputType|undefined
(inner) assign(base, ext) → {Object}
Safe version of standard JavaScript Object.assign();
Throws when base and ext have conflicting keys - prevents
accidental overwrite.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
base |
Object
|
|
ext |
Object
|
Returns:
- Type:
-
Object
base
(inner) clone(o) → {JSAnyArrObj}
Do the deep-copy of any JavaScript object that doesn't contain functions.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
o |
JSAnyArrObj
|
Returns:
- Type:
-
JSAnyArrObj
(inner) dfs(tree, f, childrenopt) → {any}
Depth-first search. Executes certain operation f
on each tree node in reduce-like fashion, accumulating
intermediate results.
- Source:
- See:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
tree |
Object
|
Tree-like structure. |
|
f |
function
|
Function to be executed on each node.
Its signature is as follows:
|
|
children |
function
|
<optional> |
Function that should accept |
Returns:
- Type:
-
any
Accumulated result for all subtree nodes.
(inner) dict(entries) → {Object}
Construct Object from the result of Object.entries() call.
entries = [[k1, v1], ..., [kn, vn]]
Imitates Python's dict().
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
entries |
Array.<Array>
|
Returns:
- Type:
-
Object
(inner) hashAccessor() → {function}
Construct function appropriate to use as the children argument
in the struct.dfs function. Use it with struct.dfs to
enumerate on any javascript object.
- Source:
- See:
Returns:
- Type:
-
function
(inner) isBasicData(c) → {Boolean}
Check if value is of BasicData type. Non recursive check.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
c |
unknown
|
Returns:
- Type:
-
Boolean
(inner) isBasicDataOrUndefined(c) → {Boolean|undefined}
Check if value is of BasicData of undefined type. Non recursive check.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
c |
unknown
|
Returns:
- Type:
-
Boolean|undefined
(inner) keyAccessor(…path) → {function}
Construct function appropriate to use as the children argument
in the struct.dfs function. Use it with struct.dfs if your
tree-like structure contains children organized as arrays.
E.g. if a node is defined as follows:
node = { val: "something", props: { num: 14, ch: [node1, node2] } }
then keyAccessor should be defined in this way:
keyAccessor("props", "ch")
keyAccessor called without arguments (keyAccessor()) returns
hashAccessor.
- Source:
- See:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
path |
Number
|
String
|
<repeatable> |
A path leading from the |
Returns:
- Type:
-
function
(inner) objectMap(o, f)
Map (iteration) on objects - shallow.
o-Objectto enumerate on.f-Functionto call on each key, params:this- bound to the enumerated object,kv- current[key, value]array,
f should return [key, value] array.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
o |
Object |
|
f |
Function |
Returns:
Mapped object
(inner) objectReduce(o, f, init)
Reduce (fold) on objects - shallow.
o-Objectto enumerate on.f-Functionto call on each key, params:this- bound to the enumerated object,acc- accumulated value,kv- current[key, value]array,
init- accumulated value initializer,
f should return value of the same type as init.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
o |
Object |
|
f |
Function |
|
init |
T |
Returns:
T
(inner) rewrite(o, path, v) → {Data}
Rewrite part of an object (first argument) reachable through passed path (second argument) with provided value (third argument). Creates new object with new data and references to all unchanged parts of the old object. This function implements copy-on-write semantics.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
o |
Data
|
|
path |
DataIndex
|
|
v |
Data
|
Returns:
- Type:
-
Data
(inner) swap(o) → {JSAnyObj}
When o == { a: "b", c: "d" }
then swap(o) == { b: "a", d: "c" }.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
o |
JSAnyObj
|
Returns:
- Type:
-
JSAnyObj