adam
Functions to create, process and test objects.
Installation
Node
npm install adam
component install gamtiq/adam
jam install adam
bower install adam
spm install adam
AMD, <script>
Use dist/adam.js
or dist/adam.min.js
(minified version).
Usage
Node, Component, SPM
var adam = require("adam");
Jam
require(["adam"], function(adam) {
...
});
AMD
define(["path/to/dist/adam.js"], function(adam) {
...
});
Bower, <script>
<script type="text/javascript" src="path/to/dist/adam.js"></script>
<script type="text/javascript">
...
</script>
Examples
var obj = {a: 1, b: 2, c: 3};
adam.getClass([8]);
adam.getType(null);
adam.isKindOf(17, "integer");
adam.isKindOf(NaN, "!number");
adam.checkField(obj, "c", ["positive", "odd"]);
adam.checkField(obj, "b", ["real", /^7/], {filterConnect: "or"});
adam.getFreeField({a5: 5, a2: 2, a7: 7, a3: 3}, {prefix: "a", startNum: 2});
adam.getSize(obj);
adam.isSizeMore(obj, 5);
adam.isEmpty({});
adam.getFields(obj);
adam.getValues(obj);
adam.getValueKey({a: 1, b: 2, c: 3, d: 4}, 3);
adam.fromArray([{id: "a", value: 11}, {id: "b", value: 7}, {id: "c", value: 10}], "id");
adam.split({a: 1, b: 2, c: 3, d: 4, e: 5}, ["a", "d"]);
See test/adam.js
for additional examples.
API
checkField(obj: Object, field: String, filter: Any, [settings: Object]): Boolean
Check whether the field of given object corresponds to specified condition(s) or filter(s).
fromArray(list: Array, [keyField: Function | String], [settings: Object]): Object
Create object (map) from list of objects.
getClass(value: Any): String
Return class of given value (namely value of internal property [[Class]]
).
getFields(obj: Object): Array
Return list of fields of specified object.
getFreeField(obj: Object, [settings: Object]): String
Return name of first free (absent) field of specified object, that conforms to the following pattern: <prefix><number>
getSize(obj: Object): Integer
Return number of fields of specified object.
getType(value: Any): String
Return type of given value.
getValueKey(obj: Object, value, [all: Boolean]): Array | String | null
Return the name of field (or list of names) having the specified value in the given object.
getValues(obj: Object): Array
Return list of field values of specified object.
isEmpty(value: Any): Boolean
Check whether given value is an empty value i.e. null
, undefined
, empty object, empty array or empty string.
isKindOf(value: Any, kind: String): Boolean
Check whether given value has (or does not have) specified kind (type or class).
isSizeMore(obj: Object, qty: Number): Boolean
Check whether number of fields of specified object is more than the given value.
split(obj: Object, firstObjFields: Array | Object): Array
Divide given object into 2 parts: the first part includes specified fields, the second part includes all other fields.
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 Denis Sikuler
Licensed under the MIT license.