Package Exports
- nhb-toolbox
- nhb-toolbox/array/types
- nhb-toolbox/colors/types
- nhb-toolbox/date/types
- nhb-toolbox/form/types
- nhb-toolbox/number/types
- nhb-toolbox/object/types
- nhb-toolbox/package.json
- nhb-toolbox/plugins/businessPlugin
- nhb-toolbox/plugins/dayPartPlugin
- nhb-toolbox/plugins/fromNowPlugin
- nhb-toolbox/plugins/palindromePlugin
- nhb-toolbox/plugins/relativeTimePlugin
- nhb-toolbox/plugins/seasonPlugin
- nhb-toolbox/plugins/timeZonePlugin
- nhb-toolbox/plugins/zodiacPlugin
- nhb-toolbox/string/types
- nhb-toolbox/types
- nhb-toolbox/utils/types
Readme
NHB Toolbox
“I solve problems you face daily”
TypeScript Utility Library
NHB Toolbox provides battle-tested utilities for professional TypeScript development. Carefully crafted to solve common challenges with elegant, production-ready solutions:
- Helper Functions & Classes: Reusable solutions for everyday tasks
- Type Guards & Predicates: Runtime safety with perfect type inference
- Validation Utilities: Robust data validation patterns
- Zero Dependencies: Framework-agnostic implementation using only native TS/JS with 0 external package
Install
Choose your preferred package manager:
npm i nhb-toolboxpnpm add nhb-toolboxyarn add nhb-toolboxChangelog
See Changelog for recent updates.
Key Features
- Type-Safe Utilities:Fully typed for perfect TypeScript integration with strict type checking
- Modular Design: Tree-shaking friendly – import only what you need with zero bloat
- Zero Dependencies: No external dependencies - works with any JS/TS framework
- IDE Support: Full type hints with JSDoc-powered API references in your editor
- Comprehensive Documentation: Learn with real-world use cases on documentation site
- Battle-Tested: Reliable utilities refined through real-world production use
- Optimized for Production: Focused on clean, efficient implementations
Signature Utilities
🕰️ Chronos - Time Mastery
The ultimate date/time manipulation class with 100+ methods for parsing, formatting, calculating, and comparing dates. Handles all edge cases and timezones safely.
new Chronos('2025-01-01').addDays(3).format('YYYY-MM-DD'); // "2025-01-04"🎨 Color - Professional Color Manipulation
Convert between color formats, generate palettes, check accessibility contrast, and perform advanced color math with perfect type safety.
const blue = new Color('#0000ff');
const darkerBlue = blue.applyDarkness(20); // 20% darker
console.log(darkerBlue.hsl); // "hsl(240, 100%, 40%)" (was 50%)🔍 Finder - Optimized Array Search
Blazing-fast array searching with binary search, fuzzy matching, and smart caching. Perfect for large datasets.
const productFinder = new Finder(products);
const laptop = productFinder.findOne('laptop', 'category', {
fuzzy: true,
caseInsensitive: false,
});🆔 Random ID Generation
generateRandomID - Enterprise-grade unique ID generation with prefixes, timestamps, and formatting
generateRandomID({
prefix: 'user',
timeStamp: true,
length: 12,
caseOption: 'upper',
}); // "USER-171234567890-AB3C4D5E6F7G"🎨 Color System Utilities
getColorForInitial - Deterministic color mapping system for consistent UI theming
// Get color palette for user avatars
getColorForInitial(['Alice', 'Bob', 'Charlie']);
// ['#00094C', '#00376E', '#005600']
getColorForInitial('Banana', 50); // '#00376E80' (50% opacity)🛡️ Sanitize Data
Clean and normalize strings/objects by trimming whitespace, removing empty values, and applying customizable filters.
const user = {
name: ' John Doe ',
age: null,
address: { city: ' NYC ', zip: '' },
tags: [],
};
sanitizeData(user, { ignoreNullish: true, ignoreEmpty: true });
// Returns { name: "John Doe", address: { city: "NYC" } } with exact input type
sanitizeData(user, { ignoreNullish: true }, 'partial');
// Return type: FlattenPartial<typeof user> which is Partial<T>
// Returns { name: "John Doe", address: { city: "NYC" } }
// { name: 'John' }🔄 JSON Hydration
parseJSON - Bulletproof JSON parsing with primitive conversion
parseJSON('{"value":"42"}'); // { value: 42 } (auto-converts numbers)💰 Format Currency
Intelligent currency formatting with automatic locale detection and 150+ supported currencies.
console.log(formatCurrency(99.99, 'EUR')); // "99,99 €"
console.log(formatCurrency('5000', 'JPY')); // "¥5,000" (ja-JP locale)
console.log(formatCurrency('5000', 'BDT')); // "৫,০০০.০০৳" (bn-BD locale)🔢 Number to Words
Convert numbers to human-readable words (supports up to 100 quintillion).
numberToWords(125); // "one hundred twenty-five"🔢 Advanced Number Operations
getNumbersInRange - Generate intelligent number sequences with prime, even/odd, and custom filtering capabilities
// Get primes between 10-30 as formatted string
getNumbersInRange('prime', { min: 10, max: 30, getAsString: true });
// "11, 13, 17, 19, 23, 29"calculatePercentage - Swiss Army knife for percentage calculations with 7 specialized modes
// Calculate percentage change
calculatePercentage({
mode: 'get-change-percent',
oldValue: 100,
newValue: 150,
}); // 50 (50% increase)🔄 Extract Updated Fields
Detect exactly what changed between two objects (including deep nested changes).
const dbRecord = { id: 1, content: 'Hello', meta: { views: 0 } };
const update = { content: 'Hello', meta: { views: 1 } };
extractUpdatedFields(dbRecord, update);
// { meta: { views: 1 } }⚡ Performance Optimizers
throttleAction - Precision control for high-frequency events
// Smooth scroll handling
throttleAction(updateScrollPosition, 100);debounceAction - Intelligent delay for expensive operations
// Search-as-you-type
debounceAction(fetchResults, 300);These utilities represent just a portion of the comprehensive
toolbox. Each is designed with production-grade reliability and developer experience in mind. Explore more in the full documentation. All the utilities and classes are categorized.
License
This project is licensed under the Apache License 2.0 with the following additional requirement:
Additional Requirement:
Any fork, derivative work, or redistribution of this project must include clear attribution to Nazmul Hassan in both the source code and any publicly available documentation.
You are free to use, modify, and distribute this project under the terms of the Apache 2.0 License, provided that appropriate credit is given.