Some commonly used utils
npm install @kubric/utils@kubric/utils contains some commonly used util functions
``Javascript`
yarn add @kubric/utils`Javascript`
npm i @kubric/utils
`Javascript`
import {isUndefined, get, mapValues} from "@kubric/utils";
* isNull(val): returns true if val is nullisUndefined(val)
* : returns true if val is undefinedisNullOrUndefined(val)
* : returns true if val is null or undefinedisFunction(val)
* : returns true if val is a functionisString(val)
* : returns true if val is a stringisValidString(val)
* : returns true if val is a non-empty stringisObjectLike(val)
* : returns true if val is not null and is of type objectisObject(val)
* : returns true if val is object-like or is a functionisPlainObject(val)
* : returns true if val is an object created by the Object constructor or one with a [
[Prototype]] of null.isNumber(val)
* : returns true if val is a number, or a value that can be parsed into a number.
* get(object, path, defaultValue): returns value from object at path. If the value at path is found to be undefined
, the defaultValue(is any) is returnedset(object, path, value, options)
* : Sets value in object in the path specified. If options.create is true
, all objects along the path will be createdgetAsNumbers(object, paths, defaults)
* : Accepts any object and an array of paths. For every path in index "pathIndex", it will be resolved against the object and an array of values will be returned as per the following rules
- If the value is a number or a value that can be coerced into a number, the parsed number is returned
- If the value exists but is not a number or a value that can be parsed into a number, the value is returned as such
- If the value exists and "defaults" is a non array value, "defaults" is passed back
- If the value exists and "defaults" is as array value, "defaults[pathIndex]" is passed back
* capitalize(str): Capitalizes str i.e. makes the first letter capitalgetStringHash(str)
* : Returns a number hash for strgetJSONHash(json)
* : Returns a number hash for the json object
* mapValues(object, func): Creates an object with the same keys as object and values generated by running each func
of it's properies through . func is invoked with 2 arguments value and key.filterObject(object, func)
* : To create a new object that contains keys/values filtered from the object that is
passed in. Value of every key in obj is passed to the function. If the function returns true, the resultant object
will have that key and its value, otherwise it is omitted in the returned object.
* debounce(func, wait): Creates a debounced function that delays invoking func until after wait milliseconds throttle(func, wait, options)
have elapsed since the last time the debounced function was invoked.
* : Creates a throttled function that only invokes func at most once per wait options.leading
milliseconds. Provide and options.trailing to indicate whether func should be invoked on the wait
leading and/or trailing edge of the timeout. The func is invoked with the last arguments provided to the func
throttled function. Subsequent calls to the throttled function return the result of the last invocation. If options.leading
and options.trailing options are both true, func is invoked on the trailing edge of the wait
timeout only if the throttled function is invoked more than once during the timeout. If wait is 0 and options.leading
is false, func invocation is deferred until to the next tick, similar to setTimeout with a bindFunctions(funcMap, bindBefore, bindAfter)
timeout of 0.
* : Creates an object with the same keys as funcMap whose values bindBefore
are obtained by binding the corresponding functions with values from the arrays and bindAfter. If arg1
any of the functions from the resultant map is called with say and arg2, the function's arguments [...bindBefore, arg1, arg2, ...bindAfter]
object will be have the value pipeline(funcArray, initialState)
* : Returns a function that invokes the given array of functions sequentially by
passing the output of the function at index n to the function at index n+1. The function returns the value
returned by the last function in the array.
* resolvePromises(promises): If provided with an array of promises, it returns a promise that resolves when all tests/StyleExtractor.test.js` for examples
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.
$3
Style extractor does concatenation of CSS class names from a style object and theme object. Refer to the test cases
at