Skip to content

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

Notifications You must be signed in to change notification settings

tbhvishal/js-toolbox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

js-toolbox ⚡

Node Version License Zero Dependencies GitHub Stars GitHub Issues Commits

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

# 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:
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:
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
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
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('<script>alert("xss")</script>');  // Safe HTML

📅 Dates

formatDate, fromNow, addDays, isSameDay, parseISO, startOfDay, endOfDay, daysBetween

Show examples
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
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
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:

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 for full guidelines

💬 Have questions? Check out Discussions or open an Issue!

📄 License

MIT © tbhvishal


Made with ❤️ for developers

⭐ Star this repo if you find it useful! ⭐

About

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

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published