teo
Functions to test/check, filter, find and process/transform objects.
Installation
Node
npm install teo
Component
component install gamtiq/teo
Jam
jam install teo
Bower
bower install teo
JSPM
jspm install teo
SPM
spm install teo
AMD, <script>
Use dist/teo.js
or dist/teo.min.js
(minified version).
Usage
Node, Component, JSPM, SPM
var teo = ;
Duo
var teo = ;...
Jam
;
JSPM
System;
AMD
;
Bower, <script>
<!-- Use bower_components/teo/dist/teo.js if the library was installed by Bower -->
Examples
teo; // trueteo; // falseteo; // false teo; // falseteo; // true var obj = {};objSymbol"a" = null;teo; // falseteo; // true teo; // trueteo; // trueteo; // trueteo; // falseteo; // false teo; // trueteo; // falseteo; // true teo; // falseteo; // true var personList = name: "Adam" age: 27 married: true children: 1 name: "Eva" age: 23 married: true children: 1 name: "Carl" age: 59 married: true children: 3 name: "Daniel" age: 17 married: false children: 0 name: "Gloria" age: 28 married: false children: 1 name: "Viola" age: 35 married: true children: 4 name: "Leonardo" age: 61 married: false children: 1 name: "Patricia" age: 44 married: false children: 2; teo; // [true, "ret"]teo; // 4teo; // ["Carl", "Viola", "Leonardo", "Patricia"] teo; // 4teo; // {name: "Leonardo", age: 61, married: false, children: 1} teo; // {a: 1, b: 2, c: false, d: "delta", e: false, f: undefined} teo; // {n_a5: 1, b3: "center", c5: null, d: "delta", n_e8: -5, field9: 99, n_g99: -38} { var value = contextvalue bNoValue = value == null sType = typeof value; if contexttest return bNoValue || sType === "object" || sType === "string" && /^-?\d+$/; else return bNoValue ? 0 : Numbervalue; } teo;// returns// {// a: "abc",// b: 25,// c: {// d: 0,// e: "eclipse",// f: {// g: 0,// h: -59,// i: "JS 2015"// }// }// }
See tests for additional examples.
API
isObject(value): Boolean
Check whether value is real object (not array nor function).
isEmpty(obj: Object, [ignoreSymbolFields: Boolean]): Boolean
Check whether object do not contain any fields.
test(obj: Object, filter: Object | Function | Array | String): Boolean
Check whether object conforms to specified condition/filter.
filterList(list: Array, filter: Object | Function | Array | String, [settings: Object]): Array | Integer
Form new array containing elements from the source array which conform to the given condition (filter) or calculate quantity of such elements.
findItemIndex(list: Array, filter: Object | Function | Array | String): Integer
Return the index of the first element in the array that conforms to the given condition (filter).
findItem(list: Array, filter: Object | Function | Array | String): Any
Return the first element in the array that conforms to the given condition (filter).
map(source: Object, action: Function | Object, [settings: Object]): Object
Execute the specified action for fields of the object and return the object containing results of processing.
See doc
folder for details.
Related projects
Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
License
Copyright (c) 2014-2015 Denis Sikuler
Licensed under the MIT license.