one-linear-validator
Version:
A minimalist, dependency-free JavaScript validation library with one-liner functions for validating emails, Strong Password, phone numbers, URLs, hex colors, and dates.
125 lines (91 loc) โข 3.15 kB
Markdown
# one-linear-validator ๐งช
[](https://www.npmjs.com/package/one-linear-validator)
[](https://www.npmjs.com/package/one-linear-validator)
[](https://github.com/MalikAhsan123/one-linear-validator/blob/main/LICENSE)
[](https://bundlephobia.com/package/one-linear-validator)
[](https://github.com/MalikAhsan123/one-linear-validator/issues)
> ๐ A minimalist, dependency-free JavaScript validation library with one-liner functions for common input formats like Email, Phone, URL, Hex Color, Date, and Strong Passwords โ returns clean structured results with error messages.
## โจ Features
- โ
Email validation
- ๐ฑ Phone number validation
- ๐ URL validation
- ๐จ Hex color code validation
- ๐
Date (YYYY-MM-DD) validation
- ๐ Strong password checker (with custom rules)
- โก๏ธ Lightweight & fast
- โ No external dependencies
- โ
ESM support (Node.js & modern browsers)
## ๐ฆ Installation
```bash
npm install one-linear-validator
or with yarn:
yarn add one-linear-validator
๐ Usage
import {
isEmail,
isPhoneNumber,
isURL,
isHexColor,
isDate,
isStrongPassword,
} from 'one-linear-validator';
console.log(isEmail('test@example.com'));
// { valid: true }
console.log(isPhoneNumber('+1234567890'));
// { valid: true }
console.log(isURL('https://example.com'));
// { valid: true }
console.log(isHexColor('#ffcc00'));
// { valid: true }
console.log(isDate('2024-05-06'));
// { valid: true }
console.log(isStrongPassword('Password@123'));
// { valid: true }
๐ API Reference
Each validator returns an object:
{ valid: true }
// or
{ valid: false, error: 'Reason here' }
isEmail(str)
Checks for a valid email format.
isPhoneNumber(str)
Accepts international formats, with or without +.
isURL(str)
Matches HTTP/HTTPS URLs, domains, optional port and path.
isHexColor(str)
Supports #RGB, #RRGGBB, or without #.
isDate(str)
Accepts date in YYYY-MM-DD format.
isStrongPassword(str, options?)
Checks password strength with default or custom rules.
Options:
{
minLength: 8,
uppercase: true,
number: true,
specialChar: true
}
โ
Example with Custom Password Rules
isStrongPassword('abc123', {
minLength: 6,
uppercase: false,
number: true,
specialChar: false,
});
๐ก Why one-linear-validator?
โ
Clean return values
โ
Simple integration
โ
Great for forms, APIs, and input sanitization
โ
Developer-friendly messages
๐ ๏ธ Contributing
Pull requests and suggestions are welcome!
Open an issue or fork and create a PR.
๐ License
Licensed under the Apache-2.0 License.
๐ Links
๐ฆ NPM Page
๐ GitHub Repo
Built with โค๏ธ by Muhammad Ahsan Raza