traverse.js
v0.1.1
Published
A cascading data traversal library.
Downloads
4
Maintainers
Readme
traverse.js
A cascading data traversal library
API Reference
.data([dataset])
- Loads the dataset into traverse. You should be assigning an array to this only.
Example:
t.data([1,2,3,4,5]);
.gt([int|string])
Evaluates the dataset for everything greater than the integer or string.
Example:
var dataset = t.data([1,2,3,4,5]).gt(3).result();
console.log(dataset);
//Returns [4,5];
.gte([int|string])
Evaluates the dataset for everything greater than or equal to the integer or string.
Example:
var dataset = t.data([1,2,3,4,5]).gte(3).result();
console.log(dataset);
//Returns [3, 4,5];
.lt([int|string])
Evaluates the dataset for everything less than to the integer or string.
Example:
var dataset = t.data([1,2,3,4,5]).lt(3).result();
console.log(dataset);
//Returns [1,2];
.lte([int])
Evaluates the dataset for everything less than or equal to the integer or string.
Example:
var dataset = t.data([1,2,3,4,5]).lte(3).result();
console.log(dataset);
//Returns [1,2,3];
.findByValue([int|string])
Evaluates the dataset to find everything equal to that value
Example:
var dataset = t.data([1,2,3,2,4,5]).findByValue(2).result();
console.log(dataset);
//Returns [2,2];
.findByValues([array])
Evaluates the dataset to find everything equal to any value in the array.
Example:
var dataset = t.data([1,2,3,2,4,5]).findByValues([2,3,4]).result();
console.log(dataset);
//Returns [2,2,3,4];
.findByKey([int|string])
Evaluates the dataset to find everything that has that key
Example:
var kd = [
{ "key": 1 },
{ "notKey": 2 },
{ "notKey2": 3 },
{ "key": 4 }
]
var dataset = t.data(kd).findByKey("key").result();
console.log(dataset);
//Returns [
{ "key": 1 },
{ "key": 4 }
];
.findByKeys([int|string])
Evaluates the dataset to find everything that has that key
Example:
var kd = [
{ "key": 1 },
{ "notKey": 2 },
{ "notKey2": 3 },
{ "key": 4 },
{ "key2": 9001 }
]
var dataset = t.data(kd).findByKeys(["key", "key2"]).result();
console.log(dataset);
//Returns [
{ "key": 1 },
{ "key": 4 },
{ "key2": 9001}
];
.sortObjKeys([ASC,DESC])
Sorts all the keys in an object.
Example:
var obj = {"b": 1, "a": 2, "c": 3};
var sorted = t.data(obj).sortObjKeys("ASC").result();
console.log(obj);
//Returns {
"c": 2,
"b": 1,
"a": 3
}
var sorted = t.data(obj).sortObjKeys("DESC").result();
console.log(obj);
//Returns {
"a": 2,
"b": 1,
"c": 3
}
.sortValues([ASC,DESC])
Sorts all the values in the object.
Example:
var dataset = [2,3,1];
var sorted = t.data(obj).sortValues("ASC").result();
console.log(obj);
//Returns [3,2,1]
var sorted = t.data(obj).sortValues("DESC").result();
console.log(obj);
//Returns [1,2,3]
.sortByKey([ASC,DESC], key)
Evaluates sorts all the keys in the object.
Example:
var dataset = [
{
"key": 5,
},
{
"key": 2
},
{
"key": 1
}
];
var sorted = t.data(obj).sortByKey("ASC", "key").result();
console.log(obj);
//Returns
[
{key: 5}, {key: 2}, {key: 1}
]
var sorted = t.data(obj).sortByKey("DESC", "key").result();
console.log(obj);
//Returns
[
{key: 1}, {key: 2}, {key: 5}
]