-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a lightweight browser version of "depd"
The module "depd" does not support browser and it is not trivial to fix that. This commits adds a lightweight implementation of the depd "deprecate" function.
- Loading branch information
Miroslav Bajtoš
committed
Feb 27, 2015
1 parent
844c067
commit edc52f1
Showing
2 changed files
with
19 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// A lightweight alternative to "depd" that works in the browser | ||
module.exports = function depd(namespace) { | ||
var warned = {}; | ||
return function deprecate(message) { | ||
if (warned[message]) return; | ||
warned[message] = true; | ||
|
||
if (process.noDeprecation) { | ||
return; | ||
} else if (process.traceDeprecation) { | ||
console.trace(namespace, 'deprecated', message); | ||
} else { | ||
console.warn(namespace, 'deprecated', message); | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
edc52f1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two major problems with
depd
:process.stderr
which is not available in the browserError.captureStackTrace
, which is Chrome-specific and does not work in PhantomJS (for example)edc52f1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dougwilson/nodejs-depd#16