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

data-gate

v0.0.8

Published

valid input data for node and browser,验证输入数据适用于Node和浏览器

Readme

datagate

主要用于验证数据格式是否正确,用于数据安全验证,node端,Browser端可以共享配置文件,最大限度的减少工作量

INSTALL

NODEJS

npm install data-gate

BROWER

<script type="text/javascript" src="index.js"></script>

API

var gate = gate(xx);
@param object 获取信息的配置文件
@param object node环境下的req对象,用于自动获取 req.body的内容

regexp

添加一个正则验证规则
@param string/object
@param RegExp

gate.regexp('int',/^[0-9]+$/)
gate.regexp({int:/^[0-9]+$/})

check

触发检测操作

gate.check();

getData

获取最后获得数据

gate.getData() // {username:'xxx',password:'123456'}

getErr

获取错误提示

gate.getErr() //['用户名错误','密码必须要6-20位']

OPTIONS

name:'username',//返回的数据键值,不填则使用id    
id:'username',//要过滤的值,浏览器时可以是元素ID,
			//直接 document.getElementById('xx').value()    
regexp:'username',//预设的正则表达式名    
required:true,//是否为必填,默认false,如果非必填则为空时不进行regexp的监测    
alias:'用户名必填', //为空时提示    
err:'用户名格式错误' //格式错误时提示    
value:"值" // 当nodejs环境的时候需要提供要检测的内容 value /id,共存时取value值 
		   //node 环境下id value均可为undefined 此时自动根据name属性在req.body中取值   
equal:"password" // 必须保证当前字段的值与 name为 password的值相等,如果不相等则提示err错误信息  
eg:    

var a = [    
    {    
    	name:'username',//返回的数据键值,不填则使用id    
    	id:'username',//要过滤的值,浏览器时可以是元素ID,直接 document.getElementById('xx').value();    
        regexp:'username',//预设的正则表达式名    
        required:true,//是否为必填,默认false,如果非必填则为空时不进行regexp的监测    
        alias:'用户名必填', //为空时提示    
        err:'用户名格式错误', //格式错误时提示    
        value:"值", // 当nodejs环境的时候需要提供要检测的内容 value /id必填其一,共存时取value值  
        equal:"password" // 必须保证当前字段的值与 name为 password的值相等,如果不相等则提示err错误信息  
    },    
    {    
        name:'password',    
        id:"password1",    
        regexp:'password',    
        required:true,    
        alias:'密码必填',    
        err:'密码请填写6-20位'    
    },    
    {    
        regexp:'email',    
        id:"email"    
    }    

];    

预设规则

*email* 邮箱     
*ip* IP   
*digit* 数字    
*url* URL   
*username* : /^[a-z0-9_-]{3,15}$/  用户名    
*password* :  /.{6,20}/ 密码    
*phone* : /^1[0-9]{10}$/ 电话    

更多规则

单个字符串的处理

Notice:  is系列函数 可以指定一个参数 也可以使用gate参数  gate(1).isInt() === gate().isInt(1)

isType

@param int/string
@param string/RegExp
是否符合某个正则条件

isInt

@param int/string
是否是整形

isEmail

@param int/string
是否是邮箱

isPhone

@param int/string
是否是手机号码

isUrl

@param int/string
是否是一个url连接