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

@yeasoft/parseutils

v1.1.1

Published

Utilities and express middleware for parsing parameters

Downloads

133

Readme

Utilities and express middleware for parsing parameters

This module contains some helper class and utilities for simplifying the task of parsing "parameters" both in express based applications as well as in other code parts.

The library may be added to any project with the following command:

# npm install @yeasoft/parseutils

NOTICE

Heavy work in progress. Most of the documentation is currently
only available in the corresponding .d.ts files

Learning by example

Since the module is in a very early stage, there is no real documentation. Here some examples:

A simple parser for Objects

const { ParamParser, HttpStatusError, resultHelper } = require( "@yeasoft/parseutils" );
const { getSpecifiedStr } = require( "@yeasoft/baseutils" );

function test( name, result, expect ) {
    if ( result.error instanceof Error ) {
        expect ? console.error( `${name} failed with error ${result.error.status}:`, result.error ) : console.log( `${name} passed with expected error ${result.error.status}: ${result.error.message}` );
    }
    else {
        expect ? console.log( `${name} passed:`, result ) : console.error( `${name} failed with unexpected result:`, result );
    }
}

const parser = new ParamParser( { errormode: 'param' } );

// add standard email address validator for parameters "from", "to", "cc" and "bcc
parser.setValidator( "from,to,cc,bcc", "email" );
// add your own validator for parameters "subject", "text" and "html"
parser.setValidator( "subject,text,html", ( params, property ) => {
    if ( typeof params[ property ] === 'string' ) {
        let subject = params[ property ].toLowerCase();
        if ( [ 'fuck', 'cunt', 'motherfucker' ].some( explicitWord => subject.indexOf( explicitWord ) != -1 ) ) {
            throw new HttpStatusError( "Mind your language", 451 );
        }
    }
} );
// add standard lowerize transformer for email fields
parser.setTransformer( "from,to,cc,bcc", "lower" );
// add your own transformer that makes sure you have a subject
parser.setTransformer( "subject", ( params, property ) => { params[ property ] = getSpecifiedStr( params[ property ], "No Subject" ); } );

// create a parser that returns all parameters but requires "from" to" and "subject" to be specified. "subject" will by autogenerated by the supplied tranformer.
const parseAll = parser.allParser( "from,to,subject" );
test( "Test 1", parseAll( {} ) );
test( "Test 2", parseAll( { from: "[email protected]", subject: "Yeah!" } ) );
test( "Test 3", parseAll( { from: "[email protected]", to: "Yeah!" } ) );
test( "Test 4", parseAll( { from: "[email protected]", to: "[email protected]", subject: "Fuck you!" } ) );
test( "Test 5", parseAll( { from: "[email protected]", to: "[email protected]" } ), true );

// create a parser that returns onöy the specified parameters but requires "from" and "to" to be specified.
const parseOnly = parser.onlyParser( "from!,to!,cc,bcc,subject" );
test( "Test 6", parseOnly( {} ) );
test( "Test 7", parseOnly( { from: "[email protected]", subject: "Yeah!" } ) );
test( "Test 8", parseOnly( { from: "[email protected]", to: "Yeah!" } ) );
test( "Test 9", parseOnly( { from: "[email protected]", to: "[email protected]", subject: "Fuck you!" } ) );
test( "Test 10", parseOnly( { from: "[email protected]", to: "[email protected]" } ), true );

A simple parser for express

See how simple it is to implement a web api:

const { ParamParser, HttpStatusError } = require( "@yeasoft/parseutils" );
const { getSpecifiedStr } = require( "@yeasoft/baseutils" );

const emailParser = new ParamParser( { methods: "GET,POST", errormode: 'exception' } );

// add standard email address validator for parameters "from", "to", "cc" and "bcc
parser.setValidator( "from,to,cc,bcc", "email" );
// add your own validator
parser.setValidator( "subject,text,html", ( params, property ) => {
    if ( typeof params[ property ] === 'string' ) {
        let subject = params[ property ].toLowerCase();
        if ( [ 'fuck', 'cunt', 'motherfucker' ].some( explicitWord => subject.indexOf( explicitWord ) != -1 ) ) {
            throw new HttpStatusError( "Mind your language", 451 );
        }
    }
} );
// add standard lowerize transformer for email fields
parser.setTransformer( "from,to,cc,bcc", "lower" );
// add your own transformer that makes sure you have a subject
parser.setTransformer( "subject", ( params, property ) => { params[ property ] = getSpecifiedStr( params[ property ], "No Subject" ); } );



// register routes for sending mails
httpd.all( [ 'api/send/:from/:to/:subject', 'api/send' ], parser.only(), ( req, res ) => {
    // you do have to care on parameter errors -> the parser throws an exception and everything is done by express

    // regardless of the method and way of passing the parameters (url, query params, body): everything is in req.params
    sendMyMail( req.params, ( error, result ) => {
        resultHelper.handle( req, res, error, result, 200 );
    } );
} );