Hey, Devs! 👋
I’m excited to announce the release of one-linear-validator, a minimalist and dependency-free JavaScript validation library that provides simple, one-liner functions for validating common data types like emails, phone numbers, URLs, hex colors, dates, and strong passwords.
Why One-Linear-Validator?
In modern web development, data validation is crucial to ensure that the data users enter is correct and secure. However, sometimes, we just need a quick and efficient solution without bloating our projects with unnecessary dependencies. That’s exactly what one-linear-validator offers – a lightweight solution to validate your data in a clean, simple, and fast manner.
I created this package with the goal of providing an easy-to-use validation library that doesn't require complex setups or external dependencies. Whether you need to validate a user’s email, check the strength of a password, or confirm a valid hex color, one-linear-validator has got you covered.
Key Features
Email Validation: Check if an email follows the correct format.
Phone Number Validation: Validate international phone numbers.
URL Validation: Ensure URLs are properly formatted.
Hex Color Validation: Verify if the input is a valid hex color code.
Date Validation: Validate dates in the YYYY-MM-DD format.
Strong Password Validation: Ensure the password meets certain strength criteria like minimum length, uppercase letters, numbers, and special characters.
No Dependencies: The library is 100% dependency-free, ensuring that your project stays lightweight and fast.
Installation
You can install one-linear-validator from npm using the following command:
npm install one-linear-validator
Or with yarn:
yarn add one-linear-validator
How to Use
The usage is pretty simple! After installation, you can use the validation functions directly by importing them.
Email Validation:
import { isEmail } from 'one-linear-validator';
console.log(isEmail('example@example.com')); // { valid: true }
console.log(isEmail('invalid-email')); // { valid: false, error: 'Invalid email format' }
Password Strength Check:
import { isStrongPassword } from 'one-linear-validator';
const options = {
minLength: 8,
uppercase: true,
number: true,
specialChar: true,
};
console.log(isStrongPassword('P@ssw0rd', options)); // { valid: true }
console.log(isStrongPassword('weakpassword')); // { valid: false, error: 'Password must contain an uppercase letter' }
Phone Number Validation:
import { isPhoneNumber } from 'one-linear-validator';
console.log(isPhoneNumber('+1234567890')); // { valid: true }
console.log(isPhoneNumber('123456')); // { valid: false, error: 'Invalid phone number format' }
Hex Color Validation:
import { isHexColor } from 'one-linear-validator';
console.log(isHexColor('#ff5733')); // { valid: true }
console.log(isHexColor('123abc')); // { valid: true }
console.log(isHexColor('gggggg')); // { valid: false, error: 'Invalid hex color' }
Why Build This?
As developers, we often need to validate user input in forms, APIs, or web applications. Instead of writing custom validation functions every time, one-linear-validator allows us to save time and effort by providing simple, one-liner validation functions that are quick to use and easy to integrate.
It's lightweight, dependency-free, and solves a common problem that many developers face. Whether you're building a small project or working with large-scale applications, this library is simple to implement and offers consistent, reliable results.
Contributing
If you’d like to contribute to the project, feel free to fork the repository and create a pull request. If you encounter any bugs or have feature requests, please raise an issue on the GitHub repository.
Top comments (1)
Nice, I always end up writing my own little validators so this would save me a bunch of time.