reflect-metadata
- Version 0.2.2
- Published
- 241 kB
- No dependencies
- Apache-2.0 license
Install
npm i reflect-metadatayarn add reflect-metadatapnpm add reflect-metadataOverview
Polyfill for Metadata Reflection API
Index
Namespaces
namespace global
namespace global {}namespace global.Reflect
namespace global.Reflect {}function decorate
decorate: {    (decorators: ClassDecorator[], target: Function): Function;    (        decorators: (PropertyDecorator | MethodDecorator)[],        target: Object,        propertyKey: string | symbol,        attributes?: PropertyDescriptor    ): PropertyDescriptor;    (decorators: ClassDecorator[], target: Function): Function;    (        decorators: (PropertyDecorator | MethodDecorator)[],        target: Object,        propertyKey: string | symbol,        attributes?: PropertyDescriptor    ): PropertyDescriptor;};- Applies a set of decorators to a target object. - Parameter decorators- An array of decorators. - Parameter target- The target object. - Returns- The result of applying the provided decorators. - Remarks- Decorators are applied in reverse order of their positions in the array. - Example 1- class Example { } - // constructor Example = Reflect.decorate(decoratorsArray, Example); 
- Applies a set of decorators to a property of a target object. - Parameter decorators- An array of decorators. - Parameter target- The target object. - Parameter propertyKey- The property key to decorate. - Parameter attributes- A property descriptor. - Remarks- Decorators are applied in reverse order. - Example 1- class Example { // property declarations are not part of ES6, though they are valid in TypeScript: // static staticProperty; // property; - static staticMethod() { } method() { } } - // property (on constructor) Reflect.decorate(decoratorsArray, Example, "staticProperty"); - // property (on prototype) Reflect.decorate(decoratorsArray, Example.prototype, "property"); - // method (on constructor) Object.defineProperty(Example, "staticMethod", Reflect.decorate(decoratorsArray, Example, "staticMethod", Object.getOwnPropertyDescriptor(Example, "staticMethod"))); - // method (on prototype) Object.defineProperty(Example.prototype, "method", Reflect.decorate(decoratorsArray, Example.prototype, "method", Object.getOwnPropertyDescriptor(Example.prototype, "method"))); 
function defineMetadata
defineMetadata: {    (metadataKey: any, metadataValue: any, target: Object): void;    (        metadataKey: any,        metadataValue: any,        target: Object,        propertyKey: string | symbol    ): void;    (metadataKey: any, metadataValue: any, target: Object): void;    (        metadataKey: any,        metadataValue: any,        target: Object,        propertyKey: string | symbol    ): void;};- Define a unique metadata entry on the target. - Parameter metadataKey- A key used to store and retrieve metadata. - Parameter metadataValue- A value that contains attached metadata. - Parameter target- The target object on which to define metadata. - Example 1- class Example { } - // constructor Reflect.defineMetadata("custom:annotation", options, Example); - // decorator factory as metadata-producing annotation. function MyAnnotation(options): ClassDecorator { return target => Reflect.defineMetadata("custom:annotation", options, target); } 
- Define a unique metadata entry on the target. - Parameter metadataKey- A key used to store and retrieve metadata. - Parameter metadataValue- A value that contains attached metadata. - Parameter target- The target object on which to define metadata. - Parameter propertyKey- The property key for the target. - Example 1- class Example { // property declarations are not part of ES6, though they are valid in TypeScript: // static staticProperty; // property; - static staticMethod(p) { } method(p) { } } - // property (on constructor) Reflect.defineMetadata("custom:annotation", Number, Example, "staticProperty"); - // property (on prototype) Reflect.defineMetadata("custom:annotation", Number, Example.prototype, "property"); - // method (on constructor) Reflect.defineMetadata("custom:annotation", Number, Example, "staticMethod"); - // method (on prototype) Reflect.defineMetadata("custom:annotation", Number, Example.prototype, "method"); - // decorator factory as metadata-producing annotation. function MyAnnotation(options): PropertyDecorator { return (target, key) => Reflect.defineMetadata("custom:annotation", options, target, key); } 
function deleteMetadata
deleteMetadata: {    (metadataKey: any, target: Object): boolean;    (metadataKey: any, target: Object, propertyKey: string | symbol): boolean;    (metadataKey: any, target: Object): boolean;    (metadataKey: any, target: Object, propertyKey: string | symbol): boolean;};- Deletes the metadata entry from the target object with the provided key. - Parameter metadataKey- A key used to store and retrieve metadata. - Parameter target- The target object on which the metadata is defined. - Returns- trueif the metadata entry was found and deleted; otherwise, false.- Example 1- class Example { } - // constructor result = Reflect.deleteMetadata("custom:annotation", Example); 
- Deletes the metadata entry from the target object with the provided key. - Parameter metadataKey- A key used to store and retrieve metadata. - Parameter target- The target object on which the metadata is defined. - Parameter propertyKey- The property key for the target. - Returns- trueif the metadata entry was found and deleted; otherwise, false.- Example 1- class Example { // property declarations are not part of ES6, though they are valid in TypeScript: // static staticProperty; // property; - static staticMethod(p) { } method(p) { } } - // property (on constructor) result = Reflect.deleteMetadata("custom:annotation", Example, "staticProperty"); - // property (on prototype) result = Reflect.deleteMetadata("custom:annotation", Example.prototype, "property"); - // method (on constructor) result = Reflect.deleteMetadata("custom:annotation", Example, "staticMethod"); - // method (on prototype) result = Reflect.deleteMetadata("custom:annotation", Example.prototype, "method"); 
function getMetadata
getMetadata: {    (metadataKey: any, target: Object): any;    (metadataKey: any, target: Object, propertyKey: string | symbol): any;    (metadataKey: any, target: Object): any;    (metadataKey: any, target: Object, propertyKey: string | symbol): any;};- Gets the metadata value for the provided metadata key on the target object or its prototype chain. - Parameter metadataKey- A key used to store and retrieve metadata. - Parameter target- The target object on which the metadata is defined. - Returns- The metadata value for the metadata key if found; otherwise, - undefined.- Example 1- class Example { } - // constructor result = Reflect.getMetadata("custom:annotation", Example); 
- Gets the metadata value for the provided metadata key on the target object or its prototype chain. - Parameter metadataKey- A key used to store and retrieve metadata. - Parameter target- The target object on which the metadata is defined. - Parameter propertyKey- The property key for the target. - Returns- The metadata value for the metadata key if found; otherwise, - undefined.- Example 1- class Example { // property declarations are not part of ES6, though they are valid in TypeScript: // static staticProperty; // property; - static staticMethod(p) { } method(p) { } } - // property (on constructor) result = Reflect.getMetadata("custom:annotation", Example, "staticProperty"); - // property (on prototype) result = Reflect.getMetadata("custom:annotation", Example.prototype, "property"); - // method (on constructor) result = Reflect.getMetadata("custom:annotation", Example, "staticMethod"); - // method (on prototype) result = Reflect.getMetadata("custom:annotation", Example.prototype, "method"); 
function getMetadataKeys
getMetadataKeys: {    (target: Object): any[];    (target: Object, propertyKey: string | symbol): any[];    (target: Object): any[];    (target: Object, propertyKey: string | symbol): any[];};- Gets the metadata keys defined on the target object or its prototype chain. - Parameter target- The target object on which the metadata is defined. - Returns- An array of unique metadata keys. - Example 1- class Example { } - // constructor result = Reflect.getMetadataKeys(Example); 
- Gets the metadata keys defined on the target object or its prototype chain. - Parameter target- The target object on which the metadata is defined. - Parameter propertyKey- The property key for the target. - Returns- An array of unique metadata keys. - Example 1- class Example { // property declarations are not part of ES6, though they are valid in TypeScript: // static staticProperty; // property; - static staticMethod(p) { } method(p) { } } - // property (on constructor) result = Reflect.getMetadataKeys(Example, "staticProperty"); - // property (on prototype) result = Reflect.getMetadataKeys(Example.prototype, "property"); - // method (on constructor) result = Reflect.getMetadataKeys(Example, "staticMethod"); - // method (on prototype) result = Reflect.getMetadataKeys(Example.prototype, "method"); 
function getOwnMetadata
getOwnMetadata: {    (metadataKey: any, target: Object): any;    (metadataKey: any, target: Object, propertyKey: string | symbol): any;    (metadataKey: any, target: Object): any;    (metadataKey: any, target: Object, propertyKey: string | symbol): any;};- Gets the metadata value for the provided metadata key on the target object. - Parameter metadataKey- A key used to store and retrieve metadata. - Parameter target- The target object on which the metadata is defined. - Returns- The metadata value for the metadata key if found; otherwise, - undefined.- Example 1- class Example { } - // constructor result = Reflect.getOwnMetadata("custom:annotation", Example); 
- Gets the metadata value for the provided metadata key on the target object. - Parameter metadataKey- A key used to store and retrieve metadata. - Parameter target- The target object on which the metadata is defined. - Parameter propertyKey- The property key for the target. - Returns- The metadata value for the metadata key if found; otherwise, - undefined.- Example 1- class Example { // property declarations are not part of ES6, though they are valid in TypeScript: // static staticProperty; // property; - static staticMethod(p) { } method(p) { } } - // property (on constructor) result = Reflect.getOwnMetadata("custom:annotation", Example, "staticProperty"); - // property (on prototype) result = Reflect.getOwnMetadata("custom:annotation", Example.prototype, "property"); - // method (on constructor) result = Reflect.getOwnMetadata("custom:annotation", Example, "staticMethod"); - // method (on prototype) result = Reflect.getOwnMetadata("custom:annotation", Example.prototype, "method"); 
function getOwnMetadataKeys
getOwnMetadataKeys: {    (target: Object): any[];    (target: Object, propertyKey: string | symbol): any[];    (target: Object): any[];    (target: Object, propertyKey: string | symbol): any[];};- Gets the unique metadata keys defined on the target object. - Parameter target- The target object on which the metadata is defined. - Returns- An array of unique metadata keys. - Example 1- class Example { } - // constructor result = Reflect.getOwnMetadataKeys(Example); 
- Gets the unique metadata keys defined on the target object. - Parameter target- The target object on which the metadata is defined. - Parameter propertyKey- The property key for the target. - Returns- An array of unique metadata keys. - Example 1- class Example { // property declarations are not part of ES6, though they are valid in TypeScript: // static staticProperty; // property; - static staticMethod(p) { } method(p) { } } - // property (on constructor) result = Reflect.getOwnMetadataKeys(Example, "staticProperty"); - // property (on prototype) result = Reflect.getOwnMetadataKeys(Example.prototype, "property"); - // method (on constructor) result = Reflect.getOwnMetadataKeys(Example, "staticMethod"); - // method (on prototype) result = Reflect.getOwnMetadataKeys(Example.prototype, "method"); 
function hasMetadata
hasMetadata: {    (metadataKey: any, target: Object): boolean;    (metadataKey: any, target: Object, propertyKey: string | symbol): boolean;    (metadataKey: any, target: Object): boolean;    (metadataKey: any, target: Object, propertyKey: string | symbol): boolean;};- Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined. - Parameter metadataKey- A key used to store and retrieve metadata. - Parameter target- The target object on which the metadata is defined. - Returns- trueif the metadata key was defined on the target object or its prototype chain; otherwise,- false.- Example 1- class Example { } - // constructor result = Reflect.hasMetadata("custom:annotation", Example); 
- Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined. - Parameter metadataKey- A key used to store and retrieve metadata. - Parameter target- The target object on which the metadata is defined. - Parameter propertyKey- The property key for the target. - Returns- trueif the metadata key was defined on the target object or its prototype chain; otherwise,- false.- Example 1- class Example { // property declarations are not part of ES6, though they are valid in TypeScript: // static staticProperty; // property; - static staticMethod(p) { } method(p) { } } - // property (on constructor) result = Reflect.hasMetadata("custom:annotation", Example, "staticProperty"); - // property (on prototype) result = Reflect.hasMetadata("custom:annotation", Example.prototype, "property"); - // method (on constructor) result = Reflect.hasMetadata("custom:annotation", Example, "staticMethod"); - // method (on prototype) result = Reflect.hasMetadata("custom:annotation", Example.prototype, "method"); 
function hasOwnMetadata
hasOwnMetadata: {    (metadataKey: any, target: Object): boolean;    (metadataKey: any, target: Object, propertyKey: string | symbol): boolean;    (metadataKey: any, target: Object): boolean;    (metadataKey: any, target: Object, propertyKey: string | symbol): boolean;};- Gets a value indicating whether the target object has the provided metadata key defined. - Parameter metadataKey- A key used to store and retrieve metadata. - Parameter target- The target object on which the metadata is defined. - Returns- trueif the metadata key was defined on the target object; otherwise,- false.- Example 1- class Example { } - // constructor result = Reflect.hasOwnMetadata("custom:annotation", Example); 
- Gets a value indicating whether the target object has the provided metadata key defined. - Parameter metadataKey- A key used to store and retrieve metadata. - Parameter target- The target object on which the metadata is defined. - Parameter propertyKey- The property key for the target. - Returns- trueif the metadata key was defined on the target object; otherwise,- false.- Example 1- class Example { // property declarations are not part of ES6, though they are valid in TypeScript: // static staticProperty; // property; - static staticMethod(p) { } method(p) { } } - // property (on constructor) result = Reflect.hasOwnMetadata("custom:annotation", Example, "staticProperty"); - // property (on prototype) result = Reflect.hasOwnMetadata("custom:annotation", Example.prototype, "property"); - // method (on constructor) result = Reflect.hasOwnMetadata("custom:annotation", Example, "staticMethod"); - // method (on prototype) result = Reflect.hasOwnMetadata("custom:annotation", Example.prototype, "method"); 
function metadata
metadata: {    (metadataKey: any, metadataValue: any): {        (target: Function): void;        (target: Object, propertyKey: string | symbol): void;    };    (metadataKey: any, metadataValue: any): {        (target: Function): void;        (target: Object, propertyKey: string | symbol): void;    };};- A default metadata decorator factory that can be used on a class, class member, or parameter. - Parameter metadataKey- The key for the metadata entry. - Parameter metadataValue- The value for the metadata entry. - Returns- A decorator function. - Remarks- If - metadataKeyis already defined for the target and target key, the metadataValue for that key will be overwritten.- Example 1- // constructor @Reflect.metadata(key, value) class Example { } - // property (on constructor, TypeScript only) class Example { @Reflect.metadata(key, value) static staticProperty; } - // property (on prototype, TypeScript only) class Example { @Reflect.metadata(key, value) property; } - // method (on constructor) class Example { @Reflect.metadata(key, value) static staticMethod() { } } - // method (on prototype) class Example { @Reflect.metadata(key, value) method() { } } 
Package Files (1)
Dependencies (0)
No dependencies.
Dev Dependencies (15)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/reflect-metadata.
- Markdown[](https://www.jsdocs.io/package/reflect-metadata)
- HTML<a href="https://www.jsdocs.io/package/reflect-metadata"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
 Package analyzed in 4107 ms.
- Missing or incorrect documentation? Open an issue for this package.
