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: 23 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 (almost 7 years ago)
- Default Branch: main
- Last Pushed: 2025-03-08T21:43:23.000Z (3 months ago)
- Last Synced: 2025-05-08T15:50:21.699Z (29 days ago)
- Topics: decorators, hacktoberfest, javascript, metadata, reflect-metadata, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@abraham/reflection
- Size: 490 KB
- Stars: 275
- Watchers: 6
- Forks: 16
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
[](https://npmjs.com/package/@abraham/reflection)
[](https://github.com/abraham/reflection/actions)
[](https://bundlephobia.com/result?p=@abraham/reflection)
[](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(...);
```