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

blame

v2.0.3

Published

Easy stack-traces (and find the file/line(/call) to blame)

Downloads

29

Readme

npm version travis ci Coverage Status dependencies dev-dependencies Codacy Badge

node-blame

Easy stack traces

Install

$ npm install --save blame

As of version 2.0.0 Blame (mostly its dependencies) requires NodeJS 4 or higher. If you are 'stuck' on NodeJS 0.10 - 0.12, you will need to specify the version (the latest in the v1 range is 1.5.9).

$ npm install --save blame@^1.5.9

Usage

var blame = require('blame'),
	stack = blame.stack();

//  stack contains the full stack-trace leading up to the invocation of `blame.stack()`

Error.stackTraceLimit

By default there is a 10 line cap on the stack traces within node.js and io.js, Blame does not meddle with this setting by itself as it is widely considered a good default setting (and it truly is). If you feel this is getting in the way of your debugging/reporting, feel free to set the limit to your liking, for example Error.stackTraceLimit = Infinity will never cap the stack trace.

Note that changing this setting has to be done very early on in your application.

API

blame.stack([Error])

Create a JSON-like structure from a given or created error-stack and wraps it inside a BlameResult object.

BlameResult

The BlameResult contains all of the data found in the error stack and provides several methods to quickly reduce the stack trace, note that all of these methods work with the obtained stack trace order, this means that the items are sorted top down, e.g. first refers to the first item on the list of items in the stack trace (meaning this was the final call) before the Error was created and/or blame.trace() was invoked.

.message (string)

The message taken from the Error, if no Error was provided to blame.stack this will contain an empty string.

.trace (array)

As of version 1.5.0 The trace method is deprecated (you'll receive a proper notice for this), please use the .stack method.

.stack (array)

The stack-trace of the error/backtrace, the format is:

[{
	"file": "/path/to/file.js",
	"line": 1234,
	"column": 12,
	"call": "Object.functionName"
},
...
]

(call may be null if the trace was not called from within a function scope)

.filter(pattern [, max]) (BlameResult)

Create a new BlameResult containing only the items which match given pattern

  • pattern must be one of: string, RegExp (will be cast to RegExp if it is not)
  • max is an optional limit of the number of items in the returned BlameResult

.after(pattern [, max]) (BlameResult)

Create a new BlameResult containing only the items after given pattern (like from but excluding the match(es)).

  • pattern must be one of: string, RegExp (will be cast to RegExp if it is not)
  • max is an optional limit of the number of items in the returned BlameResult

.from(pattern [, max]) (BlameResult)

Create a new BlameResult containing only the items from given pattern (like after but including the match(es)).

  • pattern must be one of: string, RegExp (will be cast to RegExp if it is not)
  • max is an optional limit of the number of items in the returned BlameResult

.before(pattern [, max]) (BlameResult)

Create a new BlameResult containing only the items before given pattern (like until but excluding the match(es)).

  • pattern must be one of: string, RegExp (will be cast to RegExp if it is not)
  • max is an optional limit of the number of items in the returned BlameResult

.until(pattern [, max]) (BlameResult)

Create a new BlameResult containing only the items until given pattern (like before but including the match(es)).

  • pattern must be one of: string, RegExp (will be cast to RegExp if it is not)
  • max is an optional limit of the number of items in the returned BlameResult

.first([max]) (BlameResult)

Create a new BlameResult containing only the first N items

  • max is an optional limit of the number of items in the returned BlameResult

.last([max]) (BlameResult)

Create a new BlameResult containing only the last N items

  • max is an optional limit of the number of items in the returned BlameResult

.item([index]) (ResultItem)

Obtain a single item from the BlameResult trace. The argument may be any valid index of the stack trace array, but also:

  • false, null, 0 (and ommitting) > first item (top stack trace entry)
  • true > last item (bottom stack trace entry)

.steps (array)

This (excluded from enumeration) property contains all the steps taken to have the .trace-items, every time one of the BlameResult methods are called as new BlameResult is created with a new step containing the arguments used to create the new result. Each step is in the format:

{"<after|from|before|until>": <pattern>, "max": <max>}
// or
{"<first|last>: <max>}"}

.toString (string)

Both BlameResult and BlameItem now support the toString method, the format is slightly more compact than a new Error().stack call.

BlameResult

console.log(String(blame.trace()));

Message: <message>
	* <file> @<line>:<column>
	* <call> [<file> @<line>:<column>]

BlameItem

console.log(String(blame.trace().item()));

<message>
	<file> @<line>:<column>
or
<message>
	<call> [<file> @<line>:<column>]

If you would like to add some flair to the stack traces, all of the templates used are fully customizable, please refer to the templating tutorial and the templating example.

BlameItem

.context([before [, after]]) (string)

Provide a excerpt from the file with a simple pointer to the line which was responsible for the invocation of the stack item

  • if before is ommited or its numeric value resolves as false-ish, it will default to 3
  • if after is ommited or its numeric value resolves as false-ish, it will default to the numeric value of before or else 3

(Yes, this does mean that there is a minimum of 3 lines total)

License

GPLv2 © Konfirm Open