Skip to content

Repository files navigation

map-shape

CircleCICoverage Statussemantic-releaseCommitizen friendlynpm version

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

importmapShapefrom'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.

importmapShapefrom'map-shape/fp'mapShape({foo: String,bar: parseInt,})({foo: 1,bar: '2',baz: 'hello',})// outputs { foo: '1', bar: 2 }

About

apply mapping functions to specific properties of an object

Topics

Resources

Stars

0 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages