validatorcraft
v1.0.0
Published
A lightweight, dependency-free JavaScript validation library for Node.js.
Downloads
147
Maintainers
Readme
validatorcraft
A lightweight, zero-dependency JavaScript validation library for Node.js.
Features
- Zero Dependencies: Lightweight and fast.
- Node.js Ready: Works with Node >= 18.
- Pure Functions: Returns only booleans, throws no unnecessary exceptions.
- Comprehensive: Validate emails, phones, passwords, UUIDs, hex colors, and more.
Installation
npm install validatorcraftUsage
const validator = require('validatorcraft');
// Email Validation
validator.isEmail('[email protected]'); // true
// Phone Validation
validator.isPhone('+1234567890'); // true
// Password Validation
validator.isStrongPassword('StrongP@ssw0rd'); // true
// Hex Color
validator.isHexColor('#ffffff'); // true
// Length checks
validator.betweenLength('hello', 3, 10); // trueAPI Reference
isEmail(email)
Validates proper email format.
- Returns:
boolean
isPhone(phone)
Validates phone numbers, including international numbers beginning with +.
- Returns:
boolean
isStrongPassword(password)
Validates passwords based on strong criteria:
- Minimum 8 characters
- At least one uppercase letter
- At least one lowercase letter
- At least one number
- At least one special character
- Returns:
boolean
isUsername(username)
Validates a username based on:
- 3–20 characters long
- Contains only letters, numbers, and underscores
- Returns:
boolean
isURL(url)
Validates standard http and https URLs.
- Returns:
boolean
isNumeric(value)
Returns true only if the string contains digits.
- Returns:
boolean
isAlpha(value)
Returns true only if the string contains alphabetic characters.
- Returns:
boolean
isAlphaNumeric(value)
Returns true only if the string contains alphanumeric characters.
- Returns:
boolean
isEmpty(value)
Returns true for "", null, and undefined.
- Returns:
boolean
minLength(str, len)
Checks if the string length is at least len.
- Returns:
boolean
maxLength(str, len)
Checks if the string length is at most len.
- Returns:
boolean
betweenLength(str, min, max)
Checks if the string length is between min and max (inclusive).
- Returns:
boolean
isJSON(str)
Checks if a string is valid JSON.
- Returns:
boolean
isUUID(str)
Checks if a string is a valid UUID v4.
- Returns:
boolean
isHexColor(color)
Checks if a string is a valid hex color (e.g., #fff, #000000).
- Returns:
boolean
isDate(date)
Checks if a string is a valid ISO date.
- Returns:
boolean
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License.
