# @voliware/node-inject

> Inject data into another file using tags

Latest version **0.1.3** (published 2019-10-29) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @voliware/node-inject
pnpm add @voliware/node-inject
yarn add @voliware/node-inject
bun add @voliware/node-inject
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.1.3 |
| Published | 2019-10-29 |
| First published | 2019-10-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 14.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Anthony Agostino |
| Maintainers | tones31 |
| Keywords | inject, node-inject, voliware |

## Links

- npm: https://www.npmjs.com/package/@voliware/node-inject
- Repository: https://github.com/Voliware/node-inject
- Homepage: https://github.com/Voliware/node-inject#readme
- Issues: https://github.com/Voliware/node-inject/issues
- npm.io page: https://npm.io/package/@voliware/node-inject

## Dependencies (1)

- [@voliware/logger](https://npm.io/package/@voliware/logger.md) ^1.5.0

## Recent versions

- 0.1.3 (latest) — 2019-10-29
- 0.1.2 — 2019-10-29
- 0.1.1 — 2019-10-25
- 0.1.0 — 2019-10-25

## README

# node-inject
Inject data into another file based on tags

# How to Use it
Suppose you want to inject HTML templates into a main HTML file. For example, you are building a shop page and you want to inject a shopping cart icon and an item list table.

**/templates/itemlist.html**
```html
<table id="itemlist">
    <thead>
        <tr>
            <th>Name</th>
            <th>Price</th>
        </tr>
    </thead>
</table>
```
**/templates/shoppingcart.html**
```html
<div id="shoppingcart">
    <div id="carticon"></div>
    <div id="itemcount"></div>
    <div id="paynow"></div>
</div>
```

Into a main HTML file

**/templates/index.html**
```html
<!doctype html>
<html lang="en">
    <head>
        <title>Shop</title>
    </head>
    <body>
        <!-- inject:itemlist -->
        <!-- inject:shoppingcart -->
    </body>
</html>
```

Just write and execute the following code
```js
const Inject = require('@voliware/node-inject');
let inject = new Inject()
    .inject("./templates/itemlist.html", 'itemlist')
    .inject("./templates/shoppingcart.html", 'shoppingcart')
    .into("./templates/index.html")
    .saveas("./index.html")
    .run();
```

And you'll end up with
```html
<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <title>Shop</title>
    </head>
    <body>
        <table id="itemlist">
            <thead>
                <tr>
                    <th>Name</th>
                    <th>Price</th>
                </tr>
            </thead>
        </table>
        <div id="shoppingcart">
            <div id="carticon"></div>
            <div id="itemcount"></div>
            <div id="paynow"></div>
        </div>
    </body>
</html>
```

## Node
Install with node package manager
```js
npm install @voliware/node-inject
```
Include in a file
```js
const Inject = require('@voliware/node-inject');
```

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