dep

depr

Easily deprecate a method.

Showing:

Popularity

Downloads/wk

4

GitHub Stars

0

Maintenance

Last Commit

6yrs ago

Contributors

0

Package

Dependencies

1

Size (min+gzip)

0.4KB

License

ISC

Type Definitions

Tree-Shakeable

No?

Categories

Readme

depr

Build Status

Easily deprecate a method. Log a warning the first time it's used and optionally redirect to another method.

/**
* @param {Object} scope - the object containing the method
* @param {String} method - the name of the method to deprecate
* @param {String} [message] - the message to log
* @param {String} [preferredMethod] - an alternate method to execute
*/
depr(scope, method, message, preferredMethod)

Examples

var depr = require('depr');
var app = {
  oldMethod: function () {},
  newMethod: function () {}
};

Basic

The deprecated method is executed, and a message is logged.

depr(app, 'oldMethod');
app.oldMethod();  // 'DEPRECATION WARNING: Do not use "oldMethod".'

Custom Message

The deprecated method is executed, and a custom message is logged.

depr(app, 'oldMethod', 'This method sucks.  Don\'t use it.');
app.oldMethod();  // 'This method sucks.  Don't use it.'

Redirect - Default Message

An alternate method is executed and a message is logged.

depr(app, 'oldMethod', null, 'newMethod');
app.oldMethod();
// 'DEPRECATION WARNING: Do not use "oldMethod". Use "newMethod" instead.'

Redirect - Custom Message

An alternate method is executed and a custom message is logged.

depr(app, 'oldMethod', 'STOP USING oldMethod!!!!1!', 'newMethod');
app.oldMethod();  // 'STOP USING oldMethod!!!!1!'

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100