adam
Functions to create, process and test objects/maps/arrays/sets.

Installation
Node
npm install adam
bower install adam
AMD, <script>
Use dist/adam.js
or dist/adam.min.js
(minified version).
Usage ↑
Node
var adam = require("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 ↑
function inc(data) {
return ++data.value;
}
var obj = {a: 1, b: 2, c: 3, d: 4, e: 5},
s1 = Symbol("s1"),
s2 = Symbol("s2"),
proto = {a: 1},
obj2 = Object.create(proto);
proto[s1] = "s1";
obj2.b = 2;
obj2[s2] = null;
obj2.c = "str";
obj2.d = 0;
adam.getPropertySymbols(obj2);
adam.getClass([8]);
adam.getType(null);
adam.isKindOf(17, "integer");
adam.isKindOf(NaN, "!number");
adam.isKindOf(".321e+2", "numeric");
adam.checkField(obj, "c", ["positive", "odd"]);
adam.checkField(obj, "b", ["real", /^7/], {filterConnect: "or"});
adam.checkValue(-15, ["negative", /5/, {inside: [2, -7, -15, 12, 9]}]);
adam.checkValue("73", [/^\d+$/, {inside: {a: 1, b: "43", c: null}}]);
adam.checkValue("73", [/^\d+$/, {inside: {a: 1, b: "43", c: null}}], {filterConnect: "or"});
adam.getFreeField({a5: 5, a2: 2, a7: 7, a3: 3}, {prefix: "a", startNum: 2});
adam.getFreeField(new Map([["a", 3], ["key", 9], ["key-1", true]]), {prefix: "key-"});
adam.getFreeField(new Map([["a", 3], ["key", 9], ["key-1", true]]), {prefix: "key-", startNum: 1});
adam.getSize(obj);
adam.getSize(obj, {filter: "even"});
adam.getSize(obj2, {filter: ["string", "null"], filterConnect: "or"});
adam.isSizeMore(obj, 5);
adam.isSizeMore(obj2, 1, {filter: "string"});
adam.isEmpty({});
adam.getFields(obj);
adam.getFields(obj, {filter: function(value) {return value < 4;}});
adam.getFields(obj, {filter: {field: /^[d-h]/}});
adam.getFields(obj2);
adam.getFields(obj2, {filter: ["string", "false"], filterConnect: "or"});
adam.getFields(obj2, {filter: "number", limit: 2});
adam.getFields(obj2, {filter: {field: "symbol"}})
adam.getFields(obj2, {filter: "number", limit: 7, pairs: true});
adam.getFields(obj2, {filter: "number", pairs: "list"});
adam.getFields(new Map([[obj, 1], [obj2, false], ["c", 5]]), {filter: {field: "object"}});
adam.getFields(new Map([["a", 1], ["b", false], ["c", 5]]), {filter: "number", pairs: "obj"});
adam.getValues(obj);
adam.getValues(obj, {filter: {field: /a|c/}});
adam.getValues(new Map([[obj, "a"], [obj2, 2], ["obj3", 3]]), {filter: {field: "object"}});
adam.getValueKey(obj, 3);
adam.fromArray([{id: "a", value: 11}, {id: "b", value: 7}, {id: "c", value: 10}], "id");
adam.select(["negative", "odd"], [null, 4, NaN, 7, false, -2, "", 0, -5, 3, null, -9]);
adam.select(["negative", "odd"], [null, 4, NaN, 8, false, 2, "", 0, 30, 4, false], {filterConnect: "or"});
adam.select(["negative", "odd"], [null, 4, NaN, 8, false, 2, "", 0, 30, 4, false], {filterConnect: "or", defaultValue: -3});
adam.select([{field: /[c-g]/}, "odd"], {a: [3, 5, 2], b: 1, c: 0, d: "-7", e: 4, f: -2, g: -1, h: null, i: -7, j: true, k: -5});
adam.select(["negative", "even"], new Set([null, 4, NaN, 8, -1, false, -2, "", 0, "beta", -30, 4, true]));
adam.split(obj, ["a", "d"]);
adam.split(obj, null, {filter: "odd"});
adam.split(obj, null, {filter: ["even", /3/], filterConnect: "or"});
adam.split(new Map([["a", false], [obj, 2], [false, obj2], [true, null]]), null, {filter: "true"});
adam.remove({a: 1, b: "2", c: 3}, "string");
adam.remove([1, 2, 3, 4, 5], "even");
adam.remove(new Set([1, 2, 3, 4, 5]), "odd");
adam.empty({x: -1, y: 9});
adam.reverse({a: "x", b: "files"});
adam.reverse("eval");
adam.reverse(new Map([[obj, 1], [obj2, 2]]));
adam.transform("7.381", "integer");
adam.copy(obj, {b: "no", z: "a"});
adam.copy(obj, {b: "no", z: "a"}, {filter: "odd"});
adam.copy(obj, {b: "no", z: "a"}, {filter: "even", transform: inc});
adam.change({a: 1, b: 2, c: 3}, "reverse");
adam.change({a: 10, b: 28, c: -3, d: null, e: "zero = 0"}, "empty", {filter: /0/});
adam.change([1, 2, 3, 4, 5], "reverse", {filter: "even"});
adam.map(obj, "reverse", {filter: "odd"});
adam.map(["1", "2", "3"], "number");
See test/adam.js
for additional examples.
API ↑
See docs
.
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-2020 Denis Sikuler
Licensed under the MIT license.