npm install bareutilContains recurring goto methods I encounter during development
If you come across any problems, please create an issue
``javascript
var bare = require("bareutil");
var misc = bare.misc;
var obj = bare.obj;
var val = bare.val;
//Expose to client *.com/bare.misc.js using express
var express = require('express');
var app = express();
bare.misc.expose(app, express);
bare.obj.expose(app, express);
bare.val.expose(app, express);
`
`bash`
cd bareutil
npm run test
npm run coverage
All validation is done by performing a check on the object's constructor
1. bare.val.undefined(obj) - var obj; is truevar obj;
2. defined(obj) - is falsefunction() { }
3. function(obj) - is true{ }
4. object(obj) - is true12
5. number(obj) - is true"Hello"
6. string(obj) - is truenew Date()
7. date(obj) - is truefalse
8. boolean(obj) - is true\(w)\g
9. regex(obj) - is true*
10. promise(obj) - new Promise() is true
Functional programming for objects
Array-like methods have 2 required and 1 optional parameter:
1. obj - The object to perform the operation on
2. cb(key, value) - Function called for each element in the object
3. allowFuncs - Will include functions in iterations
###### Array-like - function(obj, cb, allowFuncs)
1. bare.obj.find - Returns value if a match is found
Performs a strict comparison when a non-function is provided
2. each - Executes cb once per property
3. map - Performs transformation on object's values. Keys are preserved.
4. reduce - Provides an accumulator to reduce object down to a single value
cb(accumulated, value, key)
5. filter - Constructs new object from calls that return true. Keys are preserved.
6. keys - An array of the keys of the object
7. values - An array of the values of the object
8. toArray - Transforms into an array of {key, value} pairs
9. sum - Reduces by adding. Return true/false from cb to sum value
###### Other
1. bare.obj.increment(obj, map) - Increment each matching key by value
2. write(obj, data) - Assigns all key/values from data to obj
3. merge(obj, data) - Assigns all matching key/values from data to obj
4. slim(obj, prop) - Flattens a nested object by the property
5. copy(obj) - Creates a shallow copy the object
6. has(obj, prop) - true if object has that property definedtrue
7. contains(obj, coll) - if obj shares all keys with coll
1. bare.misc.supplant(str, values) - String substitution, {key} or $key syntax
2. random(length, possible) - Random string from possible characters
3. once(fn, context) - Calls functions with context only once. Subsequent calls return result
4. throwLater(err, msg) - Throws error sometime later
5. throwWith(msg) - Returns throw later function with msg prepended
html
Not available for server-side yet, hasn't been tested. Don't use it
``