-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
34 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
# 1.1.0 | ||
- feat: cloneDeep | ||
|
||
# 1.0.0 | ||
- feat: getArrayHasIntersect | ||
- feat: getArrayUniq | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict' | ||
|
||
const cloneDeep = (obj) => JSON.parse(JSON.stringify(obj)) | ||
|
||
module.exports = cloneDeep |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict' | ||
|
||
/* eslint-env mocha */ | ||
|
||
const assert = require('assert') | ||
const { cloneDeep } = require('../index') | ||
|
||
describe('cloneDeep', () => { | ||
it('should deep clone objects', () => { | ||
const obj = { foo: 1, bar: { baz: 'a' } } | ||
const clone = cloneDeep(obj) | ||
assert.deepStrictEqual(obj, clone) | ||
assert.notStrictEqual(obj, clone) | ||
}) | ||
|
||
it('should deep clone arrays', () => { | ||
const obj = [1, [2, 3]] | ||
const clone = cloneDeep(obj) | ||
assert.deepStrictEqual(obj, clone) | ||
assert.notStrictEqual(obj, clone) | ||
}) | ||
}) |