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

complain

v1.6.1

Published

Mark methods as deprecated and warn the user when they're called

Downloads

24,165

Readme

complain

Mark methods as deprecated and warn the user when they're called. Forked from brianc/node-deprecate.

api

var complain = require('complain');

complain()

Call complain within a function you are deprecating. It will spit out all the messages to the console the first time and only the first time the method is called.

1  │ var complain = require('complain');
2  │
3  │ var someDeprecatedFunction = function() {
4  │   complain('someDeprecatedFunction() is deprecated');
5  │ };
6  │
…  │ // …
30 │
31 │ someDeprecatedFunction();

program output:

Options

  • location: a string in the format ${filepath}:${line}:${column} indicating where the deprecated function was called from. Setting this to false disables outputting the location and will only log the message once.
  • locationIndex: a number indicating the distance (in stack frames) from the call to complain to use as the deprecated location. 0 is the call to complain. By default, it is 1, which is typically the call to the deprecated function.
  • level: a number indicating the log level. 1 = notice. 2 = warning (default).
  • heading: a string that will be printed in color above the message. By default, "WARNING" when level === 2 or "NOTICE" when level === 1.
  • headingColor: a string that is an ansi color/format. By default, colors.warning when level === 2 or colors.notice when level === 1.

complain.method()

Deprecates a method on an object:

complain.method(console, 'log', 'You should not log.');

complain.fn()

Deprecates a function and returns it:

console.log = complain.fn(console.log, 'You should not log.');

complain.color

Set to false to disable color output. Set to true to force color output. Defaults to the value of complain.stream.isTTY.

complain.colors

Controls the colors used when logging. Default value:

{
  warning: '\x1b[31;1m', // red, bold
  notice: '\x1b[33;1m', // yellow, bold
  message: false, // use system color
  location: '\u001b[90m' // gray
}

How the default looks on a dark background vs. a light background:

complain.silence

When true, do nothing when the complain method is called.

complain.stream

The to which output is written. Defaults to process.stderr.

complain.log(message)

The function used to log, by default this function writes to complain.stream and falls back to console.warn.

You can replace this with your own logging method.

complain.getModuleName(location)

The function that determines if a warning is coming from a node_module. If the location for a warning is inside a dependent module, a single generic warning is logged once per module. You can replace this with your own function for environments (like browsers) that might not have node_modules in the path.

environment variables

SHOW_MODULE_COMPLAINS

By default, deprecation warnings whose caller location is in a dependent module will not be logged. A single module-level warning will be logged per module that is using deprecated apis. If you wish to view the individual warnings, set this variable to a truthy value.

SHOW_MODULE_COMPLAINS=1 node app.js

SHOW_NESTED_COMPLAINS

By default, if a deprecated function is using other deprecated apis, there will only be a warning for the top-level call to the deprecated function. If you wish to view the nested warnings, set this variable to a truthy value.

SHOW_NESTED_COMPLAINS=1 node app.js

license

MIT