Documentation
Comprehensive guide and API reference for Node Toolkit functions.
Installation
Install via npm
Add the package to your project:
npm install @neeraj-x0/nodetoolkit
Importing
Import specific functions as needed:
const { getExchangeRate, slugify } = require('@neeraj-x0/nodetoolkit');Network & API Utils
fetchJSON(url)
Fetch JSON with auto-retry logic.
const data = await fetchJSON('https://api.example.com/data');getExchangeRate(from, to)
Get real-time currency rates.
const rate = await getExchangeRate('USD', 'EUR');getPublicIP()
Get your public IP address.
const ip = await getPublicIP();
geoLocateIP(ip)
Get location info for an IP.
const loc = await geoLocateIP('8.8.8.8');checkWebsiteStatus(url)
Check if a website is up.
const isUp = await checkWebsiteStatus('https://google.com');downloadFile(url, path)
Download file to local disk.
await downloadFile('http://img.com/a.jpg', './a.jpg');getRandomQuote()
Get a random quote.
const quote = await getRandomQuote();
shortenURL(url)
Shorten a long URL.
const short = await shortenURL('https://very-long-url.com');String Utilities
capitalize(str)
Capitalize first letter.
capitalize('hello'); // 'Hello'slugify(str)
Convert string to URL slug.
slugify('Hello World'); // 'hello-world'camelCase(str)
Convert to camelCase.
camelCase('hello world'); // 'helloWorld'truncate(str, len)
Truncate string with ellipses.
truncate('long string...', 5); // 'long...'randomString(len)
Generate random alphanumeric string.
randomString(16);
maskString(str)
Mask sensitive data.
maskString('1234567890'); // '******7890'escapeHTML(str)
Escape HTML special chars.
escapeHTML('<script>'); // '<script>'Array & Object Utils
chunk(arr, size)
Split array into chunks.
chunk([1,2,3,4], 2); // [[1,2], [3,4]]
shuffle(arr)
Randomly shuffle array.
shuffle([1,2,3]);
unique(arr)
Remove duplicates.
unique([1,1,2]); // [1,2]
groupBy(arr, key)
Group objects by key.
groupBy(users, 'role');
deepClone(obj)
Deep copy an object.
const copy = deepClone(original);
Math Utilities
randomInt(min, max)
Random integer in range.
randomInt(1, 10);
formatCurrency(num)
Format number as currency.
formatCurrency(1000, 'USD'); // '$1,000.00'
clamp(num, min, max)
Constrain number range.
clamp(105, 0, 100); // 100
formatCompactNumber(num)
Format large numbers.
formatCompactNumber(1500); // '1.5K'
System Utilities
getSystemInfo()
Get OS/CPU/Memory info.
console.log(getSystemInfo());
getFileSize(path)
Get human readable file size.
getFileSize('./video.mp4'); // '15 MB'ensureDir(path)
Ensure directory exists.
ensureDir('./downloads/images');getHash(content)
Calculate SHA256 hash.
getHash('some content');Validation
isEmail(str)
Check if valid email.
isEmail('test@test.com'); // trueisStrongPassword(str)
Check password strength.
isStrongPassword('Pass123!'); // trueisEmpty(val)
Check if null/empty.
isEmpty([]); // true
Function Wrappers
retry(fn, retries)
Retry async function on fail.
await retry(fetchData, 3);
once(fn)
Ensure function runs only once.
const init = once(() => setup());
sleep(ms)
Async delay.
await sleep(1000);
debounce(fn, ms)
Debounce execution.
const handler = debounce(() => save(), 500);
Audio/Video Conversion
toAudio(buffer, ext)
Converts an audio buffer to a playable audio file.
const audioBuffer = fs.readFileSync('input.wav');
const mp3Buffer = await toAudio(audioBuffer, 'mp3');toVideo(buffer, ext)
Converts video buffer to playable MP4 file.
const videoBuffer = await toVideo(buffer, 'mp4');
webp2mp4(source)
Converts animated WebP to MP4 video buffer.
const mp4Buffer = await webp2mp4('sticker.webp');Need help? Open an issue on GitHub.