A lightweight and flexible JavaScript library for validating. It provides a simple API to define validation rules for various data types, including strings, numbers, arrays, and objects.
- Table of Contents
- Features
- Security Notice
- Installation
- Usage Examples
- Dependencies
- Related Projects
- Validate strings, numbers, arrays, and objects.
- Built-in validation rules like
required,minLength,maxLength,min,max,email, and more. - Custom validation with
refine. - Schema-based validation for objects and arrays.
- Lightweight and easy to use.
- To ensure the security and integrity of your projects, please note that official PearPass packages are distributed exclusively through our GitHub organization.
- Any packages with similar names found on the npm registry or other third-party package managers are not affiliated with PearPass and should be strictly avoided. We recommend installing directly from this repository to ensure you are using the verified, open-source version.
Install the library using npm:
npm install git+https://github.com/tetherto/pear-apps-utils-validator.gitimport { Validator } from '@tetherto/pear-apps-utils-validator';
const validator = Validator.string().required().minLength(3);
console.log(validator.validate('')); // Output: "This field is required"
console.log(validator.validate('ab')); // Output: "Minimum length is 3"
console.log(validator.validate('abc')); // Output: nullconst schema = {
name: Validator.string().required(),
age: Validator.number().min(18),
};
const validator = Validator.object(schema);
console.log(validator.validate({ name: '', age: 16 }));
// Output: { name: "This field is required", age: "Minimum value is 18" }const itemValidator = Validator.string().minLength(3);
const arrayValidator = Validator.array().items(itemValidator);
console.log(arrayValidator.validate(['valid', 'a']));
// Output: [{ index: 1, error: "Minimum length is 3" }]This package has no production dependencies.
- @tetherto/pearpass-app-mobile - A mobile app for PearPass, a password manager
- @tetherto/pearpass-app-desktop - A desktop app for PearPass, a password manager
- @tetherto/pearpass-lib-vault - A library for managing password vaults
- @tetherto/tether-dev-docs - Documentations and guides for developers
This project is licensed under the Apache License, Version 2.0. See the LICENSE file for details.k