Skip to content

Commit

Permalink
Merge pull request #144 from rbuckton/lite-mode
Browse files Browse the repository at this point in the history
Add /lite and /no-conflict exports
  • Loading branch information
rbuckton authored Dec 13, 2023
2 parents f16259f + 7391602 commit 6ef3aed
Show file tree
Hide file tree
Showing 33 changed files with 5,667 additions and 2,523 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
.vscode/
node_modules/
test/**/*.js
test/**/*.js.map
test/**/*.js.map
index.d.mts
no-conflict.d.mts
*.js
*.js.map
*.mjs
*.mjs.map
6 changes: 6 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
.vscode
node_modules
out
docs
spec
temp
test
typings
bower.json
gulpfile.js
globals.d.ts
Reflect.ts
Reflect.js.map
ReflectLite.ts
ReflectLite.js.map
ReflectNoConflict.ts
ReflectNoConflict.js.map
spec.html
tsconfig.json
tsconfig-release.json
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Metadata Reflection API

NOTE: Now that both [Decorators](https://github.com/tc39/proposal-decorators) and
[Decorator Metadata](https://github.com/tc39/proposal-decorator-metadata) have achieved Stage 3 within TC39, the API
proposed below is no longer being considered for standardization. However, this package will continue to support
projects that leverage TypeScript's legacy `--experimentalDecorators` option as some projects may not be able to migrate
to use standard decorators.

* [Detailed proposal][Metadata-Spec]

## Installation
Expand All @@ -8,6 +14,53 @@
npm install reflect-metadata
```

## Usage

### ES Modules in NodeJS/Browser, TypeScript/Babel, Bundlers
```ts
// - Modifies global `Reflect` object (or defines one in ES5 runtimes).
// - Supports ESM and CommonJS.
// - Contains internal polyfills for `Map`, `Set`, and `WeakMap` for older runtimes.
import "reflect-metadata";

// - Modifies global `Reflect` object (or defines one in ES5 runtimes).
// - Supports ESM and CommonJS.
// - Requires runtime support for `"exports"` in `package.json`.
// - Does not include internal polyfills.
import "reflect-metadata/lite";
```

### CommonJS
```ts
// - Modifies global `Reflect` object (or defines one in ES5 runtimes).
// - Contains internal polyfills for `Map`, `Set`, and `WeakMap` for older runtimes.
require("reflect-metadata");

// - Modifies global `Reflect` object (or defines one in ES5 runtimes).
// - Requires runtime support for `"exports"` in `package.json`.
// - Does not include internal polyfills.
require("reflect-metadata/lite");
```

### In the Browser via `<script>`
**HTML**
```html
<!-- Modifies global `Reflect` object (or defines one in ES5 runtimes). -->
<!-- Contains internal polyfills for `Map`, `Set`, and `WeakMap` for older runtimes. -->
<script src="path/to/reflect-metadata/Reflect.js"></script>

<!-- Modifies global `Reflect` object (or defines one in ES5 runtimes). -->
<!-- Does not include internal polyfills. -->
<script src="path/to/reflect-metadata/ReflectLite.js"></script>
```

**Script**
```js
// - Makes types available in your editor.
/// <reference path="path/to/reflect-metadata/standalone.d.ts" />

```

## Background

* Decorators add the ability to augment a class and its members as the class is defined, through a declarative syntax.
Expand Down
Loading

0 comments on commit 6ef3aed

Please sign in to comment.