digger-utils
Small utils library shared between the digger.io and digger libraries
install
as a node module:
$ npm install digger-utils
or in the browser using browserify
methods
diggerid
returns a compact uuid using hat
var utils = ; var id = utils; // id = 95a4bdcc8dc1c7a16da87da7c4b07c38
littleid
returns a random string of (chars) length
var utils = ; var id = utils; // id = d0cd49
isdiggerid
A naive test to see if a string is a digger id (by checking the length - needs work)
escapeRegexp
parses a string so it will match literally in a regular expression
var utils = ; var match = '{[]}'; // this will not match as a RegExpvar escaped = utils; // escaped = \{\[\]\}
json_request
returns a pure javascript object representing the passed HTTP req
var utils = ; // GET /apples.html app
isArray
Returns true is the passed argument is actually an array
toArray
Converts the given argument into an array (useful for 'arguments')
is_object_empty
Returns true if the given object has no keys
strip_private_fields
Removes any field starting with an '_' from the given object
extend
uses the extend module so we can deep extend objects
combine_tree_results
takes a list of containers and appends ones that find their parent in the list
var flat_list_of_containers = ...; var tree_of_containers = utils;
inherits
A copy of node utils.inherits for inheriting classes
is_server
Returns true if running on node.js - false if on the browser
moduleloader
Takes 2 module names - one for node.js and one for the browser and requires the correct one
licence
MIT