Skip to content

Commit

Permalink
✨ Add create function (#288)
Browse files Browse the repository at this point in the history
* ✨ Add init function in object namespace

* 🚚 Rename init into create

* ✏️ Fix typo
  • Loading branch information
frinyvonnick authored and nlepage committed Jan 22, 2019
1 parent b3a27bd commit e9bcfda
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/immutadot/src/object/create.js
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 }

12 changes: 12 additions & 0 deletions packages/immutadot/src/object/create.spec.js
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
})
})
})
1 change: 1 addition & 0 deletions packages/immutadot/src/object/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
*/

export { assign } from './assign'
export { create } from './create'

0 comments on commit e9bcfda

Please sign in to comment.