util-map

Map over an object, array or string

Usage no npm install needed!

<script type="module">
  import utilMap from 'https://cdn.skypack.dev/util-map';
</script>

README

Map

NPM version Build status Test coverage Gittip

Map over an object, array or string and keep the result as the same type.

Installation

npm install util-map --save

Usage

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'

License

MIT