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

parse-err

v1.0.0

Published

Parse errors in the Browser and Node. Made for Cabin.

Downloads

13,227

Readme

parse-err

build status code style styled with prettier made with lass license

Parse errors to provide a consistent metadata object across Browser and Node environments. Made for Cabin.

Table of Contents

Install

npm:

npm install parse-err

How does it work

This package exports a function that accepts two arguments (err, props).

  • req (Object) - an HTTP request
  • props (Array) - a list of properties to cherry-pick from the error object parsed out of err (by default all properties are returned; even non-enumerable ones and ones on the prototype object)

This function iterates over the prototype of the error and the error itself to get all non-Function properties and returns these properties as an object.

Normally if you console.log(err) it will not show you all fields such as type, statusCode, or code (e.g. if you're using Stripe).

In our case, we wanted to store these properties in our logs with Cabin.

As of v1.0.0 it now parses err.errors Array too – which adds support for packages such as maybe-combine-errors and combine-errors. This is useful if you combine multiple errors into one Error object, and subsequently set a property of err.errors = errors where errors is an Array of the errors combined.

Usage

Node

const parseErr = require('parse-err');

const err = new Error('Oops!');

// just a random example
err.name = 'BeepBoop';
err.code = 100;
err.statusCode = 200;

console.error(parseErr(err));
{ name: 'BeepBoop',
  message: 'Oops!',
  stack: 'BeepBoop: Oops!\n    at Object.<anonymous> (/Users/user/Projects/parse-err/test.js:3:13)\n    at Module._compile (module.js:652:30)\n    at Object.Module._extensions..js (module.js:663:10)\n    at Module.load (module.js:565:32)\n    at tryModuleLoad (module.js:505:12)\n    at Function.Module._load (module.js:497:3)\n    at Function.Module.runMain (module.js:693:10)\n    at startup (bootstrap_node.js:188:16)\n    at bootstrap_node.js:609:3',
  code: 100,
  statusCode: 200 }

VanillaJS

<script src="https://unpkg.com/parse-err"></script>
<script type="text/javascript">
  (function() {
    var err = new Error('Oops!');
    err.name = 'BeepBoop';
    err.statusCode = 500;
    console.error(parseErr(err));
  })();
</script>

Bundler

If you are using browserify, webpack, rollup, or another bundler, then you can follow the same usage as Node above.

Supported Platforms

  • Node: v6.x+

  • Browsers (see .browserslistrc):

    npx browserslist
    and_chr 107
    and_ff 106
    and_qq 13.1
    and_uc 13.4
    android 107
    chrome 107
    chrome 106
    chrome 105
    edge 107
    edge 106
    edge 105
    firefox 107
    firefox 106
    firefox 105
    firefox 102
    ios_saf 16.1
    ios_saf 16.0
    ios_saf 15.6
    ios_saf 15.5
    ios_saf 14.5-14.8
    kaios 2.5
    op_mini all
    op_mob 72
    opera 92
    opera 91
    safari 16.1
    safari 16.0
    safari 15.6
    samsung 19.0
    samsung 18.0

Contributors

| Name | Website | | -------------- | -------------------------- | | Nick Baugh | http://niftylettuce.com/ |

License

MIT © Nick Baugh