Despite lodash and many functionalities out there, there are still some utilities didn't achive what I intend to have.
npm install utilzed
# set specific version
npm install [email protected]
This library has both flow and ts declarations
import utilzed from 'utilzed';
// for promise module and functions
const { waitForTrue, sleep } = utilzed.promise;
// for timeconvert module
const { TimeConverter, Format } = utilzed.timeconvert;
// If index module getting too big for the size you can import specific module
import timeconvert from 'utilzed/dist/timeconvert';
// If uses require function you will need to use .default
// For import in typescript or flow, this is not required
const utilzed = require('utilzed').default;
const timeconvert = require('utilzed/dist/timeconvert').default;
This library has jsdoc generated comment.
In case you might be polling for a condition before proceed:
import utilzed from 'utilzed'
// import waitForTrue from 'utilzed/dist/promise/waitForTrue'
const checkCondition = async () => (await somePollCheckFunction());
// this will waitForTrue checkCondition to be true
// checkCondition will be called every 100ms
const success = await utilzed.waitForTrue(100, checkCondition, 1000);
if (success) {
// Meaning checkCondition function returns true before 1000 ms
return;
}
// meaning after 1000ms the checkCondition returns false still
// handle unsuccessful poll for true
await sleep(100)
will await for 100ms before proceed to next function
import utilzed from 'utilzed'
await utilzed.sleep(100);
// will proceed after sleep for 100 ms
This will return true if object is empty, string is empty, number is 0 or array is empty
import utilzed from 'utilzed'
// if lodash isEmpty the following will return true
utilzed.isEmptyOrZero(100); // returns false
utilzed.isEmptyOrZero(0); // returns true
This module checks if the versioning meets the condition
import utilzed from 'utilzed'
const { OPERATORS, isVersionValid } = utilzed.versionCheck
// this will return true
isVersionValid('v2.1.1', OPERATORS.MORE_THAN_EQUAL, 'v1.1.1')
// this will return false
isVersionValid('v1.1.1', OPERATORS.LESS_THAN, 'v1.1.1')
Convert time value without mathematical headache
import utilzed from 'utilzed'
// Can use destructured assignment
const { TimeConverter, Format } = utilzed.timeconvert;
// returns 123000 (target in ms) from 123 (seconds)
TimeConverter.target(Format.MILISECONDS).from(Format.SECONDS, 123);
TODO: host it on github pages
Can refer to create-tslibs
Use VS Code as IDE:
The library template is already setup with vscode settings for auto format.
Ensure the following plugins are enabled:
- ESlint (This is setup with airbnb linting convention)
- Prettier
- Add JSDoc Comment
Optional but Recommended: