https://github.com/tbhvishal/js-toolbox
Lightweight JavaScript utilities toolkit: helpers, snippets, and productivity tools. ESM, Node.js, TypeScript-friendly, zero dependencies. Arrays, strings, dates, async, functional programming - perfect for beginners and pros
https://github.com/tbhvishal/js-toolbox
beginner-friendly best-practices code-snippets-javascript copy-paste developer-tools esm functional-programming hacktoberfest helpers javascript library lightweight nodejs npm-package productivity-tools snippets utilities utils vanilla-js zero-dependencies
Last synced: about 2 months ago
JSON representation
Lightweight JavaScript utilities toolkit: helpers, snippets, and productivity tools. ESM, Node.js, TypeScript-friendly, zero dependencies. Arrays, strings, dates, async, functional programming - perfect for beginners and pros
- Host: GitHub
- URL: https://github.com/tbhvishal/js-toolbox
- Owner: tbhvishal
- Created: 2025-10-16T07:05:42.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-10-16T09:43:22.000Z (8 months ago)
- Last Synced: 2025-10-17T11:30:16.578Z (8 months ago)
- Topics: beginner-friendly, best-practices, code-snippets-javascript, copy-paste, developer-tools, esm, functional-programming, hacktoberfest, helpers, javascript, library, lightweight, nodejs, npm-package, productivity-tools, snippets, utilities, utils, vanilla-js, zero-dependencies
- Language: JavaScript
- Homepage:
- Size: 426 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# js-toolbox โก






> A small, zero-dependency JavaScript toolbox for everyday tasks - simple, readable, and copy-paste friendly. โจ
## โจ Features
- ๐ **Zero dependencies** - lightweight and fast
- ๐ฆ **40+ utilities** - covering strings, numbers, arrays, dates, async, and more
- ๐ **Works everywhere** - Node 18+ (ESM) and browser-friendly
- ๐ **JSDoc comments** - full autocomplete support
- ๐ง **Built-in CLI** - use utilities from the command line
- โ
**Well-tested** - comprehensive test suite included
## ๐ค Why Another Utility Library?
Unlike bloated alternatives:
- **Lodash** = 72KB minified, 500+ functions you'll never use
- **js-toolbox** = <5KB total, only what you need
Perfect for:
- โ
Quick scripts and prototypes
- โ
Learning JavaScript patterns
- โ
Projects that need to stay lean
- โ
Copy-pasting one function without installing a library
## ๐ฆ Installation
```bash
# Clone the repo
git clone https://github.com/tbhvishal/js-toolbox.git
# Or copy individual functions directly into your project
```
## ๐ Quick Start
- **Use in Node.js:**
```js
import { strings, numbers } from './src/index.js';
console.log(strings.slugify('Hello World!')); // โ "hello-world"
console.log(numbers.randInt(1, 6)); // โ random number 1-6
console.log(numbers.toCurrency(1234.56)); // โ "$1,234.56"
```
- **Use via CLI:**
```bash
node ./bin/js-toolbox.js strings slugify "Hello World!"
# Output: hello-world
```
- **Copy & Paste:**
Just grab the function you need from `src/` and paste it into your project. No installation required!
## ๐ Modules
### ๐ข Numbers
`clamp`, `between`, `randInt`, `randFloat`, `sum`, `avg`, `median`, `toCurrency`, `round`, `percentage`, `isEven`, `isOdd`
Show examples
```js
import * as num from './src/numbers.js';
num.clamp(150, 0, 100); // 100
num.randInt(1, 6); // Random 1-6 (dice roll)
num.toCurrency(1234.56); // "$1,234.56"
num.percentage(25, 200); // 12.5
num.median([1, 2, 3, 4, 5]); // 3
```
### ๐ Strings
`capitalize`, `titleCase`, `kebabCase`, `slugify`, `truncate`, `pad`, `stripAnsi`, `reverse`, `camelCase`, `snakeCase`, `repeat`, `escapeHtml`
Show examples
```js
import * as str from './src/strings.js';
str.slugify('Hello World!'); // "hello-world"
str.titleCase('hello world'); // "Hello World"
str.truncate('Long text here', 10); // "Long te..."
str.camelCase('hello-world'); // "helloWorld"
str.escapeHtml('alert("xss")'); // Safe HTML
```
### ๐
Dates
`formatDate`, `fromNow`, `addDays`, `isSameDay`, `parseISO`, `startOfDay`, `endOfDay`, `daysBetween`
Show examples
```js
import * as dates from './src/dates.js';
dates.fromNow(new Date('2024-01-01')); // "289d ago"
dates.addDays(new Date(), 7); // Date 7 days from now
dates.formatDate(new Date()); // "10/16/2025"
dates.daysBetween('2024-01-01', '2024-12-31'); // 365
```
### ๐ Arrays
`unique`, `chunk`, `sample`, `shuffle`, `groupBy`, `flatten`, `compact`, `first`, `last`, `take`, `range`, `partition`
Show examples
```js
import * as arr from './src/arrays.js';
arr.unique([1, 2, 2, 3]); // [1, 2, 3]
arr.chunk([1, 2, 3, 4], 2); // [[1,2], [3,4]]
arr.range(5); // [0, 1, 2, 3, 4]
arr.shuffle([1, 2, 3]); // Random order
arr.partition([1,2,3,4], x => x % 2); // [[1,3], [2,4]]
```
### โฑ๏ธ Async
`delay`, `sleep`, `withTimeout`, `retry`, `memoizeAsync`, `simpleQueue`, `debounce`, `throttle`
Show examples
```js
import * as async from './src/async.js';
await async.delay(1000); // Wait 1 second
await async.retry(() => fetchAPI(), { tries: 3 });
const debouncedSave = async.debounce(saveData, 500);
```
### ๐ File System (Node only)
`readJSON`, `writeJSON`, `ensureDir`, `listFiles`
### ๐ HTTP
`get`, `post` - using fetch with timeout + retries
> ๐ก **Tip:** See examples in each file and comprehensive tests in `tests/`.
## ๐งช Testing
Run all tests:
```bash
npm test
```
All utilities are tested with Node's built-in `assert` module.
## ๐ค Contributing
Want to add a utility or fix a bug? Awesome!
- Keep it simple and readable
- Add a test case in `tests/`
- Update the README with an example
- Check out [`CONTRIBUTING.md`](./CONTRIBUTING.md) for full guidelines
**๐ฌ Have questions?** Check out [Discussions](https://github.com/tbhvishal/js-toolbox/discussions) or open an [Issue](https://github.com/tbhvishal/js-toolbox/issues)!
## ๐ License
MIT ยฉ [tbhvishal](https://github.com/tbhvishal)
---
**Made with โค๏ธ for developers**
โญ Star this repo if you find it useful! โญ