README
@activimetrics/utils-composite
Composite utilities (immutability, fp helpers)
NOTE: All the functions described in API are curried
NOTE: forked from jumpn/utils-composite in order to upgrade dependencies
- Installation
- Types
- API
- License
Installation
npm
Using$ npm install --save @activimetrics/utils-composite
yarn
Using$ yarn add @activimetrics/utils-composite
Types
type Composite = Array<*> | Object;
type Key = number | string;
type Path = Array<Key>;
API
get
Get property value of given key.
Parameters
key
Keycomposite
Composite
Returns any
getIn
Returns value located at the given path or undefined otherwise.
Parameters
path
Pathcomposite
Composite
Returns any
getKeys
Get own enumerable keys.
Parameters
composite
Composite
Returns Array<Key>
hasIn
Returns true if value located at given path is deeply equal to the one specified.
Parameters
path
Pathvalue
anycomposite
Composite
Returns boolean
hasKey
Returns true if key is included in composite's own enumerable ones, or false otherwise.
Parameters
key
Keycomposite
Composite
Returns boolean
haveSameProps
Returns true if both composites have the same props or false otherwise.
Parameters
c1
Compositec2
Composite
Returns boolean
is
Returns true if parameter is a Composite or false otherwise
Parameters
thing
any
isEmpty
Returns true if composite has no own enumerable keys (is empty) or false otherwise
Parameters
composite
Composite
Returns boolean
map
Maps values of the given composite using mapper
Parameters
mapper
function (value: any, key: Key, composite: $Supertype<C>): anycomposite
C
Returns $Supertype<C>
arrayRemove
Returns a new Array with the result of having removed the specified amount (count) of elements at the given index.
Parameters
remove
Returns a new composite with the result of having removed the property with the given key.
Parameters
key
Keycomposite
Composite
Returns Composite
removeIn
Returns a new composite with the result of having removed the property located at the given path.
(This does the same as calling updateIn with updater:
() => updateIn.remove
)
Parameters
path
Pathcomposite
Composite
Returns Composite
set
Returns a new composite with the result of having updated the property with the given key with the specified value.
Parameters
key
Keyvalue
anycomposite
Composite
Returns Composite
setIn
Returns a new composite with the result of having updated the property located at the given path with the specified value.
(This does the same as calling updateIn with updater: () => value
)
Parameters
path
Pathvalue
anycomposite
Composite
Returns Composite
shallowCopy
Returns a new composite with the same own enumerable props of the one given.
Parameters
composite
C
Returns C
shallowEqual
Returns true if both composites are of the same type (Array or Object) and their properties are strictly equal.
Parameters
c1
Compositec2
Composite
Returns boolean
toUndefinedIfEmpty
Returns given composite if it has any own enumerable keys (is not empty) or undefined otherwise
Parameters
composite
Composite
Returns Composite
updateIn
Returns a new composite with the result of having updated the property value at the given path with the result of the call to updater function.
Entry removal is supported by returning updateIn.remove
symbol on updater
function.
Parameters
path
Pathupdater
function (prev: any): anycomposite
Composite
Returns Composite
License
MIT :copyright: 2020 James Marca / (), 2017 Jumpn Limited