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 🙏

© 2026 – Pkg Stats / Ryan Hefner

egg-myvalidate

v1.0.1

Published

egg验证

Readme

egg-myvalidate

依赖说明

  • 无任何依赖,放心使用

安装配置

$ npm i egg-myvalidate -S
// config/plugin.js

exports.myvalidate = {
  enable: true,
  package: 'egg-myvalidate',
};

// 无需任何配置文件

使用场景

  • 使用egg开发web应用,参数验证,中文描述
  • 支持验证类型 'int','number','string','bool','boolean','date','array','object','email','phone',
  • myvalidate函数挂载在ctx上,可直接使用
  • 如何required:false,则allowNull:false失效

格式

ctx.myvalidate('验证规则',"待验证数据")

举例


const validate = await ctx.myvalidate({
  id:{
    type:'number',
    allowNull:false,
    required:false
  }
},ctx.request.body)

// validate示例值
{
  err: true,
  msg: { name: 'id', msg: '字段不允许为空', message: 'id字段定义非空,传入null' },
  message: [ { name: 'id', msg: '字段不允许为空', message: 'id字段定义非空,传入null' } ]
}
{ err: false, msg: '验证成功', message: '参数全部验证通过' }

重点

  • allowNull:false 可以在 type类型前面加 !代替 如
  const validate = await ctx.myvalidate({
    id:{
      type:'!number',
      required:false
    }
  },ctx.request.body)
// 同上面示例代码
  • allowNull:true 可以在 type类型前面加 ? 代替 如
  const validate = await ctx.myvalidate({
    id:{
      type:'?number',
      required:false
    }
  },ctx.request.body)
// 同
  const validate = await ctx.myvalidate({
    id:{
      type:'number',
      allowNull:true
      required:false
    }
  },ctx.request.body)
  • required:false 可以用 type类型后面加 ?代替 如
  const validate = await ctx.myvalidate({
    id:{
      type:'!number?',
    }
  },ctx.request.body)
// 同上面示例代码
  • required:true 可以用 type类型后面加 !代替 如
  const validate = await ctx.myvalidate({
    id:{
      type:'!number!',
    }
  },ctx.request.body)
// 同
  const validate = await ctx.myvalidate({
    id:{
      type:'!number',
      required:true
    }
  },ctx.request.body)
  • 待验证数据默认值是 ctx.request.body;
  const validate = await ctx.myvalidate({
    id:{
      type:'!number?',
    }
  })
// 同上面示例代码

License

MIT