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

formng

v0.0.2

Published

Express form new generation validator

Downloads

22

Readme

Express Form New Generation

UNDER HARD DEVELOPMENT, NOT PRODUCTION READY

It need tests. I can't say that it's stable

What filters/validators are available?

I'm not dividing on filters and validators...for me it's called rules If rule modifies variable content it starts from to, remove, parse or something else as we say in everyday life If rules validating variable contents it starts from is At now this rules are available:

  call - { call: { func: function(field. fieldName, opts){} }}
  required
  parseJson
  removeIfEmpty - Will remove [], {}, '', null, false, undefined ...
  isString
  nl2br
  match - { match: { regexp: /exp/, message: '' } }
  trim
  isArray
  toFloat
  isObject
  entityDecode
  entityEncode
  toInt
  toArray
  $childs
  $each

How to define the rules?

It's simple. I guess example will say more than i can:

  var formng = require('formng')
    , body = {
        id: '15',
        foo: ' <script> alert(1); </script><h1>some &nbsp; HTML</h1>     ',
        bar: '  ',
        baz: 'abc'
      }

  var form = formng({
    id: [ 'removeIfEmpty', parseInt ], // Here we call some rule and builtin js function `parseInt`
    foo: [ 'trim', 'required', 'entityEncode' ],
    bar: [ 'trim', 'required' ], // Will call next(new Error()) because `bar` was trimmed and empty now
    baz: [ function(field, fieldName, opts){
      return field + 'def';
    }, /^abcdef$/ ], // Here i have defined custom function, that concats `baz` value with 'def' string, after tests whether the `baz` matching /^abcdef$/ regexp 

    // Rules with options
    faz: {
      match: { reqexp: /^a.+/, message: '%s not matching regexp' }
    }

    // We can also validate nested json, but this technics not optimized yet...if you interested in that - look into the code or feel free to contact with me

  });


  app.get('/', function(req, res, next){
    // Here we will set `req.body`
    req.body = body;
    next();
  }, form, function(req, res, next){
    res.send('Passed') // You will not see this without modifying `body`...play with it :)
  });

Custom functions

It can be any function that expects value as first arg and returns value Or function like this:

  function(fieldValue, fieldName, optsPassed) {
    return 'some string to set new value'
    return false // to throw an error
    return null // to remove field from req.body
    // or return nothing(undefined) to save the value
  }

Errors:

It tryes to find .message attr in rule attributes(if presented, if not - default will be used)o If using custom validation function...we can just add message to opts object All errors passing to the next(new Error('message')) Formng will finish checking and redirect user to error route on first error found.

Rules return values and meanings:

return false - validation error. return undefined - do not modify the field, that rule was validation rule< not filter return null - delete field from body

Everything excepts all above will modify field value If false|undefined|null value is needed this function will help you(just pass it as a rule):

    function(field, fieldName, opts){
        this.set(fieldName, null/* false or undefined */)
    }

And...oh...you can manualy write rules. See node_modules/formng/rules