https://github.com/lab5e/toolbox
https://github.com/lab5e/toolbox
Last synced: 15 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/lab5e/toolbox
- Owner: lab5e
- Created: 2021-10-19T11:29:47.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-10-29T09:18:52.000Z (over 4 years ago)
- Last Synced: 2025-09-27T23:18:31.969Z (9 months ago)
- Language: TypeScript
- Size: 1.94 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Toolbox
Simple toolbox 🧰 to keep our utility functions that we scatter across several repos and diverge over time.
[](https://opensource.org/licenses/Apache-2.0)
[](https://lab5e.github.io/toolbox)
[](#tiny)
[](https://www.npmjs.com/package/@lab5e/toolbox)
[](https://github.com/lab5e/toolbox/actions/workflows/main.yml)
## 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.
```ts
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.
```ts
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.
```ts
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](https://github.com/formium/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`](https://github.com/ai/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](https://rollupjs.org) as a bundler and generates multiple rollup configs for various module formats and build settings. See [Optimizations](#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`](https://github.com/ai/size-limit)
## Publishing to NPM
We use `np`. To publish a new version, write `npx np` and follow the interactive tutorial.