azmoodan
v1.0.2
Published
Azmoodan is a JavaScript and TypeScript utility package that provides various helper functions for number manipulation, validations, and renderings.
Downloads
4
Maintainers
Readme
Azmoodan
Azmoodan is a JavaScript and TypeScript utility package that provides various helper functions for number manipulation, validations, and renderings.
Table of Contents
Installation
You can install Azmoodan using npm:
npm install azmoodan
Or using yarn:
yarn add azmoodan
Usage
You can import the functions you need from Azmoodan:
import { randomNumber, randomRGB, randomPassword ,faNumToEn, enNumToFa, numberToWordsFa, numberToWordsEn, maskPhoneNumber, formatPhoneNumber, validateEmail, checkStrongPassword, personalRegex, rangeCharacter, rangeNumber, isEmpty, getFileSize, checkFileType, isImage, isVideo, isAudio, replaceNumbers, replaceAntiNumbers, replaceAntiCharacters, replaceSpaces, isValidPhoneNumber, isValidMobileNumber, isValidateURL, isValidZipCode, isValidDate, isValidTime, extractDates, extractTimes, convertDate, getDateDifference } from 'azmoodan';
API Reference
Number Utilities
(Number utilities section remains the same as in the previous version)
Validations
validateEmail(email: string): boolean
Validates an email address.
const isValid = validateEmail('[email protected]');
console.log(isValid); // Output: true
checkStrongPassword(password: string): IStrongPassword
Checks the strength of a password and returns an object with details.
const passwordStrength = checkStrongPassword('MyStr0ng@Password');
console.log(passwordStrength);
/* Output:
{
percent: 100,
details: {
haveSign: true,
haveCharacter: true,
haveNumber: true,
moreThanEight: true
}
}
*/
personalRegex(ReGex: RegExp, value: any): boolean
Tests a value against a custom regular expression.
const isMatch = personalRegex(/^\d{3}-\d{3}-\d{4}$/, '123-456-7890');
console.log(isMatch); // Output: true
rangeCharacter(min: number = 0, max: number = Infinity, value: string | number): number
Checks if the length of a string is within a specified range and returns the difference.
const diff = rangeCharacter(5, 10, 'Hello');
console.log(diff); // Output: 5 (10 - 5)
rangeNumber(min: number = 0, max: number = Infinity, value: number): boolean
Checks if a number is within a specified range.
const isInRange = rangeNumber(1, 100, 50);
console.log(isInRange); // Output: true
isEmpty(value: any): boolean
Checks if a value is empty (including empty objects and arrays).
console.log(isEmpty([])); // Output: true
console.log(isEmpty({ key: 'value' })); // Output: false
getFileSize(file: File): number
Returns the size of a file in bytes.
const fileSize = getFileSize(myFile);
console.log(fileSize); // Output: file size in bytes
checkFileType(file: File): string
Returns the file extension.
const fileType = checkFileType(myFile);
console.log(fileType); // Output: 'jpg' (for example)
isImage(file: File | string): boolean
Checks if a file is an image based on its extension.
const isImageFile = isImage('photo.jpg');
console.log(isImageFile); // Output: true
isVideo(file: File | string): boolean
Checks if a file is a video based on its extension.
const isVideoFile = isVideo('movie.mp4');
console.log(isVideoFile); // Output: true
isAudio(file: File | string): boolean
Checks if a file is an audio file based on its extension.
const isAudioFile = isAudio('song.mp3');
console.log(isAudioFile); // Output: true
replaceNumbers(value: string | number, char: string = ''): string
Replaces all numbers in a string with a specified character.
const replaced = replaceNumbers('abc123', '*');
console.log(replaced); // Output: 'abc***'
replaceAntiNumbers(value: string | number, char: string = ''): string
Replaces all non-numeric characters in a string with a specified character.
const replaced = replaceAntiNumbers('abc123', '*');
console.log(replaced); // Output: '***123'
replaceAntiCharacters(value: string | number, char: string = ''): string
Replaces all non-word characters in a string with a specified character.
const replaced = replaceAntiCharacters('abc_123!@#', '*');
console.log(replaced); // Output: 'abc*123***'
replaceSpaces(value: string | number, char: string = ''): string
Replaces all spaces in a string with a specified character.
const replaced = replaceSpaces('Hello World', '_');
console.log(replaced); // Output: 'Hello_World'
isValidPhoneNumber(phone: number | string, prefix: boolean = false): boolean
Validates a phone number.
const isValid = isValidPhoneNumber('123-12345678', true);
console.log(isValid); // Output: true
isValidMobileNumber(phone: number | string): boolean
Validates a mobile number (specifically for Iranian mobile numbers).
const isValid = isValidMobileNumber('09123456789');
console.log(isValid); // Output: true
isValidateURL(url: string): boolean
Validates a URL.
const isValid = isValidateURL('https://www.example.com');
console.log(isValid); // Output: true
isValidZipCode(zipcode: string | number): boolean
Validates a zip code.
const isValid = isValidZipCode('12345-67890');
console.log(isValid); // Output: true
isValidDate(date: Date | string): boolean
Validates a date string in various formats.
const isValid = isValidDate('2023-05-15');
console.log(isValid); // Output: true
isValidTime(time: string): boolean
Validates a time string.
const isValid = isValidTime('14:30:00');
console.log(isValid); // Output: true
extractDates(text: string): string[]
Extracts all dates from a text string.
const dates = extractDates('Meeting on 2023-05-15 and 2023-06-01');
console.log(dates); // Output: ['2023-05-15', '2023-06-01']
extractTimes(text: string): string[]
Extracts all times from a text string.
const times = extractTimes('Meeting at 09:00 AM and lunch at 12:30 PM');
console.log(times); // Output: ['09:00 AM', '12:30 PM']
convertDate(date: Date | string, format: string = "Fa-IR"): Date | string
Converts a date to a localized string representation.
const localDate = convertDate(new Date(), 'en-US');
console.log(localDate); // Output: localized date string
getDateDifference(dateOne: Date | string, dateTwo: Date | string): number | null
Calculates the difference in days between two dates.
const diff = getDateDifference('2023-05-15', '2023-06-01');
console.log(diff); // Output: 17
Renderings
(This section is a placeholder. Please add descriptions and examples for the rendering functions from your renders.ts file.)
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Contributors
Support
If you have any questions or issues, please open an issue on the GitHub repository.