-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
226 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# EditorConfig is awesome: http://EditorConfig.org | ||
|
||
# top-most EditorConfig file | ||
root = true | ||
|
||
# Unix-style newlines with a newline ending every file | ||
[*] | ||
end_of_line = lf | ||
charset = utf-8 | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
# Set default charset | ||
[*.js] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[{package.json,.travis.yml}] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.DS_Store | ||
.idea | ||
npm-debug.log* | ||
|
||
/node_modules | ||
/test/coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"strict": true, | ||
"node": true, | ||
"curly": true, | ||
"eqeqeq": true, | ||
"immed": true, | ||
"newcap": true, | ||
"noarg": true, | ||
"sub": true, | ||
"undef": true, | ||
"boss": true, | ||
"eqnull": true, | ||
"laxbreak": true, | ||
"latedef": "nofunc" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.idea | ||
.DS_Store | ||
.editorconfig | ||
.gitignore | ||
.npmignore | ||
.jshintrc | ||
.travis.yml | ||
|
||
npm-debug.log | ||
|
||
/node_modules | ||
/test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
sudo: false | ||
language: node_js | ||
node_js: | ||
- 0.12 | ||
|
||
cache: | ||
directories: | ||
- node_modules | ||
|
||
install: npm install | ||
|
||
script: | ||
- npm test | ||
|
||
after_script: | ||
- npm run test:rpt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,57 @@ | ||
# pick-prop | ||
Randomly sampling a property from an object. | ||
|
||
> Randomly sampling a property from an object. | ||
[![MIT License](https://img.shields.io/badge/license-MIT_License-green.svg?style=flat-square)](https://github.com/bubkoo/pick-prop/blob/master/LICENSE) | ||
|
||
[![build:?](https://img.shields.io/travis/bubkoo/pick-prop/master.svg?style=flat-square)](https://travis-ci.org/bubkoo/pick-prop) | ||
[![coverage:?](https://img.shields.io/coveralls/bubkoo/pick-prop/master.svg?style=flat-square)](https://coveralls.io/github/bubkoo/pick-prop) | ||
|
||
|
||
|
||
## Install | ||
|
||
``` | ||
$ npm install --save pick-prop | ||
``` | ||
|
||
|
||
|
||
## Usage | ||
|
||
> For more use-cases see the [tests](https://github.com/bubkoo/pick-prop/blob/master/test/spec/index.js) | ||
```js | ||
var pickProp = require('pick-prop'); | ||
|
||
// pickProp(object); | ||
|
||
pickProp({ a: 1, b: 2, c: 3 }); // => 3 | ||
pickProp([2]); // => 2 | ||
|
||
pickProp(); // => undefined | ||
pickProp(null); // => undefined | ||
pickProp([]); // => undefined | ||
pickProp({}); // => undefined | ||
pickProp(1); // => undefined | ||
pickProp('a'); // => undefined | ||
``` | ||
|
||
## Related | ||
|
||
- [pick-props](https://github.com/bubkoo/pick-props) - Randomly sampling some properties from an object. | ||
- [pick-key](https://github.com/bubkoo/pick-key) - Randomly sampling a key from an object. | ||
- [pick-keys](https://github.com/bubkoo/pick-keys) - Randomly sampling some keys from an object. | ||
- [object-at](https://github.com/bubkoo/object-at) - Get object's property according to the path. | ||
- [object-has](https://github.com/bubkoo/object-has) - Checks if path is a direct property of object. | ||
- [object-set](https://github.com/bubkoo/object-set) - Sets the value at path of object. | ||
- [object-unset](https://github.com/bubkoo/object-unset) - Removes the property at path of object. | ||
- [to-path](https://github.com/bubkoo/to-path) - Converts string to a property path array. | ||
|
||
|
||
## Contributing | ||
|
||
Pull requests and stars are highly welcome. | ||
|
||
For bugs and feature requests, please [create an issue](https://github.com/bubkoo/pick-prop/issues/new). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use strict'; | ||
|
||
var isObject = require('is-object'); | ||
var pickKey = require('pick-key'); | ||
|
||
|
||
module.exports = function (object) { | ||
|
||
if (!object || !isObject(object)) { | ||
return undefined; | ||
} | ||
|
||
var key = pickKey(object); | ||
|
||
return key ? object[key] : undefined; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"name": "pick-prop", | ||
"version": "1.0.0", | ||
"description": "Randomly sampling a property from an object.", | ||
"main": "index.js", | ||
"scripts": { | ||
"lint": "jshint index.js", | ||
"pretest": "npm run lint", | ||
"test": "mocha -R spec", | ||
"test:cov": "rm -rf ./test/coverage && istanbul cover _mocha --dir ./test/coverage -- -R spec", | ||
"test:rpt": "npm run test:cov && coveralls < ./test/coverage/lcov.info", | ||
"prepublish": "npm test" | ||
}, | ||
"keywords": [ | ||
"pick", | ||
"sampling", | ||
"array", | ||
"arr", | ||
"key", | ||
"keys", | ||
"value", | ||
"values", | ||
"property", | ||
"properties", | ||
"array-like", | ||
"shuffle", | ||
"random", | ||
"randomly", | ||
"randomize", | ||
"rand" | ||
], | ||
"license": "MIT", | ||
"author": { | ||
"name": "bubkoo", | ||
"email": "bubkoo.wy@gmail.com" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/bubkoo/pick-prop.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/bubkoo/pick-prop/issues" | ||
}, | ||
"homepage": "https://github.com/bubkoo/pick-prop#readme", | ||
"devDependencies": { | ||
"jshint": "^2.9.1", | ||
"chai": "^3.5.0", | ||
"coveralls": "^2.11.9", | ||
"istanbul": "^0.4.2", | ||
"mocha": "^2.4.5" | ||
}, | ||
"dependencies": { | ||
"is-object": "^1.0.1", | ||
"pick-key": "^1.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict'; | ||
|
||
require('./spec/'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
|
||
var expect = require('chai').expect; | ||
|
||
|
||
describe('pick-key: ', function () { | ||
|
||
var pickProp = require('../../'); | ||
|
||
it('common', function () { | ||
|
||
expect(pickProp()).to.be.undefined; | ||
expect(pickProp(null)).to.be.undefined; | ||
expect(pickProp(1)).to.be.undefined; | ||
expect(pickProp('a')).to.be.undefined; | ||
|
||
expect(pickProp([])).to.be.undefined; | ||
expect(pickProp({})).to.be.undefined; | ||
|
||
expect(pickProp([2])).to.be.equal(2); | ||
expect(pickProp({ a: 1, b: 2, c: 3 })).to.be.oneOf([1, 2, 3]); | ||
}); | ||
}); |