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

node-icecream

v1.0.0

Published

Quick and easy variable and expression debugging

Downloads

64

Readme

node-icecream

NPM version NPM downloads Build status Codecov License

node-icecream is a Node.js port of the icecream library for Python.

Installation

Installing node-icecream is easy:

$ yarn add node-icecream

Or with npm:

$ npm install node-icecream

Usage

Take the following code as an example:

function foo() {
    return 'bar';
}

console.log(`foo(): ${foo()}`);
// > foo(): bar

With node-icecream, the above would become:

const ic = require('node-icecream')();

function foo() {
    return 'bar';
}

ic(foo());
// > 🍦 foo(): 'bar'

With arguments

node-icecream will return the argument(s) it is given, so you can easily plug it into existing code.

const ic = require('node-icecream')();

function foo() {
    return 'bar';
}

const result = ic(foo());
// > 🍦 foo(): 'bar'
// result === 'bar'

const results = ic(foo(), foo(), foo());
// > 🍦 foo(): 'bar', foo(): 'bar', foo(): 'bar'
// results === ['bar', 'bar', 'bar']

Without arguments

When not given any arguments, node-icecream will print the filename and the line number where it was called from. The filename shown is relative from the project's root path.

const ic = require('node-icecream')();

function foo() {
    ic();

    // For example purposes only
    if (true) {
        ic();
        return 'bar';
    }

    ic();
    return 'something is wrong';
}

ic(foo());
// > 🍦 index.js:4
// > 🍦 index.js:8
// > 🍦 foo(): 'bar'

With existing logger

node-icecream can easily be used together with an existing logger. The following is an example on how to use node-icecream with the debug package.

const debug = require('debug')('example');
const ic = require('node-icecream')({
    prefix: '',
    outputFunction: debug,
});

function foo() {
    ic();
    return 'bar';
}

ic(foo());
// > example index.js:8 +0ms
// > example foo(): 'bar' +11ms

Options

node-icecream can easily be configured to use a different prefix or print to somewhere else. Configuration is applied when requiring node-icecream:

const ic = require('node-icecream')({ prefix: 'prefix: ' });

Available options

  • prefix (default: '🍦 ' on all systems except for Windows, where it is '[ic] ') is the prefix to use. This can be both a string or a function. If it is a function, it is called every time just before printing. This option can be useful when you need timestamps to be printed.
  • outputFunction (default: console.log) is the function that is called to print the output. By default, it simply uses console.log(), but the option makes it easy to log to existing loggers aswell.

Contributing

Bug reports, feature requests and pull requests are all welcome! Continue reading for some help on getting up and running, or head over to the issues page to report a bug or request a new feature.

Getting up and running locally

The following needs to be done to start working on the project:

# Clone the repository
$ git clone https://github.com/jmerle/node-icecream.git

# cd into the cloned repository
$ cd node-icecream

# Install the necessary dependencies
$ yarn

# Do your thing

# Lint the code for style issues
$ yarn lint

# Run tests
$ yarn test

Pull requests

When starting to work on a new feature, please make sure to work off of the develop branch. This branch contains the latest code, so the master branch is a direct representation of what you get when installing through npm. Similarly, also send pull requests to the develop branch.

TypeScript

node-icecream comes with TypeScript definitions. The default import syntax can be used, which imports a wrapper around the ic function to make configuration possible.

import ice from 'node-icecream';

const ic = ice({ prefix: '[prefix] ' });

function foo(): string {
    return 'bar';
}

ic(foo());
// > [prefix] foo(): 'bar'

Limitations

  • Doesn't work in the REPL.

License

MIT