pick-by-alias
Pick properties by aliases
Last updated 3 years ago by dfcreative .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install pick-by-alias 
SYNC missed versions from official npm registry.

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.

Related

  • 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

Current Tags

  • 1.2.0                                ...           latest (3 years ago)

5 Versions

  • 1.2.0                                ...           3 years ago
  • 1.1.2                                ...           3 years ago
  • 1.1.1                                ...           3 years ago
  • 1.1.0                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 25
This Week 285
This Month 718
Last Day 56
Last Week 373
Last Month 1,713
Dependencies (0)
None
Dev Dependencies (1)

Copyright 2014 - 2017 © taobao.org |