0.1.1 • Published 5 years ago
@ganuz/get-own-metadata v0.1.1
@ganuz/get-own-metadata
Get Own Metadata is package from Ganuz library
Install
$ yarn add @ganuz/get-own-metadata
Or
$ npm install --save @ganuz/get-own-metadata
Use
Module
import {
default as getOwnMetadata
} from '@ganuz/get-own-metadata';
Browser
<script src="https://unpkg.com/@ganuz/get-own-metadata/bundle.umd.min.js"></script>
let {
getOwnMetadata
} = G;
Examples
getOwnMetadata('key', null, 'prop'); // throw TypeError
getOwnMetadata('key', {}); // => undefined
class Some{ @Metadata('foo', 'bar') static prop: string; }
getOwnMetadata('foo', Some, 'prop'); // => 'bar'
@Metadata('foo', 'bar')
class A {
@Metadata('name', 'bob') prop: string;
}
@Metadata('num', -97)
class B extends A {
@Metadata('name', 'alice') prop: string;
}
getOwnMetadata('foo', A); // => 'bar'
getOwnMetadata('num', A); // => undefined
getOwnMetadata('name', A.prototype, 'prop'); // => 'bob'
getOwnMetadata('foo', B); // => undefined
getOwnMetadata('num', B); // => -97
getOwnMetadata('name', B.prototype, 'prop'); // => 'alice'
Note: It is based on es6 WeakMap
and Map
no need for polyfill (built-in library support).
License
Copyright © Yisrael Eliev, Licensed under the MIT license.