A simple utility package with useful functions and an interactive CLI.
npm install redwanulOr install globally to use the CLI from anywhere:
npm install -g redwanulconst redwanul = require('redwanul');
// Get a greeting
console.log(redwanul.greet('John'));
// Output: Hello John! Welcome to redwanul's package.
// Generate a random number between 1 and 100
console.log(redwanul.randomNumber(1, 100));
// Output: Random number between 1 and 100
// Format current date and time
console.log(redwanul.formatDate());
// Output: Current date in a nice format
// Format text
console.log(redwanul.formatText('hello world', { uppercase: true }));
// Output: HELLO WORLD
console.log(redwanul.formatText('hello world', { capitalize: true }));
// Output: Hello world
console.log(redwanul.formatText('hello world', { reverse: true }));
// Output: dlrow olleh
// Generate a secure password
console.log(redwanul.generatePassword(16, { includeSymbols: true }));
// Output: Random 16-character password
// Calculate time difference
console.log(redwanul.timeDifference(new Date('2023-01-01'), new Date()));
// Output: Time difference in human-readable format
// Truncate long text
console.log(redwanul.truncateText('This is a very long text that needs to be truncated', 20));
// Output: This is a very lon...
// Convert text to URL-friendly slug
console.log(redwanul.slugify('Hello World! This is a test'));
// Output: hello-world-this-is-a-test
// Generate unique ID
console.log(redwanul.generateId(8));
// Output: Random 8-character ID
// Format currency
console.log(redwanul.formatCurrency(1234.56, 'USD', 'en-US'));
// Output: $1,234.56
// Validate email
console.log(redwanul.isValidEmail('test@example.com'));
// Output: true
// Validate URL
console.log(redwanul.isValidUrl('https://example.com'));
// Output: true
// Convert array to CSV
console.log(redwanul.arrayToCsv([['name', 'age'], ['John', 30], ['Jane', 25]]));
// Output: name,age\nJohn,30\nJane,25
// Access package info
console.log(redwanul.info);
// Output: { name: 'redwanul', author: 'Redwanul Haque', message: 'Thanks for using my package!' }If installed globally, you can run:
redwanulOr if installed locally:
npx redwanulThe CLI provides an interactive menu with the following options:
- Get a greeting
- Generate a random number
- Show current date and time
- Format text
- Generate a password
- Calculate time difference
- Truncate text
- Convert text to slug
- Generate unique ID
- Format currency
- Validate email
- Validate URL
- Convert array to CSV
- Exit
| Function | Description |
|---|---|
greet(name) |
Returns a greeting with the provided name |
randomNumber(min, max) |
Generates a random number between min and max (inclusive) |
formatDate(date) |
Formats a date in a nice way (defaults to current date) |
formatText(text, options) |
Formats text based on options (uppercase, lowercase, capitalize, reverse) |
generatePassword(length, options) |
Generates a secure random password with specified options |
timeDifference(date1, date2) |
Calculates human-readable time difference between two dates |
truncateText(text, maxLength, suffix) |
Truncates text to specified length with optional suffix |
slugify(text) |
Converts text to a URL-friendly slug |
generateId(length) |
Generates a unique random ID of specified length |
formatCurrency(amount, currency, locale) |
Formats a number as currency |
isValidEmail(email) |
Checks if a string is a valid email address |
isValidUrl(url) |
Checks if a string is a valid URL |
arrayToCsv(array, delimiter) |
Converts a 2D array to CSV string |
ISC
Redwanul Haque