
Product
Introducing Module Reachability: Focus on the Vulnerabilities That Matter
Module Reachability filters out unreachable CVEs so you can focus on vulnerabilities that actually matter to your application.
deprecation
Advanced tools
The `deprecation` npm package is designed to help developers manage and signal deprecations within their codebase. It provides a structured way to mark certain functionalities as deprecated, issue warnings, and guide users towards alternatives or updated practices. This can be particularly useful in libraries or applications undergoing gradual upgrades or changes, ensuring backward compatibility while encouraging the adoption of new features or methods.
Emitting Deprecation Warnings
This feature allows developers to emit deprecation warnings with a unique ID and a message guiding users towards an alternative method or practice. The code sample demonstrates how to create a new `Deprecation` instance associated with a specific package and issue a warning about a deprecated method.
"use strict";
const Deprecation = require('deprecation');
const deprecation = new Deprecation('@mycompany/mypackage');
deprecation.warn('deprecated-method', 'The `deprecatedMethod()` is deprecated and will be removed in the next major release. Use `newMethod()` instead.');
The `depd` package is similar to `deprecation` in that it provides a way to declare deprecations and issue warnings in Node.js applications. However, `depd` focuses more on a minimalistic approach and is widely used for expressing deprecations in middleware or frameworks. It automatically handles the generation of detailed deprecation messages, including the stack trace to the deprecated call, which differs from `deprecation`'s more manual and message-centric approach.
The `warning` package is another tool for managing warnings in JavaScript applications, not limited to deprecations. It allows developers to print warning messages to the console if a condition fails, which can be used for deprecations but also for other types of warnings. Compared to `deprecation`, `warning` is more general-purpose and does not specifically focus on package or method deprecations.
Log a deprecation message with stack
Browsers |
Load
|
---|---|
Node |
Install with
|
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
FAQs
Log a deprecation message with stack
The npm package deprecation receives a total of 6,533,584 weekly downloads. As such, deprecation popularity was classified as popular.
We found that deprecation demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Module Reachability filters out unreachable CVEs so you can focus on vulnerabilities that actually matter to your application.
Company News
Socket is bringing best-in-class reachability analysis into the platform — cutting false positives, accelerating triage, and cementing our place as the leader in software supply chain security.
Product
Socket is introducing a new way to organize repositories and apply repository-specific security policies.