Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
deprecated-decorator
Advanced tools
The deprecated-decorator npm package provides a way to mark methods or classes as deprecated in JavaScript/TypeScript. This helps developers to signal that certain parts of the codebase should no longer be used and may be removed in future versions.
Deprecate a Method
This feature allows you to mark a method as deprecated. When the deprecated method is called, a warning message will be logged to the console.
const { deprecated } = require('deprecated-decorator');
class Example {
@deprecated('This method will be removed in future versions. Use newMethod instead.')
oldMethod() {
console.log('This is the old method.');
}
newMethod() {
console.log('This is the new method.');
}
}
const example = new Example();
example.oldMethod();
Deprecate a Class
This feature allows you to mark an entire class as deprecated. When an instance of the deprecated class is created, a warning message will be logged to the console.
const { deprecated } = require('deprecated-decorator');
@deprecated('This class will be removed in future versions. Use NewClass instead.')
class OldClass {
method() {
console.log('This is a method in the old class.');
}
}
class NewClass {
method() {
console.log('This is a method in the new class.');
}
}
const oldInstance = new OldClass();
oldInstance.method();
The core-decorators package provides a set of decorators for common use cases, including deprecation. It offers a more comprehensive set of decorators compared to deprecated-decorator, making it a more versatile choice for developers who need additional functionality beyond deprecation.
The deprecated package is another option for marking methods and classes as deprecated. It is similar in functionality to deprecated-decorator but offers a simpler API. It is a good choice for developers who need a straightforward solution for deprecation without additional features.
A simple decorator for deprecated properties, methods and classes. It can also wrap normal functions via the old-fashioned way.
Transpilers supported:
experimentalDecorators
option enabled.npm install deprecated-decorator --save
export declare type DeprecatedDecorator = ClassDecorator & PropertyDecorator;
export interface DeprecatedOptions {
alternative?: string;
version?: string;
url?: string;
}
export declare function deprecated(options?: DeprecatedOptions): DeprecatedDecorator;
export declare function deprecated(alternative?: string, version?: string, url?: string): DeprecatedDecorator;
export declare function deprecated<T extends Function>(fn: T): T;
export declare function deprecated<T extends Function>(options: DeprecatedOptions, fn: T): T;
export declare function deprecated<T extends Function>(alternative: string, fn: T): T;
export declare function deprecated<T extends Function>(alternative: string, version: string, fn: T): T;
export declare function deprecated<T extends Function>(alternative: string, version: string, url: string, fn: T): T;
export default deprecated;
Decorating a class will enable warning on constructor and static methods (including static getters and setters):
import deprecated from 'deprecated-decorator';
// alternative, since version, url
@deprecated('Bar', '0.1.0', 'http://vane.life/')
class Foo {
static method() { }
}
Or you can decorate methods respectively:
import deprecated from 'deprecated-decorator';
class Foo {
@deprecated('otherMethod')
method() { }
@deprecated({
alternative: 'otherProperty',
version: '0.1.2',
url: 'http://vane.life/'
})
get property() { }
}
For functions:
import deprecated from 'deprecated-decorator';
let foo = deprecated({
alternative: 'bar',
version: '0.1.0'
}, function foo() {
// ...
});
MIT License.
FAQs
A simple decorator for deprecated methods and properties.
The npm package deprecated-decorator receives a total of 529,366 weekly downloads. As such, deprecated-decorator popularity was classified as popular.
We found that deprecated-decorator 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.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.