pick-by-alias
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -31,3 +31,3 @@ 'use strict' | ||
} | ||
else { | ||
else if (prop in src) { | ||
result[prop] = src[prop] | ||
@@ -34,0 +34,0 @@ } |
{ | ||
"name": "pick-by-alias", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Pick properties by aliases", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# pick-by-alias [](http://github.com/badges/stability-badges) | ||
Pick object properties by a list of aliases. May not sound as a great idea for API design, but that is really useful to avoid remembering exact option names from user point. | ||
Pick object properties [by a list of aliases]. Useful to avoid remembering exact option names from user perspective. | ||
@@ -10,3 +10,3 @@ [](https://npmjs.org/package/pick-by-alias/) | ||
let options = pick({ | ||
let {positions, color, viewport} = pick({ | ||
positions: [...], | ||
@@ -17,13 +17,11 @@ color: 'rgba(0, 100, 200, .75)', | ||
}, { | ||
positions: ['positions', 'points', 'data', 'coordinates'], | ||
color: ['colors', 'color', 'stroke'], | ||
viewport: ['viewport', 'viewBox'] | ||
positions: 'positions points data coordinates', | ||
color: 'colors color stroke', | ||
viewport: 'viewport viewBox' | ||
}) | ||
// options === {positions, color, viewport} | ||
``` | ||
### `result = pick(source, aliases)` | ||
### `result = pick(object, properties)` | ||
Return an object with properties picked by the list or dict of `aliases`. The `aliases` are matched in priority order, ie. the names going first are picked. Each alias can be an array or a comma/space-separated string. | ||
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. | ||
@@ -30,0 +28,0 @@ ```js |
@@ -51,1 +51,7 @@ 'use strict' | ||
}) | ||
t('avoid picking absent props', t => { | ||
t.deepEqual(pick({a: 1, b:2}, 'a b c'), {a: 1, b: 2}) | ||
t.end() | ||
}) |
4726
125
44