core

Methods

(static) convert(updater) → {function}

Source:
Since:
  • 1.0.0
See:
  • update for more information.
Wraps an updater function, returning a new function taking object, path and …args as parameters.
The updater function is invoked with value and …args.
Be carefull, the updater function must not mutate its value argument.
Example

Wrapping an updater

const inc = (v, i = 1) => v + i // this function increments a number with an optional value which defaults to 1
const incProp = convert(inc)
const object = { nested: { prop: 4 } }
incProp(object, 'nested.prop') // => { nested: { prop: 5 } }
incProp(object, 'nested.prop', 2) // => { nested: { prop: 6 } }
Parameters:
Name Type Description
updater function The updater function.
Returns:
Returns the wrapped function.
Type
function

(static) flow(…args) → {core.flowFunction}

Source:
Since:
  • 1.0.0
Creates a function that will successively call all functions contained in args.
Each function is called with the result of the previous one.
Non functions args are tolerated and will be ignored.
Parameters:
Name Type Attributes Description
args function | Array.<function()>
repeatable
The functions to apply
Returns:
A function successively calling function args
Type
core.flowFunction

(static) get(obj, path, defaultValue) → {*}

Source:
Since:
  • 1.0.0
Gets the value at path of obj.
Examples
get({ nested: { prop: 'val' } }, 'nested.prop') // => 'val'
get({ nested: { prop: 'val' } }, 'nested.unknown', 'default') // => 'default'
Parameters:
Name Type Description
obj * The object.
path string | Array The path of the property to get.
defaultValue * The default value.
Returns:
Returns the value or defaultValue.
Type
*

(static) set(obj, path, value) → {*}

Source:
Since:
  • 1.0.0
Sets the value at path of obj.
Example
set({ nested: { prop: 'old' } }, 'nested.prop', 'new') // => { nested: { prop: 'new' } }
Parameters:
Name Type Description
obj * The object to modify.
path string | Array The path of the property to set.
value * The value to set.
Returns:
Returns the updated object.
Type
*

(static) unset(obj, path) → {Object}

Source:
Since:
  • 1.0.0
Removes the property at path of object.
Example
unset({ nested: { prop: 'value' } }, 'nested.prop') // => { nested: {} }
Parameters:
Name Type Description
obj Object The object to modify.
path Array | string The path of the property to unset.
Returns:
Returns the updated object.
Type
Object

(static) update(obj, path, updater, …args) → {Object}

Source:
Since:
  • 1.0.0
Updates the value at path of object using the updater function.
The updater is invoked with value and …args.
Be carefull, the updater function must not mutate its value argument.
Example

Updating a prop

const inc = (v, i = 1) => v + i // this function increments a number with an optional value which defaults to 1
const object = { nested: { prop: 4 } }
update(object, 'nested.prop', inc) // => { nested: { prop: 5 } }
update(object, 'nested.prop', inc, 2) // => { nested: { prop: 6 } }
Parameters:
Name Type Attributes Description
obj Object The object to modify.
path Array | string The path of the property to set.
updater function The function to produce the updated value.
args *
repeatable
The remaining args.
Returns:
Returns the updated object.
Type
Object

Type Definitions

flowFunction(arg) → {*}

Source:
Since:
  • 1.0.0
A function successively calling a list of functions.
Parameters:
Name Type Description
arg * The starting value
Returns:
The resulting value
Type
*