|
2 年之前 | |
---|---|---|
.. | ||
dist-node | 2 年之前 | |
dist-src | 2 年之前 | |
dist-types | 2 年之前 | |
dist-web | 2 年之前 | |
LICENSE | 2 年之前 | |
README.md | 2 年之前 | |
package.json | 2 年之前 |
Log a deprecation message with stack
Browsers | Load `deprecation` directly from [cdn.pika.dev](https://cdn.pika.dev) ```html ``` |
---|---|
Node | Install with `npm install deprecation` ```js const { Deprecation } = require("deprecation"); // or: import { Deprecation } from "deprecation"; ``` |
function foo() {
bar();
}
function bar() {
baz();
}
function baz() {
console.warn(new Deprecation("[my-lib] foo() is deprecated, use bar()"));
}
foo();
// { Deprecation: [my-lib] foo() is deprecated, use bar()
// at baz (/path/to/file.js:12:15)
// at bar (/path/to/file.js:8:3)
// at foo (/path/to/file.js:4:3)
To log a deprecation message only once, you can use the once module.
const Deprecation = require("deprecation");
const once = require("once");
const deprecateFoo = once(console.warn);
function foo() {
deprecateFoo(new Deprecation("[my-lib] foo() is deprecated, use bar()"));
}
foo();
foo(); // logs nothing