Skip to content

Commit 77c225d

Browse files
committed
docs for keys, keysIn, values, valuesIn
1 parent 41c17b4 commit 77c225d

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ Functional methods like forEach, map, filter, and other Array methods for Object
2323

2424
[forEach](https://github.com/tjmehta/object-loops#forEach)
2525

26+
[keys](https://github.com/tjmehta/object-loops#keys)
27+
28+
[keysIn](https://github.com/tjmehta/object-loops#keysIn)
29+
2630
[mapKeys](https://github.com/tjmehta/object-loops#mapKeys)
2731

2832
[map](https://github.com/tjmehta/object-loops#map)
@@ -31,6 +35,10 @@ Functional methods like forEach, map, filter, and other Array methods for Object
3135

3236
[some](https://github.com/tjmehta/object-loops#some)
3337

38+
[values](https://github.com/tjmehta/object-loops#values)
39+
40+
[valuesIn](https://github.com/tjmehta/object-loops#valuesIn)
41+
3442
# Usage
3543

3644
#### You can require each method individually `object-loops/<loop>`
@@ -238,6 +246,44 @@ keyConcat // = 'foobarbaz'
238246
valSum // = 60
239247
```
240248

249+
## keys
250+
251+
Equivalent to `Object.keys`. Implemented specifically for chain.
252+
253+
```js
254+
var chain = require('object-loops/chain')
255+
256+
var obj = {
257+
foo: 10,
258+
bar: 20,
259+
baz: 30
260+
}
261+
chain(obj)
262+
.keys()
263+
.toJSON()
264+
// ['foo', 'bar', 'baz']
265+
```
266+
267+
## keysIn
268+
269+
Like to `keys`, but includes enumerable keys from the prototype chain.
270+
271+
```js
272+
var keysIn = require('object-loops/keys-in')
273+
274+
function Person (name) {
275+
this.name = name
276+
}
277+
Person.prototype.getName = function () {
278+
return this.name
279+
}
280+
281+
var person = new Person('foo')
282+
keysIn(obj)
283+
// ['name', 'getName']
284+
// for comparison, `keys` would return ['name']
285+
```
286+
241287
## mapKeys
242288

243289
Creates a new object with the results of calling a provided function on every key in the object.
@@ -345,6 +391,45 @@ anyGreaterThan25 // true
345391
*/
346392
```
347393

394+
## values
395+
396+
Like to `keys`, but returns direct enumerable values.
397+
398+
```js
399+
var values = require('object-loops/values')
400+
401+
function Person (name) {
402+
this.name = name
403+
}
404+
Person.prototype.getName = function () {
405+
return this.name
406+
}
407+
408+
var person = new Person('foo')
409+
values(obj)
410+
// ['foo']
411+
// for comparison, `valuesIn` would return ['foo', Person.prototype.getName]
412+
```
413+
414+
## valuesIn
415+
416+
Like to `keys`, but returns direct enumerable values including prototype chain.
417+
418+
```js
419+
var valuesIn = require('object-loops/values-in')
420+
421+
function Person (name) {
422+
this.name = name
423+
}
424+
Person.prototype.getName = function () {
425+
return this.name
426+
}
427+
428+
var person = new Person('foo')
429+
valuesIn(obj)
430+
// ['foo', Person.prototype.getName]
431+
```
432+
348433
## License
349434

350435
MIT

0 commit comments

Comments
 (0)