complain

2018-11-08 admin

complain是什么

什么是complain,Mark methods as deprecated and warn the user when they're called

complain使用教程帮助文档

complain

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

api

var complain = require('complain');

complain()

<sup>complain([String message1 [, String message2 [,...]]], [Object options])</sup>

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.

complain.method()

<sup>complain.method(Object proto, String methodName, [String message1 [, String message2 [,...]]], [Object options])</sup>

Deprecates a method on an object:

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

complain.fn()

<sup>complain.fn(Function func, [String message1 [, String message2 [,...]]], [Object options])</sup>

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
  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 complaint is coming from a node_module. If the location for a complaint 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.

Run with the enviornment variable SHOW_MODULE_COMPLAINS=1 to disable the generic module warning

license

MIT

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-44889.html

文章标题:complain

回到顶部