mister-validator v1.0.3
Mister Validator
A simple validation library for common data types. This library provides easy-to-use functions to validate emails, URLs, numbers, integers, non-empty strings, and dates.
Installation
You can install the mister-validator library using npm:
npm install mister-validatorUsage
First, require the library in your project:
const {
isEmail,
isURL,
isNumber,
isInteger,
isNonEmptyString,
isDate,
} = require('mister-validator');Then, use the validation functions as needed:
Functions
isEmail(value)
Validates if a value is a valid email address.
Parameters:
value (string): The value to be validated. Returns:
boolean: true if the value is a valid email, false otherwise. Example:
console.log(isEmail('test@example.com')); // true
console.log(isEmail('invalid-email')); // falseisURL(value)
Validates if a value is a valid URL.
Parameters:
value (string): The value to be validated. Returns:
boolean: true if the value is a valid URL, false otherwise. Example:
console.log(isURL('https://www.example.com')); // true
console.log(isURL('invalid-url')); // falseisNumber(value)
Validates if a value is a valid number.
Parameters:
value (string): The value to be validated. Returns:
boolean: true if the value is a valid number, false otherwise. Example:
console.log(isNumber('123')); // true
console.log(isNumber('abc')); // falseisInteger(value)
Validates if a value is a valid integer.
Parameters:
value (number): The value to be validated. Returns:
boolean: true if the value is a valid integer, false otherwise. Example:
console.log(isInteger(123)); // true
console.log(isInteger(123.45)); // falseisNonEmptyString(value)
Validates if a value is a non-empty string.
Parameters:
value (string): The value to be validated. Returns:
boolean: true if the value is a non-empty string, false otherwise. Example:
console.log(isNonEmptyString('hello')); // true
console.log(isNonEmptyString(' ')); // falseisDate(value)
Validates if a value is a valid date.
Parameters:
value (string): The value to be validated. Returns:
boolean: true if the value is a valid date, false otherwise. Example:
console.log(isDate('2024-07-26')); // true
console.log(isDate('invalid-date')); // falseContributing Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
Author- nitinraina775@gmail.com