Skip to content

Commit

Permalink
Merge pull request #6 from DarrenPaulWright/ignoreKeys
Browse files Browse the repository at this point in the history
Ignore keys
  • Loading branch information
DarrenPaulWright committed Feb 23, 2019
2 parents 4b1e953 + 08f5bcc commit e0513de
Show file tree
Hide file tree
Showing 23 changed files with 155 additions and 33 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html)

## [0.2.6] - 2019-2-17
### Changed
- Added ignoreKeys arg to [mapOwn](docs/mapOwn.md) and [clone](docs/clone.md)

## [0.2.5] - 2019-2-17
### Changed
- Added isOptimistic option to [traverse](docs/traverse.md)
Expand Down Expand Up @@ -43,6 +47,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [diffUpdate](docs/diffUpdate.md)
- [intersection](docs/intersection.md)

[0.2.6]: https://github.com/DarrenPaulWright/object-agent/compare/v0.2.5...0.2.6
[0.2.5]: https://github.com/DarrenPaulWright/object-agent/compare/v0.2.4...0.2.5
[0.2.4]: https://github.com/DarrenPaulWright/object-agent/compare/v0.2.3...0.2.4
[0.2.3]: https://github.com/DarrenPaulWright/object-agent/compare/v0.2.2...0.2.3
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# object-agent

A javascript library for working with objects

