Skip to content

Commit

Permalink
add index to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
tjmehta committed Mar 17, 2016
1 parent 4c17e45 commit 50e4b74
Showing 1 changed file with 65 additions and 55 deletions.
120 changes: 65 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ Functional methods like forEach, map, filter, and other ES5 Array methods for Ob

`npm install object-loops`

# Index

[chain](https://github.com/tjmehta/object-loops#usage)
[every](https://github.com/tjmehta/object-loops#every)
[filter](https://github.com/tjmehta/object-loops#filter)
[forEach](https://github.com/tjmehta/object-loops#forEach)
[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

#### You can require each method individually `object-loops/<loop>`
Expand All @@ -17,6 +27,7 @@ var forEach = require('object-loops/for-each')
var mapKeys = require('object-loops/map-keys')
var map = require('object-loops/map')
var reduce = require('object-loops/reduce')
//... and more
// usage
forEach({ x:10, y: 20 }, callback)
filter({ x:10, y: 20 }, callback)
Expand Down Expand Up @@ -49,6 +60,60 @@ obj.map(callback)
obj.reduce(callback)
```

## every

Tests whether every value in the object passes the test implemented by the callback.

* @function module:object-loops/every
* @param {object} [obj] - object to iterate through, not accepted if being used directly on Object.prototype
* @param {everyCallback} callback - function to test each value in the object. return falsey to end the loop, truthy otherwise.
* @param {*} [thisArg] - optional. context to bind to callback
* @returns {boolean} if callback returns false, the loop is ended and false is returned (else false)

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

var obj = {
foo: 10,
bar: 20,
baz: 30,
qux: 40,
}
var allGreaterThan25 = every(obj, function (val, key, obj) {
return val > 25
})
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
}
*/
```

## forEach

Expand Down Expand Up @@ -105,35 +170,6 @@ mappedObj /* Each val multiplied by 2
*/
```

## 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
}
*/
```

## reduce

Applies a function against an accumulator and each value of the object to reduce it to a single value.
Expand All @@ -157,32 +193,6 @@ var sum = reduce(obj, function (prevVal, val, key, obj) {
sum // 60
```

## every

Tests whether every value in the object passes the test implemented by the callback.

* @function module:object-loops/every
* @param {object} [obj] - object to iterate through, not accepted if being used directly on Object.prototype
* @param {everyCallback} callback - function to test each value in the object. return falsey to end the loop, truthy otherwise.
* @param {*} [thisArg] - optional. context to bind to callback
* @returns {boolean} if callback returns false, the loop is ended and false is returned (else false)

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

var obj = {
foo: 10,
bar: 20,
baz: 30,
qux: 40,
}
var allGreaterThan25 = every(obj, function (val, key, obj) {
return val > 25
})
allGreaterThan25 // false
*/
```

## some

Tests whether some value in the object passes the test implemented by the callback.
Expand Down

0 comments on commit 50e4b74

Please sign in to comment.