All Projects → VitorLuizC → valite

VitorLuizC / valite

Licence: MIT license
🔥 Concurrently execute your validators in a simple, practical and light validator engine.

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to valite

validate-framework
validate-framework:一款轻量、无依赖的 JavaScript 验证组件
Stars: ✭ 55 (+175%)
Mutual labels:  validator, validate
Validator.js
String validation
Stars: ✭ 18,842 (+94110%)
Mutual labels:  validator, validate
python-valid8
Yet another validation lib ;). Provides tools for general-purpose variable validation, function inputs/outputs validation as well as class fields validation. All entry points raise consistent ValidationError including all contextual details, with dynamic inheritance of ValueError/TypeError as appropriate.
Stars: ✭ 24 (+20%)
Mutual labels:  validator, validate
vayder
Easy and concise validations for Express routes
Stars: ✭ 26 (+30%)
Mutual labels:  validator, validate
FilterInputJs
Tiny and Powerful Library for limit an entry (text box,input) as number,string or more...
Stars: ✭ 37 (+85%)
Mutual labels:  validator, validate
checker
Golang parameter validation, which can replace go-playground/validator, includes ncluding Cross Field, Map, Slice and Array diving, provides readable,flexible, configurable validation.
Stars: ✭ 62 (+210%)
Mutual labels:  validator, validate
Validate
A simple jQuery plugin to validate forms.
Stars: ✭ 298 (+1390%)
Mutual labels:  validator, validate
Validate
⚔ Go package for data validation and filtering. support Map, Struct, Form data. Go通用的数据验证与过滤库,使用简单,内置大部分常用验证、过滤器,支持自定义验证器、自定义消息、字段翻译。
Stars: ✭ 378 (+1790%)
Mutual labels:  validator, validate
Nice Validator
Simple, smart and pleasant validation solution.
Stars: ✭ 587 (+2835%)
Mutual labels:  validator, validate
Validator.js
⁉️轻量级的 JavaScript 表单验证,字符串验证。没有依赖,支持 UMD ,~3kb。
Stars: ✭ 486 (+2330%)
Mutual labels:  validator, validate
Fast Xml Parser
Validate XML, Parse XML to JS/JSON and vise versa, or parse XML to Nimn rapidly without C/C++ based libraries and no callback
Stars: ✭ 1,021 (+5005%)
Mutual labels:  validator, validate
Fastest Validator
⚡️ The fastest JS validator library for NodeJS
Stars: ✭ 923 (+4515%)
Mutual labels:  validator, validate
Vee Validate
✅ Form Validation for Vue.js
Stars: ✭ 8,820 (+44000%)
Mutual labels:  validator, validate
ngx-translate-lint
Simple CLI tools for check `ngx-translate` keys
Stars: ✭ 25 (+25%)
Mutual labels:  validator
ATGValidator
iOS validation framework with form validation support
Stars: ✭ 51 (+155%)
Mutual labels:  validator
guice-validator
Guice javax.validation method validation integration
Stars: ✭ 35 (+75%)
Mutual labels:  validator
reach-schema
Functional schema-driven JavaScript object validation library.
Stars: ✭ 34 (+70%)
Mutual labels:  validate
hey-validator
Data validator
Stars: ✭ 14 (-30%)
Mutual labels:  validator
validation
Developer experience focused validator.
Stars: ✭ 15 (-25%)
Mutual labels:  validator
rust-phonenumber
Library for parsing, formatting and validating international phone numbers.
Stars: ✭ 99 (+395%)
Mutual labels:  validator

valite

Build Status

Concurrently execute your validators in a simple, practical and light validator engine.

Motivation

I spent some time looking for a validation module that was simple, practical and light. All I found were modules that promise simplicity, but deliver complex APIs; they promise lightness, but deliver very heavy dependencies; promise practicality, but deliver ready-made functions that do not meet our needs, and it is necessary to download new modules and configure messages to change language and validation behavior.

So I wrote valite, unlike all of them, it's just the core needed to build your validations. It is asynchronous by default, as everything should be in JavaScript, and has an extremely simple and concise API.

Install

valite is published under NPM registry, so you can install from any package manager.

npm install valite --save

# Use this command for Yarn.
yarn add valite

API

The API is composed by a validation function, validate, a validation object function validateObject and isValid which is a simple error checker.

Validator

Validators are functions that receives a value and returns a message or true.

const isName = (name) => Boolean(name.trim()) || 'Name shouldn\'t be empty.';

For TypeScript, valite exports Validator type to improve your code safety.

import { Validator } from 'valite';

const isName: Validator = (name: string) => Boolean(name.trim()) || 'Name shouldn\'t be empty.';

validate

Executes validators and returns first obtained message or null.

const mail = '[email protected]';

validate(mail, [
  (mail) => Boolean(mail.trim()) || 'Mail is required.',
  (mail) => /^.+@.+\..+$/.test(mail) || 'Mail is invalid',

  // You can use async validators.
  (mail) => (
    services.isMailRegistered(mail)
      .then((isRegistered) => isRegistered || 'Mail is already registered.')
      .catch(() => 'Can\'t even verify if mail is already registered.')
  )
]);
//=> Promise { 'E-Mail is already registered.' };

validateObject

Concurrently validates an object using validators from a schema and returns them in same structure.

Structure supports dot notation for deep properties.

const entries = {
  answer: document.querySelector('.answer').checked,
  user: {
    mail: document.querySelector('.mail').value,
    password: document.querySelector('.password').value,
  }
};

validateObject(entries, {
  'answer': [
    (answer) => Boolean(answer) || 'Terms should be accepted.',
  ],
  'user.mail': [
    (mail) => Boolean(value.trim()) || 'E-Mail is required.',
  ],
  'user.password': [
    (password) => Boolean(password.trim()) || 'Password is required.',
  ]
});
//=> Promise {{
//     'answer': null,
//     'user.mail': 'E-Mail is required',
//     'user.password': null
//   }}

isValid

Is a easy way to check if validate / validateObject payload has no errors.

const payload = await validateObject(/* ... */);

isValid(payload);
//=> true

License

Released under MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].