@basekits/kit-function

1.2.0 • Public • Published

@basekits/kit-function

Helper functions kit for basekits.

Install

npm i @basekits/kit-type @basekits/kit-error @basekits/kit-function

Usage

const kit = require('@basekits/core')
const type = require('@basekits/kit-type')
const error = require('@basekits/kit-error')
const fn = require('@basekits/kit-function')
kit.addKit(type)
kit.addKit(error)
kit.addKit(fn)

Available Items

The following methods will be available after adding this kit:

.waitForIt(condition, callback, interval = 300, timeout = 10000)

Runs condition function every interval miliseconds and runs callback if condition function returns true. The callback will also be run if condition doesn't return true after timeout miliseconds.

// wait for library to be available
function checkLib() {
  return 'someLibrary' in window
}

function useLibrary() {
  window.someLibrary.someMethod.call()
}

kit.waitForIt(checkLib, useLibrary)
// interval is 0.3 and timeout is 10 seconds by default

.debounce(func, wait, options)

An article that explains what debounce and throttle does. Implementation of debounce and throttle taken from lodash.


.throttle(func, wait, options)

An article that explains what debounce and throttle does. Implementation of debounce and throttle taken from lodash.


.stringify(value)

Stringifies the input. Input can be one of basekits types: error, object, array, string, number, boolean, null, undefined, nan, date, function, bigint or domelement. It will give you the innerText property in the case of a domElement. Returns an empty string in the case of unrecognized types.


.destringify(value, type = null)

Destringifies the input according to type. Returns value as it is if type left empty. type is one of basekits type.


Package Sidebar

Install

npm i @basekits/kit-function

Weekly Downloads

1

Version

1.2.0

License

MIT

Unpacked Size

20.8 kB

Total Files

11

Last publish

Collaborators

  • npm-support