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

args-expect

v0.2.1

Published

An tiny tool to make sure all arguments are as expected.

Downloads

36

Readme

Runtime Argument Test

We are always check the arguments in every function, such as below:

function get(name) {
    if (!name || !name.length) {
        throw new Error('name is empty');
    }

    // code body
}

funtion set(config) {
    if (typeof config !== 'object') {
        throw new Error('config must be an object');
    }

    if (!config.prop1) {
        throw new Error('must provide config.prop1');
    }

    if (!typeof config.prop2 !== 'number') {
        throw new Error('config.prop2 must be a number');
    }

    // code body
}

These checks are annoying but indispensable.

This tool provide a unified assertion checking for your project, like below:

var expect = require('expect');
function get(name) {
    expect(name).isString().notEmpty();

    // code body
}

funtion set(config) {
    expect(config).isObject()
        .has('prop1')
        .has( { 'prop2' :  Number} );

    //code body
}

If any condition fail, it will throw error. (or any custom event).

The tool has very tiny size, and easily to use, especially in node.js .


How to Use

NodeJS: install via npm:

npm install args-expect

Browser:

copy lib/args-expect-min.js to your project folder

API List

  1. expect(obj).isElement();

  2. expect(obj).isObject()

  3. expect(obj).isArray()

  4. expect(obj).isFunction()

  5. expect(obj).isBoolean()

  6. expect(obj).isNull()

    • return true, if obj is null or undefined
  7. expect(obj).isEmpty()

    • check if obj is null or undefined, or is string / array but has zero length.
  8. expect(obj).notNull()

  9. expect(obj).notEmpty()

  10. expect(obj).toEqual( value )

  11. expect(obj).is( type [,...] )

    • check if obj is match any of incoming types.

        expect(obj).is( String, Object ) // expect the object is String or Object
        expect(obj).is( CustomizeClass ) // expect the object is instance of CustomizeClass
  12. expect(obj).has(propName)

    • check if obj is an Object and has all specified properties.

        expect(obj).has('key');
        expect(obj).has(['key', 'prop1']);
    • check if obj has all specified properties and match the given types.

        expect(obj).has({
                key: String,
                prop1: Number
           })

Check Multi Args

expect.all(1, 2, 3).isNumber();

use expect.all() to check multi arguments with one line


Error Report Method

The default report method will throw error.

We can use mode() to create new expect obj with new report method:

// create a new expect object with log report.
var expect = require('expect').mode('log');

expect('123').isString();
// if any condition fail, it will log warning message on console

Or use any custom event

// create a new expect object with alert report
var expect = require('expect').mode(function(msg) {
    alert(msg);
});

expect('123').isString(); // it will alert warning message.

Since mode() will create new expect instance, We can use disable() to disable all instance at one shot.

require('excpet').disable();

Get The Check Result

// disable the report mode
expect = expect.mode('none');
var result = expect(1).isString();

alert(expect.rejected);

use result.rejected to get the check result.


Module Standard Supported

This tool is support CommonJS, AMD, KMD, module standard.


Questions?

If you have any questions, please feel free to create new issue.