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

error-shortener

v1.0.2

Published

generates a string containing a message and trimmed stack from error

Downloads

20

Readme

error-shortener

Build Status Coverage Status

This module is written on typescript, and contains the .d.ts file. If you write on typescript: just use it in your project and definitions will be automatically uploaded.

npm i -S error-shortener

Motivation

Once I tired of reading the error-stack on several screens. So I wrote the module to clean the stack: it removes the elements that are out of your repository (based on process.cwd()), and the elements from the node_modules folder. Note: before cleaning the error will be checked to the expected format. If it is different, the stack cleaning will not be fulfilled.

API

const API = require('error-shortner')

// performs reduction of the stack, normalized error-stack indents, replacement message and name to the actual
// alias to API.fmtShortError
API.fmtError(arg: API.IErrorLike): string
// normalized error-stack indents, replacement message and name to the actual
API.fmtLongErrorf(arg: API.IErrorLike): string
// compliance argument with the interface
API.isIErrorLike(arg: any): arg is API.IErrorLike

Examples

Example: error has an expected format

when formatting:

  • Replaced the old SomeError to the new NewError name.
  • Replaced the old message to new.
  • Excluded calls that do not relate to your source code.
  • Removed process.cwd() part of the file paths.
import { fmtError } from 'error-shortener'

const likeBluebirdError = {
    name:    `NewError`,
    message: `Text added from some place!\
              \n\t SomeMeta: foo=bar; other=abc\
              \n\t OriginalError: something happened!`,
    stack:   `SomeError: something happened!
                  at error (/home/nskazki/node.js/example/index.js:12:28)
              From previous event:
                  at error (/home/nskazki/node.js/example/index.js:12:27)
                  at /home/nskazki/node.js/example/index.js:19:15
                  at Timer.listOnTimeout (timers.js:92:15)
              From previous event:
                  at Object.<anonymous> (/home/nskazki/node.js/example/index.js:19:4)
                  at Module._compile (module.js:413:34)
                  at Object.Module._extensions..js (module.js:422:10)
                  at Module.load (module.js:357:32)
                  at Function.Module._load (module.js:314:12)
                  at Function.Module.runMain (module.js:447:10)
                  at startup (node.js:141:18)
                  at node.js:933:3`
    }

console.error(fmtError(likeBluebirdError))
/*
NewError: Text added from some place!
       SomeMeta: foo=bar; other=abc
       OriginalError: something happened!
    at error (index.js:12:28)
From previous event:
    at error (index.js:12:27)
    at index.js:19:15`
From previous event:
    at Object.<anonymous> (index.js:19:4)
*/

Example: unknown error format

when formatting:

  • added default Error name
  • normalized error-stack indents
import { fmtError } from 'error-shortener'

const likePhantomError = {
    message: 'JSON.stringify cannot serialize cyclic structures.',
    stack:   `stringify@[native code]
              wrapper

              global code
              evaluateJavaScript@[native code]
              evaluate
              file:///home/nskazki/node.js/work-projects/dmca-ip-search-service/phantom-farm/worker/node_modules/node-phantom-simple/bridge.js:121:61`
  }

console.error(fmtError(likePhantomError))

/*
Error: JSON.stringify cannot serialize cyclic structures.
Stack:
    stringify@[native code]
    wrapper
    global code
    evaluateJavaScript@[native code]
    evaluate
    file:///home/nskazki/node.js/work-projects/dmca-ip-search-service/phantom-farm/worker/node_modules/node-phantom-simple/bridge.js:121:61`
*/

Related