PHP>> v4f>> 返回
项目作者: web-pyjs

项目描述 :
:heavy_check_mark:4F | A declarative , efficient, and flexible javaScript validation library for Humans.
高级语言: JavaScript
项目地址: git://github.com/web-pyjs/v4f.git
创建时间: 2019-01-14T14:54:09Z
项目社区:https://github.com/web-pyjs/v4f

开源协议:MIT License

下载








undefined









undefined


undefined

Documentation | Exemples | API Reference | Need help ?

Description

A javascript library for validation that encourages rapid development and clean code, unlike other validation libraries v4f is designed from the ground up to be adaptable for any context, and it takes care of all your validation in different environments (client, server, native).

You can use V4f together with (react.js, angular.js, vue.js, jquery) or with any web framework.

Why

why new validation library where they exist several good ones around, sure you are completely right. but the problem with those libraries is that almost all of the theme focus in data validation and they forget the key reason why we do validation for, is that we desire to guide our users by showing them what they missing or what they doing wrong with some pieces of information, but sadly you end up with generic messages errors or writing code on the top of this libraries every time you use them.

V4F comes to solve this problem by focusing on those two features validations and failures messages, V4F comes with easy and powerful syntax that feels more human that everyone can understand with more than 40+ built-in rules.

Out of the box

  • Schema : v4f use the concept of the schema types to indicate your rules that will be checked later were we need it, this notion is powerful it lets you create complex rules ones and use it multiple types.

  • Nested schema : with v4f you can use a schema that already created inside other schemas to create complex validation.

  • Related field : validate fields that related or depends on each other easily with a simple syntax.

  • Single field : Validate only one field from schema very useful in situations like instead field validation feedback.

  • Async-sync : Validate your schema in asynchronous or synchronous way.

Getting started

Syntax overview

  1. import { Schema, Field } from "v4f";
  2. const User = Schema({
  3. username: Field()
  4. .string()
  5. .alphaNum()
  6. .required(),
  7. email: Field()
  8. .string()
  9. .email()
  10. .required(),
  11. password: Field()
  12. .string()
  13. .min(6)
  14. .max(20)
  15. .not.equals(["#username"])
  16. .not.equals(["#email"])
  17. .required(),
  18. cPassword: Field()
  19. .string()
  20. .equals(["#password"])
  21. .required()
  22. });
  23. const result = User.validate(data);

The above schema defines the following constraints:

  • username :
    • Must be string
    • Must be alpha numeric
    • Required
  • email :
    • Must be string
    • Must be valid email
    • Required
  • password :
    • Must be string
    • At least 6 characters long but no more than 20
    • Must not be equals to username and email
    • Required
  • cPassword :
    • Must be string
    • Must equals to password
    • Required

Instalation

To install the stable version:

  1. $ npm install v4f

This assumes you are using npm as your package manager.

or

  1. $ yarn add v4f

If you you use yarn as package your package manager.

Usage

Commonjs

  1. var v4f = required("v4f");
  2. const User = v4f.Schema({// Your schema here});

ES6

  1. import {Schema, Field} from "v4f";
  2. const User = Schema({// Your schema here});

Read the Usage Guide on our website for detailed instructions on how to use the library.

Rule Reference

In general, we follow the “fork-and-pull” Git workflow.

  1. Fork on GitHub
  2. Make changes to your own fork
  3. Submit a Pull request so that we can review your changes

Test

  1. $ yarn test

Linter

  1. $ yarn lint

Maintainers

  • reyx7 - Nassih Soufiane (author)

License (MIT)

  1. MIT License
  2. Copyright (c) 2019 soufiane nassih soufiane.nass7@gmail.com
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in all
  10. copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  17. SOFTWARE.