random-gen-utils
v1.0.0
Published
A comprehensive utility package for generating random strings, passwords, colors, and numbers with customizable options
Maintainers
Readme
🎲 Random Generator Utils
A lightweight, zero-dependency utility package for generating random strings, passwords, colors, and numbers with customizable options.
📦 Installation
npm install random-gen-utils🚀 Quick Start
const randomGen = require('random-gen-utils');
// Generate random string
const str = randomGen.randomString(10);
// Generate random password
const pwd = randomGen.randomPassword(16);
// Generate random color
const color = randomGen.randomColor('hex');
// Generate random number
const num = randomGen.randomNumber(1, 100);📖 API Reference
randomString(length, type)
Generate a random string with specified length and character type.
Parameters:
length(number, optional): Length of the string. Default:10type(string, optional): Type of characters -'alphanumeric','alpha', or'numeric'. Default:'alphanumeric'
Returns: string
Examples:
randomGen.randomString(); // "aB3xK9mP2q" (10 chars, alphanumeric)
randomGen.randomString(20); // 20 character alphanumeric string
randomGen.randomString(15, 'alpha'); // "AbCdEfGhIjKlMnO" (15 chars, letters only)
randomGen.randomString(8, 'numeric'); // "12345678" (8 chars, numbers only)randomPassword(length, options)
Generate a secure random password with customizable character types.
Parameters:
length(number, optional): Length of the password. Default:12options(object, optional): Password optionsuppercase(boolean): Include uppercase letters A-Z. Default:truelowercase(boolean): Include lowercase letters a-z. Default:truenumbers(boolean): Include numbers 0-9. Default:truesymbols(boolean): Include special symbols. Default:true
Returns: string
Examples:
randomGen.randomPassword(); // "aB3#xK9@mP2!" (12 chars, all types)
randomGen.randomPassword(16); // 16 character password with all types
randomGen.randomPassword(20, {
uppercase: true,
lowercase: true,
numbers: true,
symbols: false
}); // 20 char password without symbolsrandomColor(format)
Generate a random color in various formats.
Parameters:
format(string, optional): Color format -'hex','rgb','hsl', or'array'. Default:'hex'
Returns: string or array (depending on format)
Examples:
randomGen.randomColor(); // "#a3f5b2" (HEX format)
randomGen.randomColor('rgb'); // "rgb(163, 245, 178)"
randomGen.randomColor('hsl'); // "hsl(132, 85%, 80%)"
randomGen.randomColor('array'); // [163, 245, 178]randomNumber(min, max, decimal, precision)
Generate a random number within a specified range.
Parameters:
min(number, optional): Minimum value. Default:0max(number, optional): Maximum value. Default:100decimal(boolean, optional): Return decimal/float number. Default:falseprecision(number, optional): Decimal places for floats. Default:5
Returns: number
Examples:
randomGen.randomNumber(); // 42 (integer between 0-100)
randomGen.randomNumber(1, 10); // 7 (integer between 1-10)
randomGen.randomNumber(0, 1, true); // 0.72341 (decimal between 0-1)
randomGen.randomNumber(0, 100, true, 2); // 42.56 (decimal with 2 places)💡 Usage Examples
Generate Test Data
const testUsers = Array.from({ length: 10 }, (_, i) => ({
id: randomGen.randomString(8),
username: `user_${randomGen.randomNumber(1000, 9999)}`,
password: randomGen.randomPassword(16),
favoriteColor: randomGen.randomColor('hex')
}));Create Session IDs
const sessionId = randomGen.randomString(32, 'alphanumeric');Generate API Keys
const apiKey = randomGen.randomPassword(64, {
uppercase: true,
lowercase: true,
numbers: true,
symbols: false
});Random UI Theming
const theme = {
primary: randomGen.randomColor('hex'),
secondary: randomGen.randomColor('hex'),
accent: randomGen.randomColor('rgb'),
opacity: randomGen.randomNumber(50, 100, true, 2) / 100
};Express.js Route Example
const express = require('express');
const randomGen = require('random-gen-utils');
const app = express();
app.get('/api/random-color', (req, res) => {
res.json({
color: randomGen.randomColor('hex'),
rgb: randomGen.randomColor('rgb')
});
});
app.listen(3000);🌐 TypeScript Support
While this package is written in JavaScript, you can use it in TypeScript projects:
import * as randomGen from 'random-gen-utils';
const password: string = randomGen.randomPassword(16);
const num: number = randomGen.randomNumber(1, 10);✨ Features
- ✅ Zero dependencies - Lightweight and fast
- ✅ CommonJS support - Works in Node.js projects
- ✅ Customizable options - Fine-tune output to your needs
- ✅ Multiple formats - Colors in HEX, RGB, HSL, or array
- ✅ Secure passwords - Customizable character sets
- ✅ Well documented - Clear examples and API docs
📝 License
MIT License - see LICENSE file for details
🤝 Contributing
Contributions, issues, and feature requests are welcome!
👤 Author
Rakesh Kumar
🙏 Support
Give a ⭐️ if this project helped you!
