@jasgues/randomtools
v1.0.2
Published
Simple JavaScript utilities for random colors, numbers, strings, IDs, emails, names, passwords, and dates.
Readme
@jasgues/randomtools
A lightweight utility library for generating random colors, numbers, strings, IDs, emails, names, passwords, and dates.
Features
- 🎨 Generate random HEX color codes
- 🔢 Generate random integers within a specified range
- 🔤 Generate random strings for tokens and test data
- 🆔 Generate UUIDs
- 📧 Generate random emails
- 👤 Generate random names
- 🔐 Generate random passwords
- 📅 Generate random dates
- ⚡ Zero dependencies
- 📦 Lightweight and easy to use
Installation
npm install @jasgues/randomtoolsUsage
const {
randomColor,
randomNumber,
randomString,
randomUUID,
randomEmail,
randomName,
randomPassword,
randomDate
} = require("@jasgues/randomtools");
// Generate a random HEX color
console.log(randomColor());
// Example: "#4FA2D8"
// Generate a random integer between 1 and 100
console.log(randomNumber(1, 100));
// Example: 42
// Generate a random string
console.log(randomString(16));
// Example: "aZ7kP1xQ9mL2tR4b"
// Generate a UUID
console.log(randomUUID());
// Example: "550e8400-e29b-41d4-a716-446655440000"
// Generate a random email
console.log(randomEmail());
// Example: "[email protected]"
// Generate a random name
console.log(randomName());
// Example: "Alex Demir"
// Generate a random password
console.log(randomPassword(16));
// Example: "Q7!m2p#kL9s@v4Xz"
// Generate a random date
console.log(randomDate(new Date(2020, 0, 1), new Date(2025, 11, 31)));
// Example: 2023-08-14T10:22:31.000ZAPI
randomColor()
Generates a random HEX color string.
Returns
string— A color in the format#RRGGBB.
Example
const color = randomColor();
console.log(color);
// "#A13EF7"randomNumber(min, max)
Generates a random integer between min and max (inclusive).
Parameters
| Parameter | Type | Description |
| --------- | -------- | ------------- |
| min | number | Minimum value |
| max | number | Maximum value |
Returns
number— A random integer betweenminandmax.
Example
const number = randomNumber(10, 20);
console.log(number);
// 17randomString(length = 12)
Generates a random alphanumeric string.
Parameters
| Parameter | Type | Description |
| --------- | -------- | ----------- |
| length | number | String length |
Returns
string- A random alphanumeric string.
randomUUID()
Generates a random UUID.
Returns
string- A UUID string.
randomEmail()
Generates a random email address.
Returns
string- A random email address.
randomName()
Generates a random full name.
Returns
string- A random first and last name.
randomPassword(length = 16)
Generates a random password with upper-case letters, lower-case letters, numbers, and symbols.
Parameters
| Parameter | Type | Description |
| --------- | -------- | ----------- |
| length | number | Password length |
Returns
string- A random password.
randomDate(start = new Date(2000, 0, 1), end = new Date())
Generates a random Date between start and end.
Parameters
| Parameter | Type | Description |
| --------- | -------- | ----------- |
| start | Date | Minimum date |
| end | Date | Maximum date |
Returns
Date- A random date object.
License
ISC
Author
Jasgues
