map-shape
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

map-shape

CircleCI Coverage Status semantic-release Commitizen friendly npm version

One of those missing lodash functions. Includes TypeScript definitions and Flow definitions (they aren't prefect, there are some edge cases...)

import mapShape from 'map-shape'

mapShape(
  {
    foo: 1,
    bar: '2',
    baz: 'hello',
  },
  {
    foo: (value, key, obj) => `${value} ${key} ${obj.baz}`,
    bar: value => parseInt(value),
  }
)
// outputs { foo: '1 foo hello', bar: 2 }

Each mapper function is called with three arguments:

  • value - the value of the input property
  • key - the key of the input property
  • obj - the input object

Notes

If the input object is null, returns null. If the input object is undefined, returns undefined.

FP Version

Works better with lodash/fp. Only passes the value to each mapper function.

import mapShape from 'map-shape/fp'

mapShape({
  foo: String,
  bar: parseInt,
})({
  foo: 1,
  bar: '2',
  baz: 'hello',
})
// outputs { foo: '1', bar: 2 }

/map-shape/

    Package Sidebar

    Install

    npm i map-shape

    Weekly Downloads

    3

    Version

    2.0.0

    License

    MIT

    Unpacked Size

    407 kB

    Total Files

    20

    Last publish

    Collaborators

    • jedwards1211