JSPM

pick-by-alias

1.2.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 335099
  • Score
    100M100P100Q187426F
  • License MIT

Pick properties by aliases

Package Exports

  • pick-by-alias

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (pick-by-alias) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

pick-by-alias unstable

Pick object properties by synonyms. Useful to avoid remembering exact option names from user perspective.

npm install pick-by-alias

let pick = require('pick-by-alias')

let result = pick({
  positions: [...],
  color: 'rgba(0, 100, 200, .75)',
  viewBox: null,
  extra: 123
}, {
  positions: 'positions points data coordinates',
  color: 'colors color stroke',
  viewport: 'viewport viewBox'
})

pick(object, properties, keepRest=false)

Return an object with properties picked by the list or dict with aliases. Aliases are matched in priority order, ie. first matching name is picked. Each alias can be an array or a comma/space-separated string.

// pick by dict
let {a, b} = pick(src, {a: ['a', 'b', 'c'], b: 'd e f'})

// pick by list
let {c, d, e} = pick(src, ['c', 'd', 'e'])

// pick by string
let {f, g} = pick(src, 'f g')

keepRest defines if not listed object properties should be transfered to resulting object or discarded.

  • defined − get first non-undefined out of a list of values
  • update-diff − update object state by mapping diff.

License

(c) 2017 Dima Yv. MIT License