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 🙏

© 2025 – Pkg Stats / Ryan Hefner

validate_y

v2.2.0

Published

sketchy form validator

Readme

导出3个函数

  1. validate: 按传入参数顺序验证,验证失败后停止,触发当前失败元素的回调函数
  2. validateAll: 验证所有参数,通过error函数返回失败参数的key
  3. pattern: 可以访问内置的正则。

参数解释

  1. validate: validate(validates, success)
  • validates为需验证元素的数组,数组元素为对象格式
  validates = [
    {
      requirement: '',   (可传入内置正则字段,也可传入自定义验证'函数')
      value: '',         (验证参数值)
      cb: () => {        (该元素验证失败的回调函数)
        console.log('你的操作');
      }
    }
  ]
  • success: 全部元素认证通过后的成功回调

  1. validateAll: validateAll(validates, error, success)
  • validates为需验证元素的数组,数组元素为对象格式
  validates = [
    {
      requirement: '',  (可传入内置正则字段,也可传入自定义验证'函数')
      key: '',          (验证参数key值)
      value: '',        (验证参数值)
    }
  ]
  • error: 验证失败的回调函数,参数为失败元素key值的数组合集
  • success: 验证成功的回调函数

内置正则参数

['userName', 'phone', 'password', 'strongPsd', 'id', 'ChineseName', 'email', 'qq', 'wechat', 'carTag', 'notBlank', 'integer', 'positiveInteger', 'negtiveInetger', 'number', 'positiveNumber', 'negtiveNumber', 'ifFn']

  1. userName: 用户名(4到16位,字母,数字,下划线,减号)
  2. phone: 手机号(至2018年4月)
  3. password: 密码(6~18位英文或数字组合)
  4. strongPsd: 密码强度(最少6位,包括至少1个大写字母,1个小写字母,1个数字,1个特殊字符)
  5. id: 身份证
  6. ChineseName: 中文名(不允许有特殊字符、数字和英文)
  7. email: 邮件
  8. qq: qq
  9. wechat: 微信(6至20位,以字母开头,字母,数字,减号,下划线)
  10. carTag: 车牌号
  11. notBlank: 非空
  12. integer: 整数
  13. positiveInteger: 正整数
  14. negtiveInetger: 负整数
  15. number: 数字
  16. positiveNumber: 正整
  17. negtiveNumber: 负数
  18. ifFn: javascript函数

内置正则参数

  import { validate, validateAll, pattern } from 'validate_y'
  // 1. 按data顺续验证
  const data = [
                  {
                    requirement: 'notBlank',
                    value: this.name,
                    cb: () => {
                      // 失败回调
                    }
                  },
                  {
                    requirement: 'positiveNumber',
                    value: this.amount,
                    cb: () => {
                      // 失败回调
                    }
                  },
                  {
                    requirement: 'notBlank',
                    value: this.date,
                    cb: () => {
                      // 失败回调
                    }
                  },
                  {
                    requirement: 'notBlank',
                    value: this.notes,
                    cb: () => {
                      // 失败回调
                    }
                  },
                  {
                    requirement: 'notBlank',
                    value: this.picBase64,
                    cb: () => {
                      // 失败回调
                    }
                  }
                ]
  validate(data, () => {
    // 成功回调
    console.log('success');
  })

  // 2. 全部验证后,返回失败字段
  const data = [
                  {
                    requirement: 'notBlank',
                    value: this.name,
                    key: '自己定义的识别值'
                  },
                  {
                    requirement: 'positiveNumber',
                    value: this.amount,
                    key: '自己定义的识别值'
                  },
                  {
                    requirement: 'notBlank',
                    value: this.date,
                    key: '自己定义的识别值'
                  },
                  {
                    requirement: 'notBlank',
                    value: this.notes,
                    key: '自己定义的识别值'
                  },
                  {
                    requirement: 'notBlank',
                    value: this.picBase64,
                    key: '自己定义的识别值'
                  }
                ]
  validateAll(data, (keys) => {
    // 失败回调
    // keys为失败元素的数组
  }, () => {
    // 成功回调
  });