@rocklab/validation
v2.1.0
Published
A library for input validation
Downloads
133
Maintainers
Readme
Rocklab validators
A library for input validation
- Credit card (number, cvc, expiration date)
- BIC (Bank Identifier Code)
- E-mail address
- IBAN (International Bank Account Number)
- non empty
- length
- password
- username
Requirements
- node version 18
- npm version 9
Install
npm install @rocklab/validation
Usage
Validate input:
import { isEmail, hasLength } from '@rocklab/validation';
if (!isEmail(value)) {
alert('Please enter a valid email address');
}
if (!hasLength(value, { min: 3, max: 10 })) {
alert('3-8 chars required');
}
Apply multiple validators:
import { validate, Validators } from '@rocklab/validation';
const errors = validate(value, [
{ validator: Validator.NotEmpty, message: 'Input required'},
{ validator: Validator.Email, message: 'email required'},
]);
Development
Setup
git clone https://github.com/cstn/rocklab-validation.git
npm install
Commands
Build
npm run build
Check code conventions
npm run lint
npm run lint:fix
Auto format code
npm run prettier
Run tests
npm test
npm run watch
WITHOUT WARRANTY OF ANY KIND