Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hashish

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hashish

Hash data structure manipulation functions

  • 0.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
68K
decreased by-12.32%
Maintainers
0
Weekly downloads
 
Created
Source

Hashish

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 => 20

Some 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.

Methods

forEach(cb)

For each key/value in the hash, calls cb(value, key).

map(cb)

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.

filter(cb)

For each key/value in the hash, calls cb(value, key). The resulting hash omits key/value pairs where cb returned a falsy value.

detect(cb)

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.

reduce(cb)

Returns the accumulated value of a left-fold over the key/value pairs.

some(cb)

Returns a boolean: whether or not cb(value, key) ever returned a non-falsy value.

update(obj1, [obj2, obj3, ...])

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.

updateAll([ obj1, obj2, ... ])

Like multi-argument update() but operate on an array directly.

merge(obj1, [obj2, obj3, ...])

Merge the key/value pairs from the passed objects into the resultant hash without modifying the context hash. Falsy arguments are silently ignored.

mergeAll([ obj1, obj2, ... ])

Like multi-argument merge() but operate on an array directly.

has(key)

Return whether the hash has a key, key.

valuesAt(keys)

Return an Array with the values at the keys from keys.

tap(cb)

Call cb with the present raw hash. This function is chainable.

extract(keys)

Filter by including only those keys in keys in the resulting hash.

exclude(keys)

Filter by excluding those keys in keys in the resulting hash.

Attributes

These are attributes in the chaining interface and functions in the Hash.xxx interface.

keys

Return all the enumerable attribute keys in the hash.

values

Return all the enumerable attribute values in the hash.

compact

Filter out values which are === undefined.

clone

Make a deep copy of the hash.

copy

Make a shallow copy of the hash.

length

Return the number of key/value pairs in the hash. Note: use Hash.size() for non-chain mode.

size

Alias for length since Hash.length is masked by Function.prototype.

See Also

See also creationix's pattern/hash, which does a similar thing except with hash inputs and array outputs.

Installation

To install with npm:

npm install hashish

To run the tests with expresso:

expresso

Keywords

FAQs

Package last updated on 23 Jul 2011

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc