0-dependency snippets and utilities for web and node projects
npm install axl-js-toolbox0 dependency snippets and utilities for web and node projects
jsdoc provided
| fn / prop | values | default | desc |
|---------------------------|-----------------|------------------------------------|-----------------------------------------------------------------|
| graceLog.lvl | 0|1|2 | process.env.GRACE_LOG_LEVEL || window.GRACE_LOG_LEVEL || 0 | 0 - log, 1 - debug, 2 - verbose |
| graceLog.fn | {function} | console.log | log sink function |
| graceLog.prefix | {string} | GraceLog | actually a key to include in all logs |
| graceLog.log(...args) | {*} | ` | args will be passed to graceLog.fn always |
| graceLog.debug(...args) | {*} | | log args will be passed to graceLog.fn only if lvl > 0 |
| graceLog.verbose(...args) | {*} | | log args will be passed to graceLog.fn only if lvl > 1 |
| graceLog(...args) | {*} | | short-hand for graceLog.log(...args) |` | logs message and exits process (on node) or throws Error on web |
| graceLog.error(e) | {string|Error} |
Tiny async utility methods
| fn / prop | desc | returns / resolves |
|-----------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------|
| promiseSequence | Resolves promises/function set in sync (one by one). Passes result of each to another. Alternatively, if function/promise did not return result - it can pass previous result to one after. Behaviorally similar to async array.reduce. | Promise<*> - Whatever last promise returns |
| waitUntil | Keeps checking condition in configurable interval. Resolves as soon as condition returns positive value | Promise<*> |
| debounce | Prevents your function from being called too often, by wrapping it with timeout buffer. Every call to it more frequent than timeout bounces actual execution for another timeout After timeout function is executed normally, with "latest" arguments that were passed to it. | function |