@keenondrums/metadata-utils
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

metadata-utils Build Status Coverage Status Tweet

Convenience utils for reflected metadata.

Installation

  1. Run

    npm i @keenondrums/metadata-utils reflect-metadata
  2. Add import 'reflect-metadata' to the root of your application

API

getMetadataAndCache

Gets metadata from the prototype (using Relect.getMetadata) and sets it as own metadata. Useful to enhance performance for retrieving metadata from ancestors. Has the same signature as Relect.getMetadata.

import 'reflect-metadata'
import { getMetadataAndCache } from '@keenondrums/metadata-utils'

class Parent {}
Reflect.defineMetadata('key', 'value', Parent)

Reflect.getOwnMetadata('key', Parent) // returns 'value'
getMetadataAndCache('key', Parent) // returns 'value', basically calls Reflect.getOwnMetadata under the hood and does nothing else in this case

class Child extends Parent {}

Reflect.getOwnMetadata('key', Child) // returns `undefined` as Child doesn't have any own metadata for 'key'
getMetadataAndCache('key', Child) // returns 'value' from Parent and set it as own metadata
Reflect.getOwnMetadata('key', Child) // now it returns 'value'

Package Sidebar

Install

npm i @keenondrums/metadata-utils

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

10.1 kB

Total Files

11

Last publish

Collaborators

  • keenondrums
  • aigoncharov