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

miniprogram-validator

v1.0.0

Published

基于 WxValidate - 表单验证 的微信小程序表单校验工具

Downloads

6

Readme

miniprogram-validator

基于 WxValidate - 表单验证 扩展的微信小程序表单验证器,规则配置可参考其文档。

配置规则格式参考 ElementUI 使用的async-validator(仅参考其格式)

表单校验的方案:

  • 后端校验:无论前端是否校验,数据入库前都需要进行校验
  • 前端校验:如果需要提升用户体验或者减少请求次数的情况下,前端需要数据校验。如果应用的要求不高,可以免去前端校验

使用示例

将两个文件拷贝到文件夹下

libs/
    validator.js
    WxValidate.js
const Validator = require('./validator.js');

// 需要校验的数据
let data = {
  name: 'Tom',
  age: 10,
  school: 'A',
};

// 校验规则 {field: rules}
let rules = {
  name: [{ message: '姓名不能为空', required: true }],
  age: [
    { message: '年龄不能为空', required: true },
    { message: '年龄不能大于10', max: 10 },
  ],
  school: [
    {
      message: '学校只能是A/B',
      validator: (value, param) => {
        return !value || (value && ['A', 'B'].includes(value));
      },
    },
  ],
};

let validator = new Validator(rules);
let error = validator.validate(data);

if (error) {
  console.log('校验出错');
  console.log(error);
} else {
  console.log('校验通过');
}

完整代码: https://github.com/mouday/miniprogram-validator