Welcome to NHB Toolbox π¦
Replace Boilerplate(s) with One-Liner(s)
nhb-toolbox
provides battle-tested utilities for professional TypeScript/JavaScript 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
- Types: Includes utility types designed to enhance type safety and developer ergonomics
π§° Installation Guideβ
nhb-toolbox
is published to two package registries:
- NPM Registry (default public registry) - This is the simplest way to install and requires no additional setup.
- GitHub Packages (GitHubβs package registry, scoped package)
- Use NPM Registry (default) if you want the stable public version without extra config.
- GitHub Packages requires authentication and scoped package names.
π¦ Install as Main Dependencyβ
- π¦ npm
- π§Ά yarn
- π pnpm
- NPM Registry
npm i nhb-toolbox
- GitHub Packages
npm i @nazmul-nhb/nhb-toolbox
- NPM Registry
yarn add nhb-toolbox
- GitHub Packages
yarn add @nazmul-nhb/nhb-toolbox
- NPM Registry
pnpm add nhb-toolbox
- GitHub Packages
pnpm add @nazmul-nhb/nhb-toolbox
π οΈ Install as Dev Dependencyβ
- π¦ npm
- π§Ά yarn
- π pnpm
- NPM Registry
npm i -D nhb-toolbox
- GitHub Packages
npm i -D @nazmul-nhb/nhb-toolbox
- NPM Registry
yarn add -D nhb-toolbox
- GitHub Packages
yarn add -D @nazmul-nhb/nhb-toolbox
- NPM Registry
pnpm add -D nhb-toolbox
- GitHub Packages
pnpm add -D @nazmul-nhb/nhb-toolbox
π Install Globallyβ
- π¦ npm
- π§Ά yarn
- π pnpm
- NPM Registry
npm i -g nhb-toolbox
- GitHub Packages
npm i -g @nazmul-nhb/nhb-toolbox
- NPM Registry
yarn add -g nhb-toolbox
- GitHub Packages
yarn add -g @nazmul-nhb/nhb-toolbox
- NPM Registry
pnpm add -g nhb-toolbox
- GitHub Packages
pnpm add -g @nazmul-nhb/nhb-toolbox
π¦ Installation Guide from GitHub Packagesβ
GitHub Packages requires authentication and scoped package names.
Step 1: Authenticate with GitHub Packagesβ
Create or use a GitHub Personal Access Token (PAT) with read:packages
permission.
Add the following to your projectβs .npmrc
file (create if it doesnβt exist):
@nazmul-nhb:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=YOUR_GITHUB_PERSONAL_ACCESS_TOKEN
Replace
YOUR_GITHUB_PERSONAL_ACCESS_TOKEN
with your actual token.
Step 2: Install the package with scoped nameβ
Choose your preferred package manager:
npm i @nazmul-nhb/nhb-toolbox
pnpm add @nazmul-nhb/nhb-toolbox
yarn add @nazmul-nhb/nhb-toolbox
Where do consumers get the GitHub token?β
-
The token is personal and private β each consumer must create own.
-
Your GitHub Personal Access Token (PAT) should never be shared publicly or with consumers.
How consumers create own tokenβ
-
Go to GitHub account settings β Developer settings β Personal access tokens β Tokens (classic).
-
Click Generate new token, then:
-
Give it a name (e.g.,
npm package read access
). -
Set expiration as prefer.
-
Enable only the
read:packages
permission (to allow reading packages).
-
-
Generate the token and copy it immediately β won't see it again.
What should consumers do with the token?β
- Add it to
.npmrc
file (or environment) to authenticate with GitHub Packages.
Example .npmrc
snippet:
@nazmul-nhb:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=PERSONAL_ACCESS_TOKEN_HERE
Summaryβ
Registry | Package Name | Registry URL | Requires Auth? |
---|---|---|---|
NPM Registry | nhb-toolbox | https://registry.npmjs.org | No |
GitHub Packages | @nazmul-nhb/nhb-toolbox | https://npm.pkg.github.com | Yes (PAT with read:packages ) |
If you want to use both, just configure .npmrc
accordingly and install the appropriate package name depending on your needs.
Notesβ
- The GitHub Packages version may include pre-release or private builds.
- NPM Registry version is the recommended default for most users.
- You can safely use either registry depending on your environment.
π Featuresβ
- Type-Safe Utilities: Fully typed for perfect TypeScript integration with strict type checking
- Types: Ready-to-use types designed to enhance type safety and developer efficiency
- 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
- Battle-Tested: Reliable utilities refined through real-world production use
- Optimized for Production: Focused on clean, efficient implementations
πͺ§ Examples from Signature Utilitiesβ
π°οΈ Date & Time Masteryβ
Chronos
- The ultimate date/time manipulation class with 100+ methods for parsing, formatting, calculating, and comparing dates. Handles all edge cases and timezones safely.
π§© Note: Some methods in
Chronos
are available only through the plugin system. This modular design ensures the core bundle stays lightweight β plugins are loaded only when needed, reducing unnecessary code in your final build.
new Chronos('2025-01-01').addDays(3).format('YYYY-MM-DD'); // "2025-01-04"
// or with `Chronos` wrapper
chronos('2025-01-01').addDays(3).format('YYYY-MM-DD'); // "2025-01-04"
π¨ Professional Color Manipulationβ
Color
- 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%)
π Optimized Array Searchβ
Finder
- 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"
π’ Pluralize Strings and Moreβ
pluralizer
- Handles English word pluralization and singularization with support for irregular forms and uncountable nouns.
import { pluralizer } from 'nhb-toolbox';
pluralizer.pluralize('child'); // "children"
pluralizer.pluralize('category', { count: 3 }); // "categories"
pluralizer.pluralize('child', { count: 1, inclusive: true }); // "1 child"
pluralizer.toSingular('geese'); // "goose"
pluralizer.toSingular('children'); // "child"
pluralizer.isPlural('children'); // true
pluralizer.isSingular('child'); // true
pluralizer.isPlural('fish'); // true (uncountable)
π¨ 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)
π FormData Preparationβ
createFormData
- Convert JavaScript objects into FormData
with extensive configuration options for handling nested structures, files, and data transformations.
import { createFormData } from 'nhb-toolbox';
const formData = createFormData({
user: {
name: ' John Doe ',
age: 30,
preferences: { theme: 'dark' }
},
files: [file1, file2]
}, {
trimStrings: true,
lowerCaseValues: ['user.name'],
dotNotateNested: ['user.preferences'],
breakArray: ['files']
});
// Resulting FormData:
// user.name=john doe
// user.age=30
// user.preferences.theme=dark
// files[0]=[File1]
// files[1]=[File2]
π‘οΈ Data Sanitizationβ
sanitizeData
- 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: number }>('{"value":"42"}'); // { value: 42 } (auto-converts numbers)
π’ Number to Wordsβ
numberToWords
- 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β
extractUpdatedFields
- 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 } }
π¨ Style Console Output(s)β
Stylog
- Chalk
-like minimal utility to style console output(s) in both Node.js & Browser environment(s) (supports named CSS colors).
// Basic coloring
Stylog.error.log('Error message');
Stylog.success.log('Success message');
Stylog.info.log('Info message');
Stylog.whitesmoke.log('I am White!');
// Multiple styles
Stylog.blue.bold.underline.log('I am Bold Underlined Blue!');
// With object stringification
Stylog.magenta.italic.log({ data: 'value' }, true);
β‘ 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
nhb-toolbox
. Each is designed with production-grade reliability and developer experience in mind. All the utilities and classes are categorized. Explore by categories or usectrl+k
to search your desired utility, class or type.