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-input-regex-filter

v1.3.0

Published

filter data which from user side use regex, and returns a result data whose format is declared by coder.

Readme

egg-input-regex-filter

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Install 安装

$ npm i egg-input-regex-filter --save

Usage 启用

// {app_root}/config/plugin.js
exports.inputRegexFilter = {
  enable: true,
  package: 'egg-input-regex-filter',
};

Configuration 配置

// {app_root}/config/config.default.js
exports.inputRegexFilter = {
};

see config/config.default.js for more detail.

Example 例子

/**
 * use this plugin in egg.js,  this plugin map its func to both app and ctx
 * ,so you can use it like this: 
 * app/ctx.filterReg(dataObj, regexObj, quickRtn = true, rtnFn = null) , 
 * app/ctx.jsonRtn(code, data = {}, errMsg = '', okCode = 0 ), 
 * app/ctx.errRtn(errMsgObj )
 * 
 * use in controller/service , see below: 
 * 在eggjs中的使用方法: 
 */

var postDataObject = {
    "username": "xiaoming",
    "password": "12345678",
    "nickname": "apples"
}
//postDtaObj = this.ctx.request.body 

//if filter defined a field ,but it was not be seted in dataObj 
//it will be seted automaticly by filter , default value is '' 
filterObject  = {
    username: [
        {re:/^\w{5,15}$/, errCode: -1, errMsg: 'length must between 5 to 15'},
        {re:/^[a-zA-Z]+\w*$/, errCode: -1, errMsg: 'must starts  with char'},
    ],
    "password": [{re:/^\w{5,15}$/, errCode: -1, errMsg: 'length must between 5 to 15'},],
    //we will not check nickname field 
    //"nickname": [{re:/^\w{5,15}$/, errCode: -1, errMsg: 'length must between 5 to 15'},]
}

//fRtn is an obj has two attr , retData and err
let fRtn = this.app.filterReg(postDataObject, filterObject )

//so you can do it like this 
if(JSON.stringify(fRtn.err ) != "{}" ){     //fRtn.err not empty
    var errMsgJson = this.app.errRtn(fRtn.err )
    this.ctx.body = errMsgJson 
    return 
}
//if you also is a phper , you can use phpjs through: const pfn = require("phpjs") 
//it has many powerful funcs ,you will like it. above "if" can be write as:
// if(!pfn.empty(fRtn.err ) ) 

/**
    that's all above . if you like it has an extra method named jsonRtn()
    look as this :  jsonRtn(code, data = {}, errMsg = '', okCode = 0 )
    if code not eq okCode ,errMsg must be  defined , and the param data must be always an Object
    you can set it as {} if you do not want to set it anything. 
    normal return is : {code: int, data:{some data object here} }
    when err return param errMsg will be seted in data ,like this: 
    {code: int, data:{some data object here, errMsg: 'some err info'} }
    call it like this:  this.ctx.body = this.app.jsonRtn(-1, {}, 'some err happened' ) 
    
    attention: all the method above called by this.app  ,  also can be call by this.ctx 
enjoy!
*/

Questions & Suggestions

Please open an issue here.

License

MIT