# inject-decorator

> Create decorators that can inject anything into your JS modules!

Latest version **0.0.2** (published 2017-04-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install inject-decorator
pnpm add inject-decorator
yarn add inject-decorator
bun add inject-decorator
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2017-04-01 |
| First published | 2017-04-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Joe Lee |
| Maintainers | bbmoz |
| Keywords | es6, es7, es2015, es2016, babel, decorators, annotations, dom, inject |

## Links

- npm: https://www.npmjs.com/package/inject-decorator
- Repository: https://github.com/bbmoz/inject-decorator
- Issues: https://github.com/bbmoz/inject-decorator/issues
- npm.io page: https://npm.io/package/inject-decorator

## Recent versions

- 0.0.2 (latest) — 2017-04-01
- 0.0.1 — 2017-04-01

## README

# Inject Decorator [![npm version](https://badge.fury.io/js/inject-decorator.svg)](https://badge.fury.io/js/inject-decorator) [![Build Status](https://travis-ci.org/bbmoz/inject-decorator.svg)](https://travis-ci.org/bbmoz/inject-decorator)

> Create decorators that can inject anything into your JS modules!

## Example using DOM elements

Define an object that represents some dom elements, call the library with it, and then use it to decorate a class as shown below. Elements are attached to `$` of the class.

```javascript
// part 1
import inject from 'inject-decorator'

const domElements = {
  heading: document.getElementById('heading'),
  footer: document.querySelector('footer')
}

export default inject(domElements)
```

```javascript
// part 2
import dom from './dom'

@dom('heading')
class Hello {
    constructor (text) {
        this.$heading = Hello.$.heading
        this._displayDomElements(text)
    }

    _displayDomElements (text) {
        this.$heading.innerHTML = text
        this.$heading.style = 'display: block'
    }
}
```

To inject more elements than just `heading`, simply comma delimit i.e. `@dom('heading', 'footer')`. Or if you want access to all elements, use `@dom` without any arguments.

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