Skip to content

Commit

Permalink
readme: formatting updates, added missing docs for map-keys
Browse files Browse the repository at this point in the history
  • Loading branch information
tjmehta committed Mar 18, 2016
1 parent dd995fa commit a55b5e0
Showing 1 changed file with 69 additions and 30 deletions.
99 changes: 69 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,23 @@ Functional methods like forEach, map, filter, and other Array methods for Object
# Index

[chain](https://github.com/tjmehta/object-loops#usage)

[every](https://github.com/tjmehta/object-loops#every)
[find](https://github.com/tjmehta/object-loops#find)
[findKey](https://github.com/tjmehta/object-loops#findKey)

[filter](https://github.com/tjmehta/object-loops#filter)

[findKey](https://github.com/tjmehta/object-loops#findKey)

[find](https://github.com/tjmehta/object-loops#find)

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

[mapKeys](https://github.com/tjmehta/object-loops#mapKeys)

[map](https://github.com/tjmehta/object-loops#map)

[reduce](https://github.com/tjmehta/object-loops#reduce)

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

# Usage
Expand Down Expand Up @@ -88,6 +98,35 @@ allGreaterThan25 // false
*/
```

## filter

Creates a new object with all entries that pass the test implemented by the provided function.

* @param {object} [obj] - object to filter values, not accepted if being used directly on Object.prototype
* @param {function} callback - function to test each value in the object. return true to keep that entry, false otherwise.
* @param {*} [thisArg] - optional. context to bind to callback
* @returns {object} newly created object with filtered values

```js
var filter = require('object-loops/filter')

var obj = {
foo: 10,
bar: 20,
baz: 30,
qux: 40,
}
var filteredObj = filter(obj, function (val, key, obj) {
return val > 25
})
filteredObj /* Only has entries with vals greater than 25
{
baz: 30,
qux: 40
}
*/
```

## find

Find the value of the the object that passes the test implemented by the callback.
Expand Down Expand Up @@ -146,59 +185,59 @@ notfound // undefined
*/
```

## filter
## forEach

Creates a new object with all entries that pass the test implemented by the provided function.
Executes a provided function once per each object value.

* @param {object} [obj] - object to filter values, not accepted if being used directly on Object.prototype
* @param {function} callback - function to test each value in the object. return true to keep that entry, false otherwise.
* @param {object} [obj] - object to forEach, not accepted if being used directly on Object.prototype
* @param {function} callback - function that will be invoked once for each key-value pair
* @param {*} [thisArg] - optional. context to bind to callback
* @returns {object} newly created object with filtered values

```js
var filter = require('object-loops/filter')
var forEach = require('object-loops/for-each')

var obj = {
foo: 10,
bar: 20,
baz: 30,
qux: 40,
baz: 30
}
var filteredObj = filter(obj, function (val, key, obj) {
return val > 25
var keyConcat = ''
var valSum = 0
forEach(obj, function (val, key, obj) {
keyConcat += key
valSum += val
})
filteredObj /* Only has entries with vals greater than 25
{
baz: 30,
qux: 40
}
*/
keyConcat // = 'foobarbaz'
valSum // = 60
```

## forEach
## mapKeys

Executes a provided function once per each object value.
Creates a new object with the results of calling a provided function on every key in the object.

* @param {object} [obj] - object to forEach, not accepted if being used directly on Object.prototype
* @param {function} callback - function that will be invoked once for each key-value pair
* @param {object} [obj] - object to map keys, not accepted if being used directly on Object.prototype
* @param {mapKeysCallback} callback - function that produces the new key for the new mapped object
* @param {*} [thisArg] - optional. context to bind to callback
* @returns {object} newly created object with mapped keys

```js
var forEach = require('object-loops/for-each')
var mapKeys = require('object-loops/map-keys')

var obj = {
foo: 10,
bar: 20,
baz: 30
}
var keyConcat = ''
var valSum = 0
forEach(obj, function (val, key, obj) {
keyConcat += key
valSum += val
var mappedObj = mapKeys(obj, function (key, val, obj) {
return key + 'New'
})
keyConcat // = 'foobarbaz'
valSum // = 60
mappedObj /* Each key is concated w/ 'New'
{
fooNew: 10,
barNew: 20,
bazNew: 30
}
*/
```

## map
Expand Down

0 comments on commit a55b5e0

Please sign in to comment.