# reflect-annotations

> Set and inspect annotation metadata on JavaScript classes and methods

Latest version **4.0.0-beta.1** (published 2023-04-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install reflect-annotations
pnpm add reflect-annotations
yarn add reflect-annotations
bun add reflect-annotations
```

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 4.0.0-beta.1 |
| Published | 2023-04-23 |
| First published | 2016-07-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=4.0.0 |
| Dependencies | 0 |
| Unpacked size | 40.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Caleb Boyd |
| Maintainers | calebboyd |
| Keywords | annotations, decorators, class decorators, class annotations, annotation, decorator, class reflection, reflection |

## Links

- npm: https://www.npmjs.com/package/reflect-annotations
- Repository: https://github.com/ingress/ingress
- Homepage: https://github.com/ingress/ingress#readme
- Issues: https://github.com/ingress/ingress/issues
- npm.io page: https://npm.io/package/reflect-annotations

## Alternatives

- [localforage](https://npm.io/package/localforage.md) — 6.2M weekly downloads
- [localforage-observable](https://npm.io/package/localforage-observable.md) — 30.8K weekly downloads
- [@y/y](https://npm.io/package/@y/y.md) — 30.1K weekly downloads
- [@metaobjectsdev/render](https://npm.io/package/@metaobjectsdev/render.md) — 3.5K weekly downloads
- [@ledgerhq/coin-algorand](https://npm.io/package/@ledgerhq/coin-algorand.md) — 1.1K weekly downloads

## Recent versions

- 4.0.0-beta.1 (latest) — 2023-04-23
- 4.0.0-alpha.9 — 2022-02-04
- 4.0.0-alpha.8 — 2022-02-04
- 4.0.0-alpha.7 — 2022-02-04
- 4.0.0-alpha.6 — 2022-01-20
- 4.0.0-alpha.4 — 2022-01-20
- 4.0.0-alpha.3 — 2021-04-03
- 4.0.0-alpha.2 — 2021-02-22
- 4.0.0-alpha.1 — 2021-02-22
- 4.0.0-alpha.0 — 2021-02-22
- 3.5.0 — 2021-01-28
- 3.4.0 — 2021-01-19
- 3.3.0 — 2020-12-24
- 3.2.1 — 2020-10-28
- 3.2.0 — 2020-10-26
- … 34 more at https://npm.io/package/reflect-annotations/versions

## README

## reflect-annotations

Annotations are namespaced [metadata](https://www.npmjs.com/package/reflect-metadata) fields used for defining non-destructive runtime metadata on classes, methods and parameters.

### Example
```javascript
import { createAnnotationFactory, reflectAnnotations } from 'reflect-annotations'

function ExampleAnnotation (name, size) {
  this.name = name
  this.size = size
}
function ExampleAnnotation2 (name, size) {
  this.name = name
  this.size = size
}

const Example = createAnnotationFactory(ExampleAnnotation)
const Example2 = createAnnotationFactory(ExampleAnnotation2)

class MyClass {
  @Example('test', 42)
  @Example2('test', 42)
  method(@Example() a, b, @Example2() c) {
    //do something
  }
}
console.log(reflectAnnotations(MyClass))
//[{
//  name: 'method',
//  declaredOrder: true,
//  classAnnotations: [],
//  methodAnnotations: [ ExampleAnnotation {}, ExampleAnnotation2 {} ],
//  parameterAnnotations: [ ExampleAnnotation {}, undefined, ExampleAnnotation2 {} ]
//}]
console.log(reflectAnnotations(MyClass, { declaredOrder: false }))
//[{
//  name: 'method',
//  declaredOrder: false,
//  classAnnotations: [],
//  methodAnnotations: [ ExampleAnnotation2 {}, ExampleAnnotation {} ],
//  parameterAnnotations: [ ExampleAnnotation {}, undefined, ExampleAnnotation2 {} ]
//}]
```

In the above example a decorator is created when `Example` is invoked at parse time. The decorator adds an `ExampleAnnotation` _instance_ to the target's list of annotations. These "Annotations" are non destructive metadata.

By default annotations are processed in "declared order" this is the order that they're declared (top to bottom) The opposite of this order would be "parsed order" which is the order that the javascript engine executes them.

The order they're recorded in can be adjusted by passing the `{ declaredOrder: false }` as a second optional options argument.

### Requirements
- [reflect-metadata](https://www.npmjs.com/package/reflect-metadata) polyfill
- TypeScript OR this [Babel plugin](https://www.npmjs.com/package/babel-plugin-transform-decorators-legacy)

---
_Source: https://npm.io/package/reflect-annotations · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