[![npm][npm]][npm-url]
[![build][build]][build-url]
[![Coverage Status](https://coveralls.io/repos/github/DarrenPaulWright/object-agent/badge.svg?branch=master)](https://coveralls.io/github/DarrenPaulWright/object-agent?branch=master)
[![deps][deps]][deps-url]
[![size][size]][size-url]
[![Known Vulnerabilities](https://snyk.io/test/github/DarrenPaulWright/object-agent/badge.svg?targetFile=package.json)](https://snyk.io/test/github/DarrenPaulWright/object-agent?targetFile=package.json)

A javascript library for working with objects
---

<a name="Installation"></a>

Expand Down
5 changes: 4 additions & 1 deletion docs.hbs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# object-agent

A javascript library for working with objects

[![npm][npm]][npm-url]
[![build][build]][build-url]
[![Coverage Status](https://coveralls.io/repos/github/DarrenPaulWright/object-agent/badge.svg?branch=master)](https://coveralls.io/github/DarrenPaulWright/object-agent?branch=master)
[![deps][deps]][deps-url]
[![size][size]][size-url]
[![Known Vulnerabilities](https://snyk.io/test/github/DarrenPaulWright/object-agent/badge.svg?targetFile=package.json)](https://snyk.io/test/github/DarrenPaulWright/object-agent?targetFile=package.json)

A javascript library for working with objects
---
{{>main}}
Expand Down
40 changes: 40 additions & 0 deletions docs/clone.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# object-agent

A javascript library for working with objects

[![npm][npm]][npm-url]
[![build][build]][build-url]
[![Coverage Status](https://coveralls.io/repos/github/DarrenPaulWright/object-agent/badge.svg?branch=master)](https://coveralls.io/github/DarrenPaulWright/object-agent?branch=master)
[![deps][deps]][deps-url]
[![size][size]][size-url]
[![Known Vulnerabilities](https://snyk.io/test/github/DarrenPaulWright/object-agent/badge.svg?targetFile=package.json)](https://snyk.io/test/github/DarrenPaulWright/object-agent?targetFile=package.json)

---

<a name="clone"></a>

## clone(value, [ignoreKeys]) ⇒ <code>\*</code>
Deep clone a value.

**Kind**: global function

| Param | Type | Description |
| --- | --- | --- |
| value | <code>\*</code> | |
| [ignoreKeys] | <code>Array</code> \| <code>String</code> | Any keys in this array will not be cloned |

**Example**
``` javascriptimport { clone } from 'object-agent';clone({ a: 'b', c: 'd' });// => { a: 'b', c: 'd' }```

## License

[MIT](LICENSE.md)

[npm]: https://img.shields.io/npm/v/object-agent.svg
[npm-url]: https://npmjs.com/package/object-agent
[build]: https://travis-ci.org/DarrenPaulWright/object-agent.svg?branch=master
[build-url]: https://travis-ci.org/DarrenPaulWright/object-agent
[deps]: https://david-dm.org/darrenpaulwright/object-agent.svg
[deps-url]: https://david-dm.org/darrenpaulwright/object-agent
[size]: https://packagephobia.now.sh/badge?p=object-agent
[size-url]: https://packagephobia.now.sh/result?p=object-agent
Expand Down
5 changes: 4 additions & 1 deletion docs/deepEqual.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# object-agent

A javascript library for working with objects

[![npm][npm]][npm-url]
[![build][build]][build-url]
[![Coverage Status](https://coveralls.io/repos/github/DarrenPaulWright/object-agent/badge.svg?branch=master)](https://coveralls.io/github/DarrenPaulWright/object-agent?branch=master)
[![deps][deps]][deps-url]
[![size][size]][size-url]
[![Known Vulnerabilities](https://snyk.io/test/github/DarrenPaulWright/object-agent/badge.svg?targetFile=package.json)](https://snyk.io/test/github/DarrenPaulWright/object-agent?targetFile=package.json)

A javascript library for working with objects
---

<a name="deepEqual"></a>

Expand Down
5 changes: 4 additions & 1 deletion docs/diffUpdate.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# object-agent

A javascript library for working with objects

[![npm][npm]][npm-url]
[![build][build]][build-url]
[![Coverage Status](https://coveralls.io/repos/github/DarrenPaulWright/object-agent/badge.svg?branch=master)](https://coveralls.io/github/DarrenPaulWright/object-agent?branch=master)
[![deps][deps]][deps-url]
[![size][size]][size-url]
[![Known Vulnerabilities](https://snyk.io/test/github/DarrenPaulWright/object-agent/badge.svg?targetFile=package.json)](https://snyk.io/test/github/DarrenPaulWright/object-agent?targetFile=package.json)

A javascript library for working with objects
---

<a name="diffUpdate"></a>

Expand Down
13 changes: 8 additions & 5 deletions docs/forOwn.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# object-agent

A javascript library for working with objects

[![npm][npm]][npm-url]
[![build][build]][build-url]
[![Coverage Status](https://coveralls.io/repos/github/DarrenPaulWright/object-agent/badge.svg?branch=master)](https://coveralls.io/github/DarrenPaulWright/object-agent?branch=master)
[![deps][deps]][deps-url]
[![size][size]][size-url]
[![Known Vulnerabilities](https://snyk.io/test/github/DarrenPaulWright/object-agent/badge.svg?targetFile=package.json)](https://snyk.io/test/github/DarrenPaulWright/object-agent?targetFile=package.json)

A javascript library for working with objects
---

<a name="forOwn"></a>

Expand All @@ -16,10 +19,10 @@ Iterates over own properties of an object. Stops iterating as soon as the callba
**Kind**: global function
**Returns**: <code>Boolean</code> - true if the callback function returns a truthy value for any key; otherwise, false.

| Param | Type |
| --- | --- |
| object | <code>Object</code> |
| callback | <code>function</code> |
| Param | Type | Description |
| --- | --- | --- |
| object | <code>Object</code> | |
| callback | <code>function</code> | Provides two args: value and key |

**Example**
``` javascriptimport { forOwn } from 'object-agent';const thing = { a: 'b', c: 'd'};forOwn(thing, (value, key) => { console.log(value, key);});// => 'b', 'a'// => 'd', 'c'```
Expand Down
5 changes: 4 additions & 1 deletion docs/get.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# object-agent

A javascript library for working with objects

[![npm][npm]][npm-url]
[![build][build]][build-url]
[![Coverage Status](https://coveralls.io/repos/github/DarrenPaulWright/object-agent/badge.svg?branch=master)](https://coveralls.io/github/DarrenPaulWright/object-agent?branch=master)
[![deps][deps]][deps-url]
[![size][size]][size-url]
[![Known Vulnerabilities](https://snyk.io/test/github/DarrenPaulWright/object-agent/badge.svg?targetFile=package.json)](https://snyk.io/test/github/DarrenPaulWright/object-agent?targetFile=package.json)

A javascript library for working with objects
---

<a name="get"></a>

Expand Down
5 changes: 4 additions & 1 deletion docs/intersection.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# object-agent

A javascript library for working with objects

[![npm][npm]][npm-url]
[![build][build]][build-url]
[![Coverage Status](https://coveralls.io/repos/github/DarrenPaulWright/object-agent/badge.svg?branch=master)](https://coveralls.io/github/DarrenPaulWright/object-agent?branch=master)
[![deps][deps]][deps-url]
[![size][size]][size-url]
[![Known Vulnerabilities](https://snyk.io/test/github/DarrenPaulWright/object-agent/badge.svg?targetFile=package.json)](https://snyk.io/test/github/DarrenPaulWright/object-agent?targetFile=package.json)

A javascript library for working with objects
---

<a name="intersection"></a>

Expand Down
5 changes: 4 additions & 1 deletion docs/isEmpty.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# object-agent

A javascript library for working with objects

[![npm][npm]][npm-url]
[![build][build]][build-url]
[![Coverage Status](https://coveralls.io/repos/github/DarrenPaulWright/object-agent/badge.svg?branch=master)](https://coveralls.io/github/DarrenPaulWright/object-agent?branch=master)
[![deps][deps]][deps-url]
[![size][size]][size-url]
[![Known Vulnerabilities](https://snyk.io/test/github/DarrenPaulWright/object-agent/badge.svg?targetFile=package.json)](https://snyk.io/test/github/DarrenPaulWright/object-agent?targetFile=package.json)

A javascript library for working with objects
---

<a name="isEmpty"></a>

Expand Down
5 changes: 4 additions & 1 deletion docs/isEqual.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# object-agent

A javascript library for working with objects

[![npm][npm]][npm-url]
[![build][build]][build-url]
[![Coverage Status](https://coveralls.io/repos/github/DarrenPaulWright/object-agent/badge.svg?branch=master)](https://coveralls.io/github/DarrenPaulWright/object-agent?branch=master)
[![deps][deps]][deps-url]
[![size][size]][size-url]
[![Known Vulnerabilities](https://snyk.io/test/github/DarrenPaulWright/object-agent/badge.svg?targetFile=package.json)](https://snyk.io/test/github/DarrenPaulWright/object-agent?targetFile=package.json)

A javascript library for working with objects
---

<a name="isEqual"></a>

Expand Down
16 changes: 10 additions & 6 deletions docs/mapOwn.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
# object-agent

A javascript library for working with objects

[![npm][npm]][npm-url]
[![build][build]][build-url]
[![Coverage Status](https://coveralls.io/repos/github/DarrenPaulWright/object-agent/badge.svg?branch=master)](https://coveralls.io/github/DarrenPaulWright/object-agent?branch=master)
[![deps][deps]][deps-url]
[![size][size]][size-url]
[![Known Vulnerabilities](https://snyk.io/test/github/DarrenPaulWright/object-agent/badge.svg?targetFile=package.json)](https://snyk.io/test/github/DarrenPaulWright/object-agent?targetFile=package.json)

A javascript library for working with objects
---

<a name="mapOwn"></a>

## mapOwn(object, callback) ⇒ <code>Object</code> \| <code>\*</code>
## mapOwn(object, callback, [ignoreKeys]) ⇒ <code>Object</code> \| <code>\*</code>
Builds a new object by iterating over own properties of an object.

**Kind**: global function
**Returns**: <code>Object</code> \| <code>\*</code> - If null or undefined are passed in then the same is returned, otherwise a new object

| Param | Type |
| --- | --- |
| object | <code>Object</code> |
| callback | <code>function</code> |
| Param | Type | Description |
| --- | --- | --- |
| object | <code>Object</code> | |
| callback | <code>function</code> | Provides two args: value and key |
| [ignoreKeys] | <code>Array</code> \| <code>String</code> | Any keys in this array will be ignored |

**Example**
``` javascriptimport { mapOwn } from 'object-agent';const thing = { a: 'b', c: 'd'};mapOwn(thing, (value, key) => value + ' ' + key);// => { a: 'b a', c: 'd c' }```
Expand Down
5 changes: 4 additions & 1 deletion docs/pull.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# object-agent

A javascript library for working with objects

[![npm][npm]][npm-url]
[![build][build]][build-url]
[![Coverage Status](https://coveralls.io/repos/github/DarrenPaulWright/object-agent/badge.svg?branch=master)](https://coveralls.io/github/DarrenPaulWright/object-agent?branch=master)
[![deps][deps]][deps-url]
[![size][size]][size-url]
[![Known Vulnerabilities](https://snyk.io/test/github/DarrenPaulWright/object-agent/badge.svg?targetFile=package.json)](https://snyk.io/test/github/DarrenPaulWright/object-agent?targetFile=package.json)

A javascript library for working with objects
---

<a name="pull"></a>

Expand Down
5 changes: 4 additions & 1 deletion docs/set.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# object-agent

A javascript library for working with objects

[![npm][npm]][npm-url]
[![build][build]][build-url]
[![Coverage Status](https://coveralls.io/repos/github/DarrenPaulWright/object-agent/badge.svg?branch=master)](https://coveralls.io/github/DarrenPaulWright/object-agent?branch=master)
[![deps][deps]][deps-url]
[![size][size]][size-url]
[![Known Vulnerabilities](https://snyk.io/test/github/DarrenPaulWright/object-agent/badge.svg?targetFile=package.json)](https://snyk.io/test/github/DarrenPaulWright/object-agent?targetFile=package.json)

A javascript library for working with objects
---

<a name="set"></a>

Expand Down
5 changes: 4 additions & 1 deletion docs/traverse.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# object-agent

A javascript library for working with objects

[![npm][npm]][npm-url]
[![build][build]][build-url]
[![Coverage Status](https://coveralls.io/repos/github/DarrenPaulWright/object-agent/badge.svg?branch=master)](https://coveralls.io/github/DarrenPaulWright/object-agent?branch=master)
[![deps][deps]][deps-url]
[![size][size]][size-url]
[![Known Vulnerabilities](https://snyk.io/test/github/DarrenPaulWright/object-agent/badge.svg?targetFile=package.json)](https://snyk.io/test/github/DarrenPaulWright/object-agent?targetFile=package.json)

A javascript library for working with objects
---

<a name="traverse"></a>

Expand Down
5 changes: 4 additions & 1 deletion docs/unset.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# object-agent

A javascript library for working with objects

[![npm][npm]][npm-url]
[![build][build]][build-url]
[![Coverage Status](https://coveralls.io/repos/github/DarrenPaulWright/object-agent/badge.svg?branch=master)](https://coveralls.io/github/DarrenPaulWright/object-agent?branch=master)
[![deps][deps]][deps-url]
[![size][size]][size-url]
[![Known Vulnerabilities](https://snyk.io/test/github/DarrenPaulWright/object-agent/badge.svg?targetFile=package.json)](https://snyk.io/test/github/DarrenPaulWright/object-agent?targetFile=package.json)

A javascript library for working with objects
---

<a name="unset"></a>

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "object-agent",
"version": "0.2.5",
"version": "0.2.6",
"description": "A javascript library for working with objects",
"main": "src/index.js",
"scripts": {
Expand All @@ -22,7 +22,8 @@
"docs-deepEqual": "jsdoc2md src/deepEqual.js > docs/deepEqual.md --template docs.hbs",
"docs-diffUpdate": "jsdoc2md src/diffUpdate.js > docs/diffUpdate.md --template docs.hbs",
"docs-intersection": "jsdoc2md src/intersection.js > docs/intersection.md --template docs.hbs",
"docs": "npm run docs-readme && npm run docs-get && npm run docs-set && npm run docs-unset && npm run docs-forOwn && npm run docs-mapOwn && npm run docs-traverse && npm run docs-isEmpty && npm run docs-isEqual && npm run docs-deepEqual && npm run docs-diffUpdate && npm run docs-pull && npm run docs-intersection"
"docs-clone": "jsdoc2md src/clone.js > docs/clone.md --template docs.hbs",
"docs": "npm run docs-readme && npm run docs-get && npm run docs-set && npm run docs-unset && npm run docs-forOwn && npm run docs-mapOwn && npm run docs-traverse && npm run docs-isEmpty && npm run docs-isEqual && npm run docs-deepEqual && npm run docs-diffUpdate && npm run docs-pull && npm run docs-intersection && npm run docs-clone"
},
"repository": {
"type": "git",
Expand Down
7 changes: 4 additions & 3 deletions src/clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ import set from './set';
* @function clone
*
* @arg {*} value
* @arg {Array|String} [ignoreKeys] - Any keys in this array will not be cloned
*
* @returns {*}
*/
export default function clone(item) {
export default function clone(item, ignoreKeys = []) {
const objectRefs = [];
const circularRefs = [];

Expand All @@ -33,7 +34,7 @@ export default function clone(item) {
}
objectRefs.push([item, path]);

return mapOwn(item, (value, key) => doClone(value, path.concat(key)));
return mapOwn(item, (value, key) => doClone(value, path.concat(key)), ignoreKeys);
}
if (isArray(item)) {
return item.map((value, index) => doClone(value, path.concat(index)));
Expand All @@ -51,5 +52,5 @@ export default function clone(item) {

circularRefs.forEach((ref) => set(result, ref[0], get(result, ref[1])));

return result
return result;
}
2 changes: 1 addition & 1 deletion src/forOwn.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @function forOwn
*
* @arg {Object} object
* @arg {Function} callback
* @arg {Function} callback - Provides two args: value and key
*
* @returns {Boolean} true if the callback function returns a truthy value for any key; otherwise, false.
*/
Expand Down
Loading

0 comments on commit e0513de

Please sign in to comment.