object.pick
Advanced tools
Comparing version 1.1.1 to 1.1.2
15
index.js
@@ -10,10 +10,10 @@ /*! | ||
var isObject = require('isobject'); | ||
module.exports = function pick(obj, keys) { | ||
var res = {}; | ||
var i = 0; | ||
if (typeof obj !== 'object') { | ||
return res; | ||
if (!isObject(obj) && typeof obj !== 'function') { | ||
return {}; | ||
} | ||
var res = {}; | ||
if (typeof keys === 'string') { | ||
@@ -27,5 +27,6 @@ if (keys in obj) { | ||
var len = keys.length; | ||
var idx = -1; | ||
while (len--) { | ||
var key = keys[i++]; | ||
while (++idx < len) { | ||
var key = keys[idx]; | ||
if (key in obj) { | ||
@@ -32,0 +33,0 @@ res[key] = obj[key]; |
{ | ||
"name": "object.pick", | ||
"description": "Returns a filtered copy of an object with only the specified keys, like `pick` from lo-dash / underscore.", | ||
"version": "1.1.1", | ||
"description": "Returns a filtered copy of an object with only the specified keys, similar to `_.pick` from lodash / underscore.", | ||
"version": "1.1.2", | ||
"homepage": "https://github.com/jonschlinkert/object.pick", | ||
"author": { | ||
"name": "Jon Schlinkert", | ||
"url": "https://github.com/jonschlinkert" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/jonschlinkert/object.pick.git" | ||
}, | ||
"author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"repository": "jonschlinkert/object.pick", | ||
"bugs": { | ||
"url": "https://github.com/jonschlinkert/object.pick/issues" | ||
}, | ||
"license": { | ||
"type": "MIT", | ||
"url": "https://github.com/jonschlinkert/object.pick/blob/master/LICENSE" | ||
}, | ||
"files":[ "index.js"], | ||
"license": "MIT", | ||
"files": [ | ||
"index.js" | ||
], | ||
"main": "index.js", | ||
@@ -29,5 +22,9 @@ "engines": { | ||
}, | ||
"dependencies": { | ||
"isobject": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"mocha": "*", | ||
"should": "^4.0.4" | ||
"gulp-format-md": "^0.1.7", | ||
"mocha": "^2.4.5", | ||
"vinyl": "^1.1.1" | ||
}, | ||
@@ -37,3 +34,29 @@ "keywords": [ | ||
"pick" | ||
] | ||
} | ||
], | ||
"verb": { | ||
"run": true, | ||
"toc": false, | ||
"layout": "default", | ||
"tasks": [ | ||
"readme" | ||
], | ||
"plugins": [ | ||
"gulp-format-md" | ||
], | ||
"related": { | ||
"list": [ | ||
"get-value", | ||
"set-value", | ||
"mixin-deep", | ||
"extend-shallow" | ||
], | ||
"highlight": "object.omit" | ||
}, | ||
"reflinks": [ | ||
"verb" | ||
], | ||
"lint": { | ||
"reflinks": true | ||
} | ||
} | ||
} |
@@ -1,9 +0,13 @@ | ||
# object.pick [![NPM version](https://badge.fury.io/js/object.pick.svg)](http://badge.fury.io/js/object.pick) [![Build Status](https://travis-ci.org/jonschlinkert/object.pick.svg)](https://travis-ci.org/jonschlinkert/object.pick) | ||
# object.pick [![NPM version](https://img.shields.io/npm/v/object.pick.svg)](https://www.npmjs.com/package/object.pick) [![Build Status](https://img.shields.io/travis/jonschlinkert/object.pick.svg)](https://travis-ci.org/jonschlinkert/object.pick) | ||
> Returns a filtered copy of an object with only the specified keys, like `pick` from lo-dash / underscore. | ||
> Returns a filtered copy of an object with only the specified keys, similar to `_.pick` from lodash / underscore. | ||
## Install with [npm](npmjs.org) | ||
You might also be interested in [object.omit](https://github.com/jonschlinkert/object.omit). | ||
```bash | ||
npm i object.pick --save | ||
## Install | ||
Install with [npm](https://www.npmjs.com/): | ||
```sh | ||
$ npm install object.pick --save | ||
``` | ||
@@ -15,3 +19,2 @@ | ||
## Usage | ||
@@ -29,21 +32,49 @@ | ||
## Run tests | ||
## Related projects | ||
```bash | ||
npm test | ||
* [extend-shallow](https://www.npmjs.com/package/extend-shallow): Extend an object with the properties of additional objects. node.js/javascript util. | [homepage](https://github.com/jonschlinkert/extend-shallow) | ||
* [get-value](https://www.npmjs.com/package/get-value): Use property paths (` a.b.c`) to get a nested value from an object. | [homepage](https://github.com/jonschlinkert/get-value) | ||
* [mixin-deep](https://www.npmjs.com/package/mixin-deep): Deeply mix the properties of objects into the first object. Like merge-deep, but doesn't clone. | [homepage](https://github.com/jonschlinkert/mixin-deep) | ||
* [set-value](https://www.npmjs.com/package/set-value): Create nested values and any intermediaries using dot notation (`'a.b.c'`) paths. | [homepage](https://github.com/jonschlinkert/set-value) | ||
## Contributing | ||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/object.pick/issues/new). | ||
## Building docs | ||
Generate readme and API documentation with [verb](https://github.com/verbose/verb): | ||
```sh | ||
$ npm install verb && npm run docs | ||
``` | ||
Or, if [verb](https://github.com/verbose/verb) is installed globally: | ||
```sh | ||
$ verb | ||
``` | ||
## Running tests | ||
Install dev dependencies: | ||
```sh | ||
$ npm install -d && npm test | ||
``` | ||
## Author | ||
**Jon Schlinkert** | ||
+ [github/jonschlinkert](https://github.com/jonschlinkert) | ||
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | ||
* [github/jonschlinkert](https://github.com/jonschlinkert) | ||
* [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | ||
## License | ||
Copyright (c) 2015-2015 Jon Schlinkert | ||
Released under the MIT license | ||
Copyright © 2016 [Jon Schlinkert](https://github.com/jonschlinkert) | ||
Released under the [MIT license](https://github.com/jonschlinkert/object.pick/blob/master/LICENSE). | ||
*** | ||
_This file was generated by [verb](https://github.com/assemble/verb) on February 13, 2015._ | ||
_This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on March 21, 2016._ |
5525
4
29
78
1
3
+ Addedisobject@^2.0.0
+ Addedisarray@1.0.0(transitive)
+ Addedisobject@2.1.0(transitive)