blob: 648809d5d6eaf7a63381772974fc1a51d4706e73 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# deprecation
> Log a deprecation message with stack
![build](https://action-badges.now.sh/gr2m/deprecation)
## Usage
<table>
<tbody valign=top align=left>
<tr><th>
Browsers
</th><td width=100%>
Load `deprecation` directly from [cdn.pika.dev](https://cdn.pika.dev)
```html
<script type="module">
import { Deprecation } from "https://cdn.pika.dev/deprecation/v2";
</script>
```
</td></tr>
<tr><th>
Node
</th><td>
Install with `npm install deprecation`
```js
const { Deprecation } = require("deprecation");
// or: import { Deprecation } from "deprecation";
```
</td></tr>
</tbody>
</table>
```js
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](https://www.npmjs.com/package/once) module.
```js
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
```
## License
[ISC](LICENSE)
|