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

fail-nicely

v2.0.0

Published

A one-liner to at least explain why things didn't work out

Downloads

15

Readme

fail-nicely

A one-liner to at least explain why things didn't work out

Example

See demo: fail-nicely

npm install fail-nicely
var createHandler = require('fail-nicely');

var handlerFailure = createHandler(onSuccess, {title: 'Sorry!'});

function onSuccess (message) {
  console.log(message);
}

// Execute the callback with a failure:
handlerFailure('This demo requires WebGL 7 support!');

// Execute the onSuccess callback:
handlerFailure(null, 'Loaded successfully!');

You can also just pass it an error:

try {
  var y = 7 + g;
} catch (e) {
  handlerFailure(e);
}

The factory pattern is just a little convoluted, but the upshot is that intercepting fatal errors becomes a simple one-liner:

var fs = require('fs')
fs.readFile('test.json', createHandler(function (data) {
  console.log('loaded data:', data)
}))

Usage

require('fail-nicely')(callback[, options])

Returns a node-style callback (function (err, data)) that intercepts and handlers errors and otherwise forwards data through to callback.

When err is truthy, appends an overlay to the body element with a short explanation of what happened. Usefulf for making quick and ugly demos a little less ugly. If the first argument is an Error, it will use the error's message. If it's a string, that will be the explanation. Options are:

  • bg: overlay background color (default: '#333')
  • fg: overlay foreground (text) color (default: '#fff')
  • zIndex: z-index of the overlay (default: 9999)
  • title: heading title (default: 'Sorry!')
  • fontFamily: font family (default: Helvetica, Arial, sans-serif)
  • position: positioning of the overlay element (default: fixed)
  • invert: quick shorthand for swapping the foreground/background colors

Returns: Nothing.

License

© 2016 Ricky Reusser. MIT License.