@rocklab/validation
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

Rocklab validators

Node CI

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

Package Sidebar

Install

npm i @rocklab/validation

Weekly Downloads

54

Version

2.1.0

License

MIT

Unpacked Size

121 kB

Total Files

99

Last publish

Collaborators

  • cstn