Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Small package that leverages the power of ES6 Proxy to validate and sanitize objects.

License

NotificationsYou must be signed in to change notification settings

sorodrigo/proxy-validator

Repository files navigation

Build Status

proxy-validator

Small package that leverages the power of ES6 Proxy to validate and sanitize objects.

Learn More, read the article:

How I made a validation library using ES6 Proxy

Installation

$ npm i proxy-validator

Usage

The API is fairly simple. Create a validator by providing a validation schema and/or a sanitizing schema.

importProxyValidatorfrom'proxy-validator';// The schema props correspond to the props that will be validated.constvalidators={// Define a set of rules to apply for each prop, each rule is formed by a key and a value.name:{// The key corresponds to a validator function.isLength:{// The value can be either an object, containing options and an errorMessage...options:{min:6},errorMessage:'Minimum length 6 characters.'},// ...or a boolean, in which case the message will be the default one.isUppercase:true},mobile:{isMobilePhone:{options:'en-GB',errorMessage:'Invalid mobile number.'},isAlphanumeric:true}};constsanitizers={// As with the validation, the sanitizing schema is formed by a a key/value pair.name:{// The key corresponds with the sanitizing functiontrim:true// and the value can be either boolean (use defaults)},email:{normalizeEmail:{options:{// ...or a config options object.all_lowercase:true}}}};// Creates a validatorconstContactValidator=ProxyValidator(validators,sanitizers);// Creates a proxy that will enforce the validator rules.constcontact=ContactValidator();contact.name='Mike';// throws errorscontact.name=' MICHAEL';console.log(contact);// { name: 'MICHAEL' };

Validators

The validation is based on the amazing libvalidator bychriso. Find the complete list of available validators and sanitizers inhere.

About

Small package that leverages the power of ES6 Proxy to validate and sanitize objects.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors2

  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp