Add API for custom handling of deprecations
This commit is contained in:
parent
175449f096
commit
ccef805e9b
5 changed files with 58 additions and 1 deletions
|
@ -88,9 +88,13 @@ deprecate.warn = function(oldName, newName) {
|
|||
return deprecate.log(oldName + " is deprecated. Use " + newName + " instead.");
|
||||
};
|
||||
|
||||
var deprecationHandler = null;
|
||||
|
||||
// Print deprecation message.
|
||||
deprecate.log = function(message) {
|
||||
if (process.throwDeprecation) {
|
||||
if (typeof deprecationHandler === 'function') {
|
||||
deprecationHandler(message);
|
||||
} else if (process.throwDeprecation) {
|
||||
throw new Error(message);
|
||||
} else if (process.traceDeprecation) {
|
||||
return console.trace(message);
|
||||
|
@ -99,4 +103,12 @@ deprecate.log = function(message) {
|
|||
}
|
||||
};
|
||||
|
||||
deprecate.setHandler = function(handler) {
|
||||
deprecationHandler = handler;
|
||||
};
|
||||
|
||||
deprecate.getHandler = function() {
|
||||
return deprecationHandler;
|
||||
}
|
||||
|
||||
module.exports = deprecate;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue