package
array.map equivalent that also works on Objects and Strings
npm install map-propertiesGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Estimated unpacked size across 3 packages.
51.6 kB
Includes dependencies.
array.map equivalent that also works on Objects and Strings
$ npm install --save map-propertiesvar map = require('map-properties');
var mapFn = function(val) {
return val + val.toUpperCase();
};
map(['a', 'b'], mapFn);
// => ['aA', 'bB']
map({a: 'b', c: 'd'}, mapFn);
// => {a: 'bB', c: 'dD'}
map('ab', mapFn);
// => 'aAbB'required
Type: string|object|array
The source from which to map properties.
required
Type: callback(propertyValue, propertyName, source, destination)
A callback that maps the properties to their new values. It is called with the following arguments:
propertyValue - the value of the property on the source object.propertyName - the name (or index) of the propertysource - the source object/array/string from which the properties are being mapped.destination - the destination object on to which the properties are being mapped.optional
If provided, will be the this value during execution of mapFn.
optional
Explicitly provide the destination object, otherwise it will be created automatically.
var destination = {};
map(source, mapFn, null, destination);destination
MIT © James Talmage