File tree Expand file tree Collapse file tree 5 files changed +16
-18
lines changed Expand file tree Collapse file tree 5 files changed +16
-18
lines changed Original file line number Diff line number Diff line change 1
1
/**
2
- Get a random property from an object.
2
+ Get a random value from an object.
3
3
4
4
@example
5
5
```
6
- import randomObjectProperty from 'random-obj-prop ';
6
+ import randomObjectValue from 'random-object-value ';
7
7
8
- randomObjectProperty ({foo: '🐴', bar: '🦄'});
8
+ randomObjectValue ({foo: '🐴', bar: '🦄'});
9
9
//=> '🦄'
10
10
```
11
11
*/
12
- export default function randomObjectProperty < T > ( object : Record < string , T > ) : T ;
12
+ export default function randomObjectValue < T > ( object : Record < string , T > ) : T ;
Original file line number Diff line number Diff line change 1
- export default function randomObjectProperty ( object ) {
2
- const keys = Object . keys ( object ) ;
3
- return object [ keys [ Math . floor ( Math . random ( ) * keys . length ) ] ] ;
1
+ export default function randomObjectValue ( object ) {
4
2
const values = Object . values ( object ) ;
5
3
return values [ Math . floor ( Math . random ( ) * values . length ) ] ;
6
4
}
Original file line number Diff line number Diff line change 1
1
{
2
- "name" : " random-obj-prop " ,
2
+ "name" : " random-object-value " ,
3
3
"version" : " 3.0.0" ,
4
- "description" : " Get a random property from an object" ,
4
+ "description" : " Get a random value from an object" ,
5
5
"license" : " MIT" ,
6
- "repository" : " sindresorhus/random-obj-prop " ,
6
+ "repository" : " sindresorhus/random-object-value " ,
7
7
"funding" : " https://github.com/sponsors/sindresorhus" ,
8
8
"author" : {
9
9
"name" : " Sindre Sorhus" ,
Original file line number Diff line number Diff line change 1
- # random-obj-prop
1
+ # random-object-value
2
2
3
- > Get a random property from an object
3
+ > Get a random value from an object
4
4
5
5
## Install
6
6
7
7
``` sh
8
- npm install random-obj-prop
8
+ npm install random-object-value
9
9
```
10
10
11
11
## Usage
12
12
13
13
``` js
14
- import randomObjectProperty from ' random-obj-prop ' ;
14
+ import randomObjectValue from ' random-object-value ' ;
15
15
16
- randomObjectProperty ({foo: ' 🐴' , bar: ' 🦄' });
16
+ randomObjectValue ({foo: ' 🐴' , bar: ' 🦄' });
17
17
// => '🦄'
18
18
```
19
19
Original file line number Diff line number Diff line change 1
1
import test from 'ava' ;
2
2
import stableFunction from 'stable-function' ;
3
- import randomObjectProperty from './index.js' ;
3
+ import randomObjectValue from './index.js' ;
4
4
5
5
const fixture = {
6
6
foo : 'a' ,
@@ -10,9 +10,9 @@ const fixture = {
10
10
} ;
11
11
12
12
test ( 'main' , t => {
13
- t . false ( stableFunction ( ( ) => randomObjectProperty ( fixture ) ) ) ;
13
+ t . false ( stableFunction ( ( ) => randomObjectValue ( fixture ) ) ) ;
14
14
15
15
for ( let index = 0 ; index < 1000 ; index ++ ) {
16
- t . is ( typeof randomObjectProperty ( fixture ) , 'string' ) ;
16
+ t . is ( typeof randomObjectValue ( fixture ) , 'string' ) ;
17
17
}
18
18
} ) ;
You can’t perform that action at this time.
0 commit comments