package
Hash data structure manipulation functions
npm install hashishGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Estimated unpacked size across 22 packages.
3.1 MB
Includes dependencies.
Hashish is a node.js library for manipulating hash data structures. It is distilled from the finest that ruby, perl, and haskell have to offer by way of hash/map interfaces.
Hashish provides a chaining interface, where you can do:
var Hash = require('hashish');
Hash({ a : 1, b : 2, c : 3, d : 4 })
.map(function (x) { return x * 10 })
.filter(function (x) { return x < 30 })
.forEach(function (x, key) {
console.log(key + ' => ' + x);
})
;Output:
a => 10
b => 20Some functions and attributes in the chaining interface are terminal, like
.items or .detect(). They return values of their own instead of the chain
context.
Each function in the chainable interface is also attached to Hash in chainless
form:
var Hash = require('hashish');
var obj = { a : 1, b : 2, c : 3, d : 4 };
var mapped = Hash.map(obj, function (x) {
return x * 10
});
console.dir(mapped);Output:
{ a: 10, b: 20, c: 30, d: 40 }In either case, the 'this' context of the function calls is the same object that the chained functions return, so you can make nested chains.
For each key/value in the hash, calls cb(value, key).
For each key/value in the hash, calls cb(value, key).
The return value of cb is the new value at key in the resulting hash.
For each key/value in the hash, calls cb(value, key).
The resulting hash omits key/value pairs where cb returned a falsy value.
Returns the first value in the hash for which cb(value, key) is non-falsy.
Order of hashes is not well-defined so watch out for that.
Returns the accumulated value of a left-fold over the key/value pairs.
Returns a boolean: whether or not cb(value, key) ever returned a non-falsy
value.
Mutate the context hash, merging the key/value pairs from the passed objects
and overwriting keys from the context hash if the current obj has keys of
the same name. Falsy arguments are silently ignored.
Like multi-argument update() but operate on an array directly.
Merge the key/value pairs from the passed objects into the resultant hash without modifying the context hash. Falsy arguments are silently ignored.
Like multi-argument merge() but operate on an array directly.
Return whether the hash has a key, key.
Return an Array with the values at the keys from keys.
Call cb with the present raw hash.
This function is chainable.
Filter by including only those keys in keys in the resulting hash.
Filter by excluding those keys in keys in the resulting hash.
These are attributes in the chaining interface and functions in the Hash.xxx
interface.
Return all the enumerable attribute keys in the hash.
Return all the enumerable attribute values in the hash.
Filter out values which are === undefined.
Make a deep copy of the hash.
Make a shallow copy of the hash.
Return the number of key/value pairs in the hash.
Note: use Hash.size() for non-chain mode.
Alias for length since Hash.length is masked by Function.prototype.
See also creationix's pattern/hash, which does a similar thing except with hash inputs and array outputs.
To install with npm:
npm install hashishTo run the tests with expresso:
expresso