UNPKG

@boost/decorators

Version:

Experimental decorators for common patterns.

39 lines (32 loc) 1.47 kB
import { isClass } from './helpers/isClass.mjs'; import { isMethod } from './helpers/isMethod.mjs'; import { isParam } from './helpers/isParam.mjs'; import { isProperty } from './helpers/isProperty.mjs'; /* eslint-disable no-console */ /** * A decorator that marks a class declaration, class method, * class property, or method parameter as deprecated by * logging a deprecation message to the console. */ function Deprecate(message) { return (target, property, descriptor) => { const isProtoOrStatic = typeof target === 'function'; const className = isProtoOrStatic ? target.name : target.constructor.name; const accessSymbol = isProtoOrStatic ? `.${String(property)}` : `#${String(property)}`; // Class if (isClass(target, property, descriptor)) { console.debug(message ?? `Class \`${className}\` has been deprecated.`); // Method } else if (isMethod(target, property, descriptor)) { console.debug(message ?? `Method \`${className + accessSymbol}()\` has been deprecated.`); // Property } else if (isProperty(target, property, descriptor)) { console.debug(message ?? `Property \`${className + accessSymbol}\` has been deprecated.`); // Param } else if (isParam(target, property, descriptor)) { console.debug(message ?? `Parameter ${descriptor} for \`${className + accessSymbol}()\` has been deprecated.`); } }; } export { Deprecate }; //# sourceMappingURL=Deprecate.mjs.map