1.0.3 • Published 9 years ago

underscore-obj v1.0.3

Weekly downloads
2
License
MIT
Repository
github
Last release
9 years ago

underscore-obj

additional utility methods for underscore (mapping and filtering objects)

Map Values

This function maps the values of an object.

const _ = require( "underscore-obj" );
var obj = { foo : "oof", bar : "rab" };
var obj2 = _.mapV( obj, (v,k) => k + v );
// obj2 is { foo : "foooof", bar : "barrab" }

Map Keys

This function maps the keys of an object>

const _ = require( "underscore-obj" );
var obj = { foo : "oof", bar : "rab" };
var obj2 = _.mapK( obj, (v,k) => k + v );
// obj2 is { foooof : "oof", barrab : "rab" }

Map Keys & Values

This function maps both the keys and the values. The mapping function should return a pair of: [ key, value ]

const _ = require( "underscore-obj" );
var obj = { foo : "oof", bar : "rab" };
var obj2 = _.mapVK( obj, (v,k) => [v,k] );
// obj2 is { oof : "foo", rab : "bar" }

Filter Keys & Values

This function filters entries of an object by considering both the values and keys.

const _ = require( "underscore-obj" );
var obj = { foo : "oof", bar : "bar" };
var obj2 = _.filterVK( obj, (v,k) => v === k );
// obj2 is { bar : "bar" }
1.0.3

9 years ago

1.0.2

9 years ago

1.0.0

9 years ago