Skip to content

redwan-ul/redwanul

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

redwanul

A simple utility package with useful functions and an interactive CLI.

Installation

npm install redwanul

Or install globally to use the CLI from anywhere:

npm install -g redwanul

Usage

As a module in your project

const 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!' }

Using the CLI

If installed globally, you can run:

redwanul

Or if installed locally:

npx redwanul

The CLI provides an interactive menu with the following options:

  1. Get a greeting
  2. Generate a random number
  3. Show current date and time
  4. Format text
  5. Generate a password
  6. Calculate time difference
  7. Truncate text
  8. Convert text to slug
  9. Generate unique ID
  10. Format currency
  11. Validate email
  12. Validate URL
  13. Convert array to CSV
  14. Exit

Available Functions

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

License

ISC

Author

Redwanul Haque

About

A simple utility package with useful functions and an interactive CLI

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors