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

megasniff

v1.0.0

Published

Better debugging for promise chains and pipelines

Downloads

5

Readme

Megasniff

Better debugging for chained functions (promises, streams, etc.). Inspired by supersniff, but with these improvements in mind:

  • [x] Support for custom loggers (like bunyan, winston, or other services)
  • [x] Pre- and suffix support
  • [x] No forced tag
  • [x] Using error levels for errors

Things to do:

  • [ ] Custom configureable log levels
  • [ ] Decorator functions (e.g. error => error.message)

Motivation

Can be found here. It shall be a readable replacement for:

getData()
  .then(data => {
    console.info(data)
    return data
  })
  .then(transformData)

Installation

npm install megasniff

Examples

const megasniff = require('megasniff')

const reveersedList = new Promise(resolve => resolve([3, 1, 2]))
  .then(megasniff)
  .then(list => list.sort())
  .then(megasniff)
  .then(list => list.reverse())
  .then(megasniff)

This yields in the console:

[ 3, 1, 2 ]
[ 1, 2, 3 ]
[ 3, 2, 1 ]
const megasniff = require('megasniff')

new Promise(resolve => resolve('Good'))
  .then(megasniff.config({ prefix: `Value at ${new Date()}:` }))

This yields on stdout:

Good Value at Wed Oct 17 2018 15:47:26 GMT+0200 (Central European Summer Time)
const megasniff = require('megasniff')
const logger = console

new Promise((resolve, reject) => reject(new Error('Bad')))
  .catch(megasniff.config({ suffix: '.. We are condemned' }))
  .catch(error => error)

This yields on stderr:

Error: Bad ... We are doomed

API

Default Usage:

const megasniff = require('megasniff')

const sortedList = new Promise(resolve => resolve([3, 1, 2]))
  .then(megasniff)
  .then(list => list.sort())
  .then(megasniff)

megasniff is a function that logs and returns the passed value. The value is logged either to stdout or sterr depending on the passed value.

Configuration:

const megasniff = require('megasniff')
const logger = console
new Promise(resolve => resolve('Good Software'))
  .then(megasniff.config({ prefix: `[megasniff]`, logger }))

megasniff.config takes an object as argument. Megasniff can be configured with these optional parameters:

| key | value | |--------|-----------------------------------| | log | External logger | | logger | Other key for external logger | | prefix | Will be prefixed the logged value | | suffix | Will be suffixed the logged value |