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

assertive.js

v0.0.1

Published

Assertion library for Node.js

Downloads

3

Readme

Assertive.js

Assertion library for Node.js

Installation

    npm install assertive.js

Basic usage

    let assert = require("assertive.js");

    assert.that("Some random string").is("String");

API

that(target)

Sets the target of the assertion.

    assert.that("String");

isEqualTo(element)

Deep, coercive equality between the actual and expected parameters using the Abstract Equality Comparison ( === ). Based on node's Assert.deepStrictEqual.

    assert.that("String").isEqualTo("String");        // ==> true
    assert.that("Something").isEqualTo("different");  // ==> false

isNotEqualTo(element)

Negation of isEqualTo.

    assert.that("String").isNotEqualTo("Something different");  // ==> true
    assert.that("String").isNotEqualTo("String");               // ==> false

isSimilarTo(element)

Deep, coercive equality between the actual and expected parameters using the Abstract Equality Comparison ( == ). Based on node's Assert.deepEqual.

    assert.that(1).isSimilarTo("1");                             // ==> true
    assert.that({ a: { b: 1 } }).isSimilarTo({ a: { b: 2 } });   // ==> false

isNotSimilarTo(element)

Negation of isSimilarTo.

    assert.that({ a: { b: 1 } }).isNotSimilarTo({ a: { b: 2 } });  // ==> true
    assert.that({ a: { b: 1 } }).isNotSimilarTo({ a: { b: 1 } });  // ==> false

is(type)

Asserts that the target is of a specific type.

    assert.that("String").is("String");  // ==> true
    assert.that("String").is("Number");  // ==> false

Type is NOT case sensistive.

Available types
  • Array
  • ArrayBuffer
  • Boolean
  • DataView
  • Error
  • Float
  • Function
  • GeneratorFunction
  • Int
  • Map
  • Null
  • Number
  • Object
  • Promise
  • RegExp
  • Set
  • String
  • Symbol
  • Uint
  • Undefined
  • WeakMap
  • WeakSet

isNot(type)

Negation of is.

    assert.that("String").isNot("Number");  // ==> true
    assert.that("String").isNot("String");  // ==> false

throws(error)

Based on node's Assert.throws.

    let block = () => {
        throw new TypeError;
    }

    assert.that(block).throws(TypeError);   // ==> true
    assert.that(block).throws(Error);       // ==> false

isLargerThan(number)

Asserts that the target is larger than number.

    assert.that(10).isLargerThan(5);   // ==> true
    assert.that(10).isLargerThan(10);  // ==> false

isLargerOrEqualTo(number)

Asserts that the target is larger or equal to number.

    assert.that(10).isLargerOrEqualTo(5);   // ==> true
    assert.that(10).isLargerOrEqualTo(10);  // ==> true

isSmallerThan(number)

Asserts that the target is smaller than number.

    assert.that(7).isSmallerThan(10);   // ==> true
    assert.that(7).isSmallerThan(7);    // ==> false

isSmallerOrEqualTo(number)

Asserts that the target is Smaller or equal to number.

    assert.that(7).isSmallerOrEqualTo(10);   // ==> true
    assert.that(7).isSmallerOrEqualTo(7);    // ==> true

$errors

Return an array with the error objects of the errors occoured in the assertions.

    assert.that(20).isSmallerOrEqualTo(10);   // ==> false

    console.log(assert.$errors);
    // [ [AssertionError] ]

Native NodeJS Assert API

If you rather use the built in Assert API, you still can. The assertion library wraps the built in API, so you can use it as you normally would. Check out Node's Assert Documentation for more information and examples.

Methods

  • deepEqual(actual, expected, message)
  • deepStrictEqual(actual, expected, message)
  • doesNotThrow(block, error, message)
  • equal(actual, expected, message)
  • fail(message)
  • fail(actual, expected, message, operator, stackStartFunction)
  • ifError(value)
  • notDeepEqual(actual, expected, message)
  • notDeepStrictEqual(actual, expected, message)
  • notEqual(actual, expected, message)
  • notStrictEqual(actual, expected, message)
  • ok(value, message)
  • strictEqual(actual, expected, message)
  • throws(block, error, message)
Usage
    assert.deepEqual(actual, expected, message)
    assert.deepStrictEqual(actual, expected, message)
    assert.doesNotThrow(block, error, message)
    assert.equal(actual, expected, message)
    assert.fail(message)
    assert.fail(actual, expected, message, operator, stackStartFunction)
    assert.ifError(value)
    assert.notDeepEqual(actual, expected, message)
    assert.notDeepStrictEqual(actual, expected, message)
    assert.notEqual(actual, expected, message)
    assert.notStrictEqual(actual, expected, message)
    assert.ok(value, message)
    assert.strictEqual(actual, expected, message)
    assert.throws(block, error, message)

Testing

Tests were built using Jest.

Author

Changelog

  • 0.0.1 - Release