Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

map-utils

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

map-utils

map util functions, map, utils, pick, pluck, set, exists

  • 0.4.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

map-utils Build Status

works with great with Array.map

exists

return true for any value other than ull or undefined

var utils = require('map-utils');

utils.exists(null);      // false
utils.exists(undefined); // false
utils.exists('foo');     // true

pick

accepts keys and returns a function which accepts an object and return a new object with the keys specified

var utils = require('map-utils');
var arr = [
  {
    foo: 1,
    bar: 1,
    qux: 1
  },
  {
    foo: 2,
    bar: 2,
    qux: 2
  }
];

arr.map(utils.pick('foo', 'bar'));
/*
  [
    {
      foo: 1,
      bar: 1
    },
    {
      foo: 2,
      bar: 2
    }
  ]
*/

omit

accepts keys and returns a function which accepts an object and returns a new object without the keys specified

var utils = require('map-utils');
var arr = [
  {
    foo: 1,
    bar: 1,
    qux: 1
  },
  {
    foo: 2,
    bar: 2,
    qux: 2
  }
];

arr.map(utils.omit('foo', 'bar'));
/*
  [
    {
      qux: 1
    },
    {
      qux: 2
    }
  ]
*/

pluck

accepts keys and returns a function which accepts an object and returns the value of the key specified

var utils = require('map-utils');
var arr = [
  {
    foo: 1,
    bar: 1,
    qux: 1
  },
  {
    foo: 2,
    bar: 2,
    qux: 2
  }
];

arr.map(utils.pluck('foo')); // [1, 2]

set

accepts obj or key val arguments and returns a function which accepts an object which those key/values will be set on

var utils = require('map-utils');
var arr1 = [
  {
    foo: 1,
    bar: 1
  },
  {
    foo: 2,
    bar: 1
  }
];
var arr2 = [
  {
    foo: 1
  },
  {
    foo: 2
  }
];

arr1.map(utils.set('qux', 1));
arr2.map(utils.set({ bar:1, qux:1 }));
/* both arr and arr2 becom:
  [
    {
      foo: 1,
      bar: 1,
      qux: 1
    },
    {
      foo: 2,
      bar: 1,
      qux: 1
    }
  ]
*/

unset

accepts keys and returns a function which accepts an object which those keys will be deleted from

var utils = require('map-utils');
var arr = [
  {
    foo: 1,
    bar: 1,
    qux: 1
  },
  {
    foo: 2,
    bar: 2,
    qux: 2
  }
];

arr.map(utils.unset('foo', 'bar'));
/* arr becomes:
  [
    {
      foo: 1,
      bar: 1
    },
    {
      foo: 2,
      bar: 2
    }
  ]
*/

Keywords

FAQs

Package last updated on 23 Mar 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc