Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/abraham/reflection
Lightweight (3K) ES Module implementation of reflect-metadata
https://github.com/abraham/reflection
decorators hacktoberfest javascript metadata reflect-metadata typescript
Last synced: 25 days ago
JSON representation
Lightweight (3K) ES Module implementation of reflect-metadata
- Host: GitHub
- URL: https://github.com/abraham/reflection
- Owner: abraham
- License: mit
- Created: 2018-07-23T16:00:38.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2024-05-01T07:02:09.000Z (6 months ago)
- Last Synced: 2024-10-05T08:01:17.166Z (about 1 month ago)
- Topics: decorators, hacktoberfest, javascript, metadata, reflect-metadata, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@abraham/reflection
- Size: 479 KB
- Stars: 263
- Watchers: 6
- Forks: 14
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
[![Version Status](https://img.shields.io/npm/v/@abraham/reflection.svg?style=flat&label=version&colorB=4bc524)](https://npmjs.com/package/@abraham/reflection)
[![Build Status](https://github.com/abraham/reflection/workflows/Index/badge.svg)](https://github.com/abraham/reflection/actions)
[![npm bundle size (minified + gzip)](https://img.shields.io/bundlephobia/minzip/@abraham/reflection.svg?style=flat&colorB=4bc524)](https://bundlephobia.com/result?p=@abraham/reflection)
[![Coverage Status](https://coveralls.io/repos/github/abraham/reflection/badge.svg?branch=master)](https://coveralls.io/github/abraham/reflection?branch=master)# Reflection
Lightweight ES Module implementation of [reflect-metadata](https://github.com/rbuckton/reflect-metadata/) to work with TypeScript's [experimental decorator support](https://www.typescriptlang.org/docs/handbook/decorators.html).
## Why?
The main reason for this library is to provide a much smaller implementation that can be included as a module.
- ES module
- `reflection` can be loaded with ``
- Size (uncompressed)
- [`reflect-metadata`](https://github.com/rbuckton/reflect-metadata) is ~50K
- [`core-js/es7/reflect`](https://github.com/zloirock/core-js) is ~80K
- `@abraham/reflection` is ~3KRead about how to [drop 20K from your production Angular app](https://bendyworks.com/blog/drop-20k-from-your-production-angular-app) by switching to this.
## Install
```sh
npm install @abraham/reflection
```## Usage
```ts
import '@abraham/reflection';
Reflect.defineMetadata(metadataKey, metadataValue, target);
```You can also import `Reflection`:
```ts
import { Reflection as Reflect } from '@abraham/reflection';
Reflect.defineMetadata(metadataKey, metadataValue, target);
```## API
Reflection does not currently cover the complete API surface of reflect-metadata. The following methods are available:
```ts
Reflect.decorate(...);
Reflect.defineMetadata(...);
Reflect.getMetadata(...);
Reflect.hasMetadata(...);
Reflect.getOwnMetadata(...);
Reflect.hasOwnMetadata(...);
Reflect.metadata(...);
```