# es-injector

> Tiny tool for dynamically injecting javascript code on your page. Written on ES5, so You even don't need Babel in your project.

Latest version **1.0.3** (published 2018-10-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install es-injector
pnpm add es-injector
yarn add es-injector
bun add es-injector
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2018-10-21 |
| First published | 2018-10-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Igor Filippov |
| Maintainers | igorfilippov3 |
| Keywords | script, inject, dynamically, es5, promise |

## Links

- npm: https://www.npmjs.com/package/es-injector
- npm.io page: https://npm.io/package/es-injector

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.0.3 (latest) — 2018-10-21
- 1.0.2 — 2018-10-21
- 1.0.1 — 2018-10-21
- 1.0.0 — 2018-10-21

## README

# es-injector
Tiny tool for dynamically injecting javascript code on your page. 
Written on ES5, so You even don't need Babel in your project.

Creates promise which appends script tag on the page. Waits when code will be loaded
and then resolves. If load time tooks to long (3 sec by default) - rejects.

## Install
npm install es-injector --save

## Usage

```js
import esInjector from "es-injector";

const config = {
  src: "https://www.google.com/recaptcha/api.js", // required
  variableName: "grecaptcha", // required
  variableMethod: ["execute", "render"] // optional, if need
  // see other params in Params scheme
};

esInjector.inject(config)
  .then(
    () => console.log(grecaptcha, "Script loaded!"),
    () => console.log("Connection timed out!")
  );
```

## Params scheme
If load time took more time than You specifyed in config.waitTime (3 seconds by default) the promise will be rejected.

```js
/**
  * @param {object} config - (required)
  * @param {string} config.src - (required)
  * @param {string} config.variableName - (required)
  * @param {string[]} config.varibableMethod - (optional)
  * @param {boolean} config.defer - (optional)
  * @param {boolean} config.async - (optional)
  * @param {number} config.waitTime - (optional)
*/
```

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