1.0.0 • Published 5 years ago
@kubric/litedash v1.0.0
litedash
litedash is a light weight version of some most commonly used functions from lodash
Installation
yarn add litedashUsage
import {isUndefined, get, mapValues} from "litedash";Functions
Type checks
- isNull(val): returns- trueif val is- null
- isUndefined(val): returns- trueif val is- undefined
- isNullOrUndefined(val): returns- trueif val is- nullor- undefined
- isFunction(val): returns- trueif val is a function
- isString(val): returns- trueif val is a string
- isValidString(val): returns- trueif val is a non-empty string
- isObjectLike(val): returns- trueif val is not- nulland is of type- object
- isObject(val): returns- trueif val is object-like or is a function
- isPlainObject(val): returns- trueif val is an object created by the- Objectconstructor or one with a- [[Prototype]]of- null.
JSON
- get(object, path, defaultValue): returns value from- objectat- path. If the value at- pathis found to be- undefined, the- defaultValue(is any) is returned
- set(object, path, value, options): Sets- valuein- objectin the- pathspecified. If- options.createis- true, all objects along the path will be created
String
- capitalize(str): Capitalizes- stri.e. makes the first letter capital
- getStringHash(str): Returns a number hash for- str
- getJSONHash(json): Returns a number hash for the- jsonobject
Object
- mapValues(object, func): Creates an object with the same keys as- objectand values generated by running each of it's properies through- func.- funcis invoked with 2 arguments- valueand- key.
- filterObject(object, func): Returns a new object with keys and corresponding values from- object, for every key/value that returns- truewhen- funcis invoked with that value and key as arguments.
Function
- debounce(func, wait): Creates a debounced function that delays invoking- funcuntil after- waitmilliseconds have elapsed since the last time the debounced function was invoked.
- throttle(func, wait, options): Creates a throttled function that only invokes- funcat most once per- waitmilliseconds. Provide- options.leadingand- options.trailingto indicate whether- funcshould be invoked on the leading and/or trailing edge of the- waittimeout. The- funcis invoked with the last arguments provided to the throttled function. Subsequent calls to the throttled function return the result of the last- funcinvocation. If- options.leadingand- options.trailingoptions are both- true,- funcis invoked on the trailing edge of the timeout only if the throttled function is invoked more than once during the- waittimeout. If- waitis 0 and- options.leadingis- false,- funcinvocation 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 as- funcMapwhose values are obtained by binding the corresponding functions with values from the arrays- bindBeforeand- bindAfter. If any of the functions from the resultant map is called with say- arg1and- arg2, the function's- argumentsobject 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.