@bjorkhaug/sreflect
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

Reflect-metadata adapted to Symbol.metadata

This implementation does not follow spec completely, but implements some of the ideas
from tc39 proposals of decorator metadata and reflect-metadata.

Use at your own risk / caution.

Credit to: https://github.com/rbuckton/reflect-metadata/

Typescript must emit metadata for this to work and the polyfill must be imported at the very
entrypoint to your application.

Example of use


/**
 * Note: it is important to add sreflect to the very
 * beginning of your app to polyfill Reflect
 */
import '@bjorkhaug/sreflect'

// Define metadata on an object
const obj = {}
Reflect.defineMetadata('key', 'value', obj)

// Check if the object has the defined metadata
if (Reflect.hasMetadata('key', obj)) {
  // Metadata exists!
}

// Get the metadata value
const value = Reflect.getMetadata('key', obj)

// Get all metadata keys
const keys = Reflect.getMetadataKeys(obj)

// Delete the metadata
Reflect.deleteMetadata('key', obj)

// Use the decorate function
const decorators = [
  function (target: any) {
    // ...
  },
]
Reflect.decorate(decorators, obj)

Readme

Keywords

none

Package Sidebar

Install

npm i @bjorkhaug/sreflect

Weekly Downloads

33

Version

0.0.2

License

MIT

Unpacked Size

19.6 kB

Total Files

44

Last publish

Collaborators

  • simenbjorkhaug