0.1.1 • Published 5 years ago
@ganuz/get-own-metadata-keys v0.1.1
@ganuz/get-own-metadata-keys
Get Own Metadata Keys is package from Ganuz library
Install
$ yarn add @ganuz/get-own-metadata-keys
Or
$ npm install --save @ganuz/get-own-metadata-keys
Use
Module
import {
default as getOwnMetadataKeys
} from '@ganuz/get-own-metadata-keys';
Browser
<script src="https://unpkg.com/@ganuz/get-own-metadata-keys/bundle.umd.min.js"></script>
let {
getOwnMetadataKeys
} = G;
Examples
getOwnMetadataKeys(null); // throw TypeError
getOwnMetadataKeys({}); // => []
class C{ @Metadata(Number, 0) prop: string; }
getOwnMetadataKeys(C.prototype, 'prop'); // => [Number]
class Some {}
class Other extends Some{}
defineMetadata(Number, 777, Some);
defineMetadata('foo', 'bar', Some);
defineMetadata('color', 'blue', Some, 'prop');
defineMetadata(Object, null, Some, 'prop');
defineMetadata(String, 'word', Other);
defineMetadata(Function, Object, Other);
defineMetadata('color', 'red', Other, 'prop');
getOwnMetadataKeys(Some); => [Number, 'foo']
getOwnMetadataKeys(Some, 'prop'); => ['color', Object]
getOwnMetadataKeys(Other); => [String, Function]
getOwnMetadataKeys(Other, 'prop'); => ['color']
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.