Azmoodan is a JavaScript and TypeScript utility package that provides various helper functions for number manipulation, validations, and renderings.
npm install azmoodanAzmoodan is a JavaScript and TypeScript utility package that provides various helper functions for number manipulation, validations, and renderings.
1. Installation
2. Usage
3. API Reference
- Number Utilities
- Validations
- Renderings
4. Contributing
5. License
6. Contributors
You can install Azmoodan using npm:
``bash`
npm install azmoodan
Or using yarn:
`bash`
yarn add azmoodan
You can import the functions you need from Azmoodan:
`javascript`
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';
(Number utilities section remains the same as in the previous version)
#### validateEmail(email: string): boolean
Validates an email address.
`javascript`
const isValid = validateEmail('example@email.com');
console.log(isValid); // Output: true
#### checkStrongPassword(password: string): IStrongPassword
Checks the strength of a password and returns an object with details.
`javascript`
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.
`javascript`
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.
`javascript`
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.
`javascript`
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).
`javascript`
console.log(isEmpty([])); // Output: true
console.log(isEmpty({ key: 'value' })); // Output: false
#### getFileSize(file: File): number
Returns the size of a file in bytes.
`javascript`
const fileSize = getFileSize(myFile);
console.log(fileSize); // Output: file size in bytes
#### checkFileType(file: File): string
Returns the file extension.
`javascript`
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.
`javascript`
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.
`javascript`
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.
`javascript`
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.
`javascript`
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.
`javascript`
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.
`javascript`
const replaced = replaceAntiCharacters('abc_123!@#', '*');
console.log(replaced); // Output: 'abc123**'
#### replaceSpaces(value: string | number, char: string = ''): string
Replaces all spaces in a string with a specified character.
`javascript`
const replaced = replaceSpaces('Hello World', '_');
console.log(replaced); // Output: 'Hello_World'
#### isValidPhoneNumber(phone: number | string, prefix: boolean = false): boolean
Validates a phone number.
`javascript`
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).
`javascript`
const isValid = isValidMobileNumber('09123456789');
console.log(isValid); // Output: true
#### isValidateURL(url: string): boolean
Validates a URL.
`javascript`
const isValid = isValidateURL('https://www.example.com');
console.log(isValid); // Output: true
#### isValidZipCode(zipcode: string | number): boolean
Validates a zip code.
`javascript`
const isValid = isValidZipCode('12345-67890');
console.log(isValid); // Output: true
#### isValidDate(date: Date | string): boolean
Validates a date string in various formats.
`javascript`
const isValid = isValidDate('2023-05-15');
console.log(isValid); // Output: true
#### isValidTime(time: string): boolean
Validates a time string.
`javascript`
const isValid = isValidTime('14:30:00');
console.log(isValid); // Output: true
#### extractDates(text: string): string[]
Extracts all dates from a text string.
`javascript`
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.
`javascript`
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.
`javascript`
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.
`javascript``
const diff = getDateDifference('2023-05-15', '2023-06-01');
console.log(diff); // Output: 17
(This section is a placeholder. Please add descriptions and examples for the rendering functions from your renders.ts file.)
Contributions are welcome! Please feel free to submit a Pull Request.
If you have any questions or issues, please open an issue on the GitHub repository.