npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

como-validator

v1.0.5

Published

表单验证包

Downloads

14

Readme

表单验证包

安装

	npm install como-validator

使用

const {comoRules,validate} = require('como-validator');

let data = {uname:'szjcomo',age:18,gender:'男'};
let rules = {
	uname:comoRules.getInstance().name('用户名').required().notEmpty().trim().chinese(),
	age:comoRules.getInstance().name('年龄').required().number().min(10).max(20),
	gender:comoRules.getInstance().name('年龄').required().in_array(['男','女']),
	education:comoRules.getInstance().name('学历').default('本科').required()
};
validate(rules,data).then((res) => {
	console.log('正确的值:',res);
}).catch((err) => {
	console.log('错误信息:',err.message);
})

示例

let rule = {
	username:comoRules.getInstance().name('用户名称').required().notEmpty().trim()
	// username:comoRules.getInstance().name('用户名').required().min_length(2).max_length(20).chinese(),
	// password:comoRules.getInstance().name('密码').required().min_length(6).max_length(20).letter_number(),
	// sex:comoRules.getInstance().name('性别').in_array(['男','女']),
	// extends:comoRules.getInstance().name('扩展信息').required().isJson(),
	// born:comoRules.getInstance().name('出生日期').required().date(),
	// password1:comoRules.getInstance().required().ref('password','两次密码必须一致'),
	// idcard:comoRules.getInstance().id_card('身份证号码错误'),
	// email:comoRules.getInstance().email('邮箱格式错误'),
	// qq:comoRules.getInstance().qq('qq号码错误').number(),
	// login_ip:comoRules.getInstance().ip('ip地址格式错误'),
	// phone:comoRules.getInstance().phone('手机号码错误'),
	// web_url:comoRules.getInstance().name('网站地址').required().url(),
	// info:comoRules.getInstance().name('详情').object(),
	// nickname:comoRules.getInstance().name('呢称').letter(),
	// datetest:comoRules.getInstance().name('测试数字和字母').required().letter_number(),
	// age:comoRules.getInstance().name('年龄').min(6).max(13),
}

let data = {
	password:'xxxx',sex:'男',extends:'xxx',born:'2017-01-01',
	password1:'xxx',idcard:'xxx',email:'[email protected]',qq:'123456',
	login_ip:'127.0.0.1',phone:'xxx',web_url:'http://www.baidu.com',info:{name:'hello'},
	nickname:'abcd',datetest:'ab123c',age:7,username:'szjcomo'
};

const valid = async function(rule,data) {
	try {
		let res = await validate(rule,data);
		console.log(res);
	} catch(err) {
		console.log(err.message)
	}
}

valid(rule,data);

更新日志

2021年1月14日

  • 增加了去空函数,增加了别名函数

2021年1月25日

  • 增加了isJson函数 is_json函数