deprecated-decorator
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -1,2 +0,9 @@ | ||
export declare function deprecated(alternative?: string, version?: string, url?: string): (target: Function | Object, name?: string, descriptor?: PropertyDescriptor) => any; | ||
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 default deprecated; |
@@ -24,3 +24,15 @@ /* | ||
warnedPositions[at] = true; | ||
var message = (type === 'property' ? 'Property or method' : 'Class') + " \"" + name + "\" has been deprecated"; | ||
var message; | ||
switch (type) { | ||
case 'property': | ||
message = 'Property'; | ||
break; | ||
case 'method': | ||
message = 'Method'; | ||
break; | ||
case 'class': | ||
message = 'Class'; | ||
break; | ||
} | ||
message += " \"" + name + "\" has been deprecated"; | ||
if (version) { | ||
@@ -99,6 +111,15 @@ message += " since version " + version; | ||
} | ||
function deprecated(alternative, version, url) { | ||
function deprecated(options, version, url) { | ||
var alternative; | ||
if (typeof options === 'string') { | ||
alternative = options; | ||
} | ||
else if (options) { | ||
(alternative = options.alternative, version = options.version, url = options.url, options); | ||
} | ||
return function (target, name, descriptor) { | ||
if (typeof name === 'string') { | ||
return decorateProperty('property', name, descriptor, alternative, version, url); | ||
var type = descriptor && typeof descriptor.value === 'function' ? | ||
'method' : 'property'; | ||
return decorateProperty(type, name, descriptor, alternative, version, url); | ||
} | ||
@@ -105,0 +126,0 @@ else if (typeof target === 'function') { |
{ | ||
"name": "deprecated-decorator", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "A simple decorator for deprecated methods and properties.", | ||
@@ -5,0 +5,0 @@ "main": "bld/index.js", |
@@ -14,2 +14,19 @@ [![NPM Package](https://badge.fury.io/js/deprecated-decorator.svg)](https://www.npmjs.com/package/deprecated-decorator) | ||
## API References | ||
```ts | ||
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 default deprecated; | ||
``` | ||
## Usage | ||
@@ -38,3 +55,7 @@ | ||
@deprecated('otherProperty') | ||
@deprecated({ | ||
alternative: 'otherProperty', | ||
version: '0.1.2', | ||
url: 'http://vane.life/' | ||
}) | ||
get property() { } | ||
@@ -41,0 +62,0 @@ } |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15835
8
198
66