Socket
Socket
Sign inDemoInstall

complain

Package Overview
Dependencies
2
Maintainers
11
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.5.0 to 1.6.0

13

index.js

@@ -23,3 +23,3 @@ 'use strict';

complain.color = complain.stream && complain.stream.isTTY;
complain.colors = { warning:'\x1b[31;1m', message:false, location:'\u001b[90m' };
complain.colors = { warning:'\x1b[31;1m', notice:'\x1b[33;1m', message:false, location:'\u001b[90m' };
complain.getModuleName = getModuleName;

@@ -38,2 +38,5 @@

var locationIndex;
var headingColor;
var heading;
var level;
var args = arguments;

@@ -50,2 +53,6 @@

level = options.level || 2;
heading = options.heading || (level == 2 ? "WARNING!!" : "NOTICE");
headingColor = options.headingColor || (level == 2 ? complain.colors.warning : complain.colors.notice);
// Default to the location of the call to the deprecated function

@@ -67,3 +74,3 @@ locationIndex = options.locationIndex == null ? 1 : options.locationIndex;

if (!hits[moduleName]) {
var output = format('WARNING!!', complain.colors.warning)
var output = format("NOTICE", complain.colors.notice);
output += linebreak + format('The module ['+moduleName+'] is using deprecated features.', complain.colors.message);

@@ -84,3 +91,3 @@ output += linebreak + format('Run with process.env.SHOW_MODULE_COMPLAINS=1 to see all warnings.', complain.colors.message);

var output = format('WARNING!!', complain.colors.warning);
var output = format(heading, headingColor);

@@ -87,0 +94,0 @@ for(var i = 0; i < args.length; i++) {

{
"name": "complain",
"version": "1.5.0",
"version": "1.6.0",
"description": "Mark methods as deprecated and warn the user when they're called",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -34,4 +34,7 @@ # complain

**`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.
- **`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`.

@@ -71,2 +74,3 @@ ### complain.method()

warning: '\x1b[31;1m', // red, bold
notice: '\x1b[33;1m', // yellow, bold
message: false, // use system color

@@ -73,0 +77,0 @@ location: '\u001b[90m' // gray

@@ -79,8 +79,20 @@ var assert = require('assert');

it('allows a lower log level', function() {
complain('this is a less urgent message', { level:1, locationIndex:0 });
var text = output._text.join(' ');
assert(text.indexOf('NOTICE') > 0, 'should have contained the string "notice"');
assert(text.indexOf('this is a less urgent message') > 0, 'should have contained the message');
});
it('shows single generic warning if the complain comes from a node_module', function() {
it('allows custom header', function() {
complain('this is a migratable deprecation', { heading:'MIGRATE', headingColor:'\x1b[36;1m', locationIndex:0 });
var text = output._text.join(' ');
assert(text.indexOf('MIGRATE') > 0, 'should have contained the string "migrate"');
assert(text.indexOf('this is a migratable deprecation') > 0, 'should have contained the message');
});
it('shows single generic notice if the complain comes from a node_module', function() {
moduleWithComplains.one();
var text = output._text.join(' ');
console.log(text);
assert(text.indexOf('WARNING') > 0, 'should have contained the string "warning"');
assert(text.indexOf('NOTICE') > 0, 'should have contained the string "notice"');
assert(text.indexOf('module-with-complains') > 0, 'should contain the module name');

@@ -87,0 +99,0 @@ moduleWithComplains.two();

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc