Constructor
new Quercus(pairArropt)
- Source:
- Since:
- 1.0.0
Quercus main constructor.
Example
// Empty tree
const q = new Quercus();
// Tree initialized with a path-value pair
const q2 = new Quercus([["foo", bar], 5]);
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
pairArr |
Array.<Array.<any>, any> |
<optional> |
[]
|
Optional array of path-value pairs to init. |
Extends
- Map
Methods
(static) isQuercus(val) → {boolean}
- Source:
- Since:
- 1.0.0
Checks if a value is a Quercus instance.
Example
const q = new Quercus([["foo", "bar"], 5]);
Quercus.isQuercus(q)
// => true
Quercus.isQuercus(q.getPath(["foo"]))
// => true
Quercus.isQuercus("foo")
// => false
Parameters:
| Name | Type | Description |
|---|---|---|
val |
any | Value to check. |
Returns:
If the value is a Quercus instance.
- Type
- boolean
getPath(path) → {any|null}
- Source:
- Since:
- 1.0.0
Returns value of a given path.
If the path could not be found, null is returned.
Example
const q = new Quercus([
[["foo", "bar"], 5],
[["foo", "bizz"], 12],
[["bar", "fazz"], 560]
]);
q.getPath(["foo", "bar"]);
// => 5
q.getPath(["bar"]);
// => Quercus{"fazz": 560}
q.getPath(["lorem"]);
// => null
Parameters:
| Name | Type | Description |
|---|---|---|
path |
Array.<any> | Path to get. |
Returns:
Value of the node, or null if it is not found.
- Type
- any | null
hasPath(path, quercusNodesAreTruthyopt) → {boolean}
- Source:
- Since:
- 1.0.0
Checks if a given path exists.
Example
const q = new Quercus([
[["foo", "bar"], 5],
[["foo", "bizz"], 12],
[["bar", "fazz"], 560]
]);
q.hasPath(["foo", "bar"]);
// => true
q.hasPath(["foo"]);
// => false
q.hasPath(["foo"], true);
// => true
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
path |
Array.<any> | Path to check. |
||
quercusNodesAreTruthy |
boolean |
<optional> |
false
|
If nodes should be considered to be truthy. |
Returns:
If the given path exists.
- Type
- boolean
setPath(path, val) → {Quercus|null}
- Source:
- Since:
- 1.0.0
Sets value of a given path.
If the given path is empty, null is returned. If the value was set successfully, the value's Node is returned.
Example
const q = new Quercus();
q.setPath(["foo", "bar"], 5);
// => Quercus{"bar": 5}
q.setPath(["bar", "fazz"], 560);
// => Quercus{"fazz": 560}
q.setPath([], "foo");
// => null
Parameters:
| Name | Type | Description |
|---|---|---|
path |
Array.<any> | Path to set. |
val |
any | Value to set. |
Returns:
Node that was set on, or null if it could not be set.
- Type
- Quercus | null