Comparing version 1.0.1 to 1.1.0
@@ -6,4 +6,4 @@ "use strict"; | ||
}); | ||
exports.default = objectReducer; | ||
function objectReducer(obj, reducer, initialValue) { | ||
exports.default = objectReduce; | ||
function objectReduce(obj, reducer, initialValue) { | ||
for (var key in obj) { | ||
@@ -10,0 +10,0 @@ initialValue = reducer(initialValue, obj[key], key, obj); |
@@ -6,4 +6,4 @@ "use strict"; | ||
}); | ||
exports.default = objectReducer; | ||
function objectReducer(obj, reducer, initialValue) { | ||
exports.default = objectReduce; | ||
function objectReduce(obj, reducer, initialValue) { | ||
for (var key in obj) { | ||
@@ -10,0 +10,0 @@ initialValue = reducer(initialValue, obj[key], key, obj); |
{ | ||
"name": "fast-loops", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Small, performant & immutable iteration utilities for Arrays and Objects", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -5,3 +5,3 @@ # Fast Loops | ||
<img alt="TravisCI" src="https://travis-ci.org/rofrischmann/fast-loops.svg?branch=master"> <a href="https://codeclimate.com/github/rofrischmann/fast-loops/coverage"><img alt="Test Coverage" src="https://codeclimate.com/github/rofrischmann/fast-loops/badges/coverage.svg"></a> <img alt="gzipped size" src="https://img.shields.io/badge/gzipped+minified-0.46kb-brightgreen.svg"> <img alt="npm downloads" src="https://img.shields.io/npm/dm/fast-loops.svg"> <img alt="npm version" src="https://badge.fury.io/js/fast-loops.svg"> | ||
<img alt="TravisCI" src="https://travis-ci.org/rofrischmann/fast-loops.svg?branch=master"> <a href="https://codeclimate.com/github/rofrischmann/fast-loops/coverage"><img alt="Test Coverage" src="https://codeclimate.com/github/rofrischmann/fast-loops/badges/coverage.svg"></a> <img alt="gzipped size" src="https://img.shields.io/badge/gzipped+minified-0.47kb-brightgreen.svg"> <img alt="npm downloads" src="https://img.shields.io/npm/dm/fast-loops.svg"> <img alt="npm version" src="https://badge.fury.io/js/fast-loops.svg"> | ||
@@ -28,5 +28,8 @@ ## Installation | ||
* [objectFind](#objectfindobj-query) | ||
* [objectMap](#objectmapobj-mapper) | ||
* [objectReduce](#objectreduceobj-reducer-accumulator) | ||
* [objectRenameKeys](#objectrenamekeysobj-keys) | ||
* [objectMergeDeep](#objectmergedeepbase-objs) | ||
### `arrayEach(arr, iterator)` <img alt="gzipped size" src="https://img.shields.io/badge/gzipped-0.38kb-brightgreen.svg"> | ||
### `arrayEach(arr, iterator)` | ||
@@ -49,3 +52,3 @@ Iterates over each value in the array.<br> | ||
### `arrayFilter(arr, filter)` <img alt="gzipped size" src="https://img.shields.io/badge/gzipped-0.4kb-brightgreen.svg"> | ||
### `arrayFilter(arr, filter)` | ||
@@ -56,3 +59,3 @@ Filters an array according to the filter criteria.<br> | ||
1. `arr` (*Array*): The array that gets filtered | ||
2. `filter` (*Function*): The filter method with the signature `(value, index, length, arr) => boolean`. | ||
2. `filter` (*Function*): The filter method with the signature `(value, index, length, arr) => boolean` | ||
@@ -68,3 +71,3 @@ ```javascript | ||
### `arrayMap(arr, mapper)` <img alt="gzipped size" src="https://img.shields.io/badge/gzipped-0.39kb-brightgreen.svg"> | ||
### `arrayMap(arr, mapper)` | ||
@@ -75,3 +78,3 @@ Maps an array by running the mapper on each value.<br> | ||
1. `arr` (*Array*): The array that gets mapped | ||
2. `mapper` (*Function*): The mapping method with the signature `(value, index, length, arr) => any`. | ||
2. `mapper` (*Function*): The mapping method with the signature `(value, index, length, arr) => newValue` | ||
@@ -87,3 +90,3 @@ ```javascript | ||
### `arrayReduce(arr, reducer, accumulator)` <img alt="gzipped size" src="https://img.shields.io/badge/gzipped-0.38kb-brightgreen.svg"> | ||
### `arrayReduce(arr, reducer, accumulator)` | ||
@@ -94,3 +97,3 @@ Reduces an array based on the accumulator.<br> | ||
1. `arr` (*Array*): The array that gets reduced | ||
2. `reducer` (*Function*): The reducer method with the signature `(accumulator, value, index, length, arr) => accumulator`. | ||
2. `reducer` (*Function*): The reducer method with the signature `(accumulator, value, index, length, arr) => accumulator` | ||
3. `accumulator` (*any*): The initial accumulator value | ||
@@ -107,3 +110,3 @@ | ||
### `objectEach(obj, iterator)` <img alt="gzipped size" src="https://img.shields.io/badge/gzipped-0.37kb-brightgreen.svg"> | ||
### `objectEach(obj, iterator)` | ||
@@ -124,3 +127,3 @@ Iterates over each key in the object. | ||
### `objectFilter(obj, filter)` <img alt="gzipped size" src="https://img.shields.io/badge/gzipped-0.38kb-brightgreen.svg"> | ||
### `objectFilter(obj, filter)` | ||
@@ -130,3 +133,3 @@ Filters an object's keys according to the filter criteria. | ||
1. `obj` (*Object*): The object that gets filtered | ||
2. `filter` (*Function*): The filter method with the signature `(value, key, obj) => boolean`. | ||
2. `filter` (*Function*): The filter method with the signature `(value, key, obj) => boolean` | ||
@@ -143,3 +146,3 @@ ```javascript | ||
### `objectFind(obj, query)` <img alt="gzipped size" src="https://img.shields.io/badge/gzipped-0.37kb-brightgreen.svg"> | ||
### `objectFind(obj, query)` | ||
@@ -151,3 +154,3 @@ Tries to find a key-value pair that matches the query.<br> | ||
1. `obj` (*Object*): The object that gets queried | ||
2. `query` (*Function*): The query method with the signature `(value, key, obj) => boolean`. | ||
2. `query` (*Function*): The query method with the signature `(value, key, obj) => boolean` | ||
@@ -158,3 +161,3 @@ ```javascript | ||
const query = (value, key) => value > 20 && parseInt(key) % 2 === 0 | ||
const biggerThan20AndEvenKey = objectFilter({ 1: 10, 2: 20, 3: 30, 4: 40 }, query) | ||
const biggerThan20AndEvenKey = objectFind({ 1: 10, 2: 20, 3: 30, 4: 40 }, query) | ||
@@ -165,8 +168,27 @@ console.log(biggerThan20AndEvenKey) | ||
### `objectReduce(obj, reducer, accumulator)` <img alt="gzipped size" src="https://img.shields.io/badge/gzipped-0.37kb-brightgreen.svg"> | ||
### `objectMap(obj, mapper)` | ||
Maps an object by running the `mapper` on each value.<br> | ||
Similar to `Object.keys(obj).map(mapper)`. | ||
1. `obj` (*Object*): The object that gets reduced | ||
2. `mapper` (*Function*): The mapper method with the signature `(value, key, obj) => newValue` | ||
```javascript | ||
import { objectMap } from 'fast-loops' | ||
const mapped = objectMap({ 1: 10, 2: 20, 3: 30 }, (value, key) => value + parseInt(key)) | ||
console.log(mapped) | ||
// => { 1: 11, 2: 22, 3: 33 } | ||
``` | ||
### `objectReduce(obj, reducer, accumulator)` | ||
Reduces an object based on the accumulator. | ||
1. `obj` (*Object*): The object that gets reduced | ||
2. `reducer` (*Function*): The reducer method with the signature `(accumulator, value, key, obj) => accumulator`. | ||
2. `reducer` (*Function*): The reducer method with the signature `(accumulator, value, key, obj) => accumulator` | ||
3. `accumulator` (*any*): The initial accumulator value | ||
@@ -183,2 +205,43 @@ | ||
### `objectRenameKeys(obj, keys)` | ||
Renames object keys. | ||
> Uses [objectReduce](#objectreduceobj-reducer-accumulator) under the hood. | ||
1. `obj` (*Object*): The object that gets reduced | ||
2. `keys` (*Object*): The keys mapping an old key to a new key | ||
```javascript | ||
import { objectRenameKeys } from 'fast-loops' | ||
const renamedObj = objectRenameKeys({ foo: 1, bar: 2 }, { foo: "baz" }) | ||
console.log(sumOfValues) | ||
// => { baz: 1, bar: 2 } | ||
``` | ||
### `objectMergeDeep(base, ...objs)` | ||
Recursively merges objects into a base object. | ||
1. `base` (*Object*): The base object which is changed | ||
2. `objs` (*Array\<Object\>*): A list of objects to be merged into the base object | ||
```javascript | ||
import { objectMergeDeep } from 'fast-loops' | ||
const base = { | ||
foo: 1, | ||
bar: { | ||
foo: 2 | ||
} | ||
} | ||
const mergedObj = objectRenameKeys(base, { baz: 3 }, { bar: { foo: 3 }}) | ||
console.log(mergedObj) | ||
// => { foo: 1, bar: { foo: 3 }, baz: 3 } | ||
``` | ||
## Direct Imports | ||
@@ -185,0 +248,0 @@ While we support the `module` key to support Tree Shaking, you might still want to import single methods without any overhead. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21285
27
326
243