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

examine

v0.1.3

Published

assert + error-first callback

Downloads

18

Readme

examine

js-standard-style Coverage Status

examine is a utility module that provides a powerful yet simple API to assert code in production. Using an assertion framework wrapped inside this package you will be able to use the assertion framework APIs without the fear of uncaught exceptions.

Errors thrown by the assert and expect APIs are caught and handled by the callback you bind to examine.

Imagine a big invisible and smart try-catch block wrapped around your app that only catches specific errors. That's what this is.

Quick Example

var examine = new Examine()
var assert = examine.assert

function errorHandler (err) {
  console.log('Caught it!', err)
}

examine.subject(errorHandler)

var string = 'Hello :)'

assert.typeOf(string, 'boolean')

console.log('This wont be executed')

API

examine.subject(handler)

Bind a handler to the examine instance. The handler will be called when an error is thrown from the .expect or .assert APIs and it can be switched during the execution order.

examine.assert and examine.expect

The assert and the expect APIs belong to the assertion library chai.js. They have a very good documentation if you don't know how to use these APIs.

Known Pitfalls

try-catch

If you use a try-catch block be careful to not put a examine expect/assert statement inside it, because it can have behaviour that is not wanted. If you do the error that is thrown will be caught by the try-catch block and the subject handler won't be called.

Take the following example:

var examine = new Examine()
var assert = examine.assert

function errorHandler (err) {
  console.log('This wont be called')
}

examine.subject(errorHandler)

try {
  assert.ok(null)
} catch (e) {
  console.log('Caught it here!', e)
}

Questions

Does throw still work as expected if I use this package?

Of course yes, the only throws that are caught and handled are the examine errors, everything else that you throw is your responsibility to catch it.

Are you using process.on('uncaughtException', handle) to caught the thrown errors?

No, and you can still use it without affecting the functionality of this package.

Is this black magic?

I don't consider this to be black magic, just a clever hack. You can see the source of the mystery here.

Where is should style?

should is not supported because of the following reasons:

  • It is considered bad practice to modify the prototype of String, Object, Number, Boolean, etc.
  • It is not possible to know which subject handler that should be called

TODO

  • Finish assert and expect APIs tests
  • Add some practical examples

License

MIT