@kubric/litedash
v1.0.0
Published
A lightweight version of lodash
Downloads
1,428
Readme
litedash
litedash is a light weight version of some most commonly used functions from lodash
Installation
yarn add litedash
Usage
import {isUndefined, get, mapValues} from "litedash";
Functions
Type checks
isNull(val)
: returnstrue
if val isnull
isUndefined(val)
: returnstrue
if val isundefined
isNullOrUndefined(val)
: returnstrue
if val isnull
orundefined
isFunction(val)
: returnstrue
if val is a functionisString(val)
: returnstrue
if val is a stringisValidString(val)
: returnstrue
if val is a non-empty stringisObjectLike(val)
: returnstrue
if val is notnull
and is of typeobject
isObject(val)
: returnstrue
if val is object-like or is a functionisPlainObject(val)
: returnstrue
if val is an object created by theObject
constructor or one with a[[Prototype]]
ofnull
.
JSON
get(object, path, defaultValue)
: returns value fromobject
atpath
. If the value atpath
is found to beundefined
, thedefaultValue
(is any) is returnedset(object, path, value, options)
: Setsvalue
inobject
in thepath
specified. Ifoptions.create
istrue
, all objects along the path will be created
String
capitalize(str)
: Capitalizesstr
i.e. makes the first letter capitalgetStringHash(str)
: Returns a number hash forstr
getJSONHash(json)
: Returns a number hash for thejson
object
Object
mapValues(object, func)
: Creates an object with the same keys asobject
and values generated by running each of it's properies throughfunc
.func
is invoked with 2 argumentsvalue
andkey
.filterObject(object, func)
: Returns a new object with keys and corresponding values fromobject
, for every key/value that returnstrue
whenfunc
is invoked with that value and key as arguments.
Function
debounce(func, wait)
: Creates a debounced function that delays invokingfunc
until afterwait
milliseconds have elapsed since the last time the debounced function was invoked.throttle(func, wait, options)
: Creates a throttled function that only invokesfunc
at most once perwait
milliseconds. Provideoptions.leading
andoptions.trailing
to indicate whetherfunc
should be invoked on the leading and/or trailing edge of thewait
timeout. Thefunc
is invoked with the last arguments provided to the throttled function. Subsequent calls to the throttled function return the result of the lastfunc
invocation. Ifoptions.leading
andoptions.trailing
options are bothtrue
,func
is invoked on the trailing edge of the timeout only if the throttled function is invoked more than once during thewait
timeout. Ifwait
is 0 andoptions.leading
isfalse
,func
invocation is deferred until to the next tick, similar to setTimeout with a timeout of 0.bindFunctions(funcMap, bindBefore, bindAfter)
: Creates an object with the same keys asfuncMap
whose values are obtained by binding the corresponding functions with values from the arraysbindBefore
andbindAfter
. If any of the functions from the resultant map is called with sayarg1
andarg2
, the function'sarguments
object will be have the value[...bindBefore, arg1, arg2, ...bindAfter]
pipeline(funcArray, initialState)
: Returns a function that invokes every function in an array of functions starting with the first one, passing results of the previous invocation to the next function in the array.
Promise
resolvePromises(promises)
: If provided with an array of promises, it returns a promise that resolves when all the promises in the array has resolved. The returned promise will resolve with an array of results with the result in index i corresponding to promise i in the input array. If provided with a map of promises, it returns a promise that resolves when all the promises in the object has resolved. The returned promise will resolve with a map of results with the result in key i corresponding to promise at the key i in the input object. If anything else is provided, the input value is returned as such.