Simple toolbox 🧰 to keep our utility functions that we scatter across several repos and diverge over time.
A simple, yet comprehensive Validation tool which gives you both validation rules and a Validation
class to play with. You can either use the validation rules directly or create a curried Validation class that can be reused.
import { validation } from "@lab5e/toolbox";
const value = "5";
const validation = validation
.initValidation()
.min(0)
.max(10)
.validate(value);
if (value === true) {
console.log("Yay, our number is between 0 and 10");
} else {
console.log(`Validation failed. Message. ${validation}`);
}
A simple promisified version to copy some text to the user clipboard.
import { copyToClipboard } from "@lab5e/toolbox";
/* Using await */
(async () => {
await copyToClipboard("Text to clipboard");
console.log("Success!");
})();
/* Using promise directly */
copyToClipboard("Text to clipboard").then(() => {
console.log("Success!");
});
While not idiomatic, and utterly wrong in most cases, a promisified sleep can always be handy sometimes.
import { sleep } from "@lab5e/toolbox";
/* Using await */
(async () => {
await sleep(500);
console.log("Ah, good to be awake again");
})();
/* Using promise directly */
sleep(500).then(() => {
console.log("Ah, good to be awake again");
});
We use TSDX for pretty much everything, and most npm scripts just proxy to tsdx
.
Use npm run build
.
To run tests, use npm test
.
Code quality is set up with prettier
, husky
, and lint-staged
.
Jest tests are set up to run with npm test
.
To run in watch mode run npm run test:watch
To see coverage run npm run test:coverage
size-limit
is set up to calculate the real cost of your library with npm run size
and visualize the bundle with npm run analyze
.
We us TSDX which uses Rollup as a bundler and generates multiple rollup configs for various module formats and build settings. See Optimizations for details.
We create UMD, CommonJS, and JavaScript Modules in our build. The appropriate paths are configured in package.json
and dist/index.js
We use TypeScript for everything, giving us types for all the published packages.
main
which installs deps w/ cache, lints, tests, and builds on all pushes against a Node and OS matrixsize
which comments cost comparison of your library on every pull request using size-limit
We use np
. To publish a new version, write npx np
and follow the interactive tutorial.
Generated using TypeDoc