@lab5e/toolbox
TypeScript icon, indicating that this package has built-in type declarations

0.1.8 • Public • Published

Toolbox

Simple toolbox 🧰 to keep our utility functions that we scatter across several repos and diverge over time.

License Documentation npm bundle size (minified + gzip) toolbox CI

Available tools

Validation

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}`);
}

CopyToClipboard

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!");
});

Sleep

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");
});

Development

We use TSDX for pretty much everything, and most npm scripts just proxy to tsdx.

Run single build

Use npm run build.

Run tests

To run tests, use npm test.

Configuration

Code quality is set up with prettier, husky, and lint-staged.

Jest

Jest tests are set up to run with npm test.

Watch mode

To run in watch mode run npm run test:watch

Coverage

To see coverage run npm run test:coverage

Bundle Analysis

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.

Rollup

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

TypeScript

We use TypeScript for everything, giving us types for all the published packages.

Continuous Integration

GitHub Actions

  • main which installs deps w/ cache, lints, tests, and builds on all pushes against a Node and OS matrix
  • size which comments cost comparison of your library on every pull request using size-limit

Publishing to NPM

We use np. To publish a new version, write npx np and follow the interactive tutorial.

Readme

Keywords

Package Sidebar

Install

npm i @lab5e/toolbox

Weekly Downloads

2

Version

0.1.8

License

Apache-2.0

Unpacked Size

532 kB

Total Files

37

Last publish

Collaborators

  • pkkummermo
  • stalehd