@amphibian/map

return items from an array or object based on a mapping function

Stats

stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
Minified + gzip package size for @amphibian/map in KB

Readme

map

build status

return items from an array or object based on a mapping function

npm install @amphibian/map
var map = require('@amphibian/map');
var array = ['zero', 'one', 'two', 'three', 'four'];

map(array, (index, i) => i); // > [0, 1, 2, 3, 4]
map(array, (index, i) => {
    if (i === 1) {
        return; // NOTE `undefined` is ignored
    }

    return i + 10;
}); // > [10, 12, 13, 14]

var object = {
    zero: {hello: true},
    one: {hello: false},
    two: {hello: true},
    three: {hello: false}
};

map(object, (key, value) => value); /* > [
    {hello: true}, {hello: false}, {hello: true}, {hello: false}
] */

// You can also stop the mapping when you're satisfied with the results
var results = map(array, (index, i, end, results) => {
    if (results.length < 2) {
        return index;
    } else {
        end();
        return index;
    }
});

console.log(results); // > ['zero', 'one', 'two']

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.