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 🙏

© 2024 – Pkg Stats / Ryan Hefner

cert-is

v1.0.2

Published

Provides a collection of runtime assertion tools for checking strict equality, type, and range of a set of values.

Downloads

79

Readme

cert-is

Provides a collection of assertion tools for checking strict equality, type, and range of a set of values.

This project aims to simplify runtime value checking for safety-critical applications.

NPM

NPM NPM NPM NPM NPM NPM

Migration Notice 0.2.1 --> 1.0.0:

  • Certifier.isRange and Checker.isRange have been removed.
  • Exports are now structured as follows:
export declare function cert(...values: any): Certifier
export declare function check(...values: any): Checker
export {
  Certifier,
  Checker,
  RangeArgumentError,
  RangeAssertionError,
  TypeArgumentError,
  TypeAssertionError,
  ValueArgumentError,
  ValueAssertionError
};
export default cert;
  • Project has been converted to TypeScript

Update 1.0.0:

  • This library has been converted to TypeScript, but development will likely stop here.
  • Please check out jpcx/restrict-v instead.

Installation

yarn add cert-is

Testing

cd /path/to/node_modules/cert-is
yarn install -dev
yarn test

Contribution

Please raise an issue if you find any. Pull requests are welcome!

Documentation

Module: cert-is

Index

Classes
Type aliases
Functions

Type aliases

AnyConstructorFunction

Ƭ AnyConstructorFunction: object

Defined in src/certifier.ts:16

Any function that uses new to construct an object.

Type declaration:

Functions

cert

cert(...values: any): Certifier

Defined in src/index.ts:59

Constructs a Certifier instance given a set of values. All values must pass the supplied tests.

func cert

example

const certifier = cert('foo', 'bar')
certifier.is('foo') // undefined
certifier.is('bar') // undefined
certifier.is('qux') // THROWS ValueAssertionError

example

cert('foo').is('foo')                      // returns Certifier instance
cert('foo').is('bar')                      // THROWS ValueAssertionError
cert('foo').is('foo', 'bar')               // returns Certifier instance
cert('foo').isNot('foo')                   // THROWS ValueAssertionError
cert('foo').isType('string')               // returns Certifier instance
cert('foo').isType('number')               // THROWS TypeAssertionError
cert('foo').isType('string', 'number')     // returns Certifier instance
cert(new Map()).isType(Map)                // returns Certifier instance
cert(new Map()).isType(Object)             // returns Certifier instance
cert(new Map()).isType(Set)                // THROWS TypeAssertionError
cert(new Map()).isType(Map, Set)           // returns Certifier instance
cert(15).isGT(2)                           // returns Certifier instance
cert(15).isGT(2).isLT(17)                  // returns Certifier instance
cert(18).isGT(17).isLT(2)                  // THROWS RangeAssertionError
cert(15).isGT(15)                          // THROWS RangeAssertionError
cert(15).isGTE(15)                         // returns Certifier instance
cert(15, 23).isGTE(15)                     // returns Certifier instance
cert(15, 23).isGTE('foo')                  // THROWS TypeArgumentError

Parameters:

Name | Type | Description | ------ | ------ | ------ | ...values | any | Values to construct Certifier with. |

Returns: Certifier

Certifier instance.


check

check(...values: any): Checker

Defined in src/index.ts:80

Constructs a Checker instance given a set of values. All values must pass the supplied tests.

func check

example

check('foo').is('foo')        // returns true
check('foo').is('bar')        // returns Checker instance
check('foo').isType('string') // returns true
check('foo').isType('bar')    // THROWS TypeArgumentError
check('foo').isGT('')         // THROWS TypeArgumentError

Parameters:

Name | Type | Description | ------ | ------ | ------ | ...values | any | Values to construct Checker with. |

Returns: Checker

Checker instance.

License

This project is licensed under the MIT License - see the LICENSE file for details