Map over an object, array or string and keep the result as the same type.
npm install util-map --save
var map = require('util-map');
// Map over objects.
map({
a: 0,
b: 1,
c: 2
}, function (value, key, obj) {
return value + 10;
});
//=> { a: 10, b: 11, c: 12 }
// Map over arrays.
map(['a', 'b', 'c'], function (value, key, obj) {
return String.fromCharCode(value.charCodeAt(0) + 1);
});
// => ['b', 'c', 'd']
// Map over strings.
map('abc', function (value, key, obj) {
return key + 1;
});
//=> '123'
MIT