V4f
:heavy_check_mark:4F | A declarative , efficient, and flexible javaScript validation library for Humans.
Install / Use
/learn @nsoufian/V4fREADME
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
import { Schema, Field } from "v4f";
const User = Schema({
username: Field()
.string()
.alphaNum()
.required(),
email: Field()
.string()
.email()
.required(),
password: Field()
.string()
.min(6)
.max(20)
.not.equals(["#username"])
.not.equals(["#email"])
.required(),
cPassword: Field()
.string()
.equals(["#password"])
.required()
});
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:
$ npm install v4f
This assumes you are using npm as your package manager.
or
$ yarn add v4f
If you you use yarn as package your package manager.
Usage
Commonjs
var v4f = required("v4f");
const User = v4f.Schema({// Your schema here});
ES6
import {Schema, Field} from "v4f";
const User = Schema({// Your schema here});
Read the Usage Guide on our website for detailed instructions on how to use the library.
Rule Reference
- [X] Generic
- [X] String
- [X] Number
- [X] less
- [X] lessOrEquals
- [X] greater
- [X] greaterOrEquals
- [X] positive
- [X] negative
- [X] between
- [X] betweenOrEquals
- [X] Boolean
- [X] Array
- [X] Object
- [X] Iterator
- [X] lengthEquals
- [X] lengthLess
- [X] lengthLessOrEquals
- [X] max
- [X] lengthGreater
- [X] lengthGreaterOrEquals
- [X] min
- [X] lengthBetween
- [X] lengthBetweenOrEquals
- [ ] Date
Contributing
In general, we follow the "fork-and-pull" Git workflow.
- Fork on GitHub
- Make changes to your own fork
- Submit a Pull request so that we can review your changes
Test
$ yarn test
Linter
$ yarn lint
Maintainers
- reyx7 - Nassih Soufiane (author)
License (MIT)
MIT License
Copyright (c) 2019 soufiane nassih soufiane.nass7@gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the follow
Related Skills
node-connect
346.8kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
107.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
346.8kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
346.8kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
