-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ✨ Add init function in object namespace * 🚚 Rename init into create * ✏️ Fix typo
- Loading branch information
1 parent
b3a27bd
commit e9bcfda
Showing
3 changed files
with
29 additions
and
0 deletions.
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { set } from 'core/set' | ||
|
||
/** | ||
* create a new Object with the value set at <code>path</code> | ||
* @function | ||
* @memberof object | ||
* @param {Array|string} path The path of the property to set. | ||
* @param {*} value The value to set | ||
* @return {Object} Returns the new object createialized. | ||
* @example create({}, 'nested.prop', 1) // => { nested: { prop: 1 } } | ||
* @since 2.0.0 | ||
*/ | ||
const create = (path, value) => set({}, path, value) | ||
|
||
export { create } | ||
|
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,12 @@ | ||
/* eslint-env jest */ | ||
import { create } from 'object' | ||
import { immutaTest } from 'test.utils' | ||
describe('object.create', () => { | ||
it('should create objects', () => { | ||
immutaTest(undefined, ['nested.prop'], (input, path) => { | ||
const output = create(path, 1) | ||
expect(output).toEqual({ nested: { prop: 1 } }) | ||
return output | ||
}) | ||
}) | ||
}) |
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 |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
*/ | ||
|
||
export { assign } from './assign' | ||
export { create } from './create' |