https://github.com/lagden/injection
Inject data into file
https://github.com/lagden/injection
data file inject nodejs
Last synced: 2 months ago
JSON representation
Inject data into file
- Host: GitHub
- URL: https://github.com/lagden/injection
- Owner: lagden
- License: mit
- Created: 2018-10-17T07:32:44.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-03-04T02:55:31.000Z (over 3 years ago)
- Last Synced: 2025-10-21T17:12:58.004Z (8 months ago)
- Topics: data, file, inject, nodejs
- Language: JavaScript
- Size: 1.1 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Injection
[![NPM version][npm-img]][npm]
[![Build Status][ci-img]][ci]
[![Coverage Status][coveralls-img]][coveralls]
[![XO code style][xo-img]][xo]
[npm-img]: https://img.shields.io/npm/v/@tadashi/injection.svg
[npm]: https://www.npmjs.com/package/@tadashi/injection
[ci-img]: https://travis-ci.org/lagden/injection.svg
[ci]: https://travis-ci.org/lagden/injection
[coveralls-img]: https://coveralls.io/repos/github/lagden/injection/badge.svg?branch=master
[coveralls]: https://coveralls.io/github/lagden/injection?branch=master
[xo-img]: https://img.shields.io/badge/code_style-XO-5ed9c7.svg
[xo]: https://github.com/sindresorhus/xo
Inject data into file
## Install
```
$ npm i -S @tadashi/injection
```
## Sample
This is the file that will be inject: `script.js`
```js
const a = 'Horray';
alert(a);
```
This is the source file with the markup showing where is the place will be injected: `input.html`
```html
/* inject: ./script.js */
```
Making injection specifying the output file
```js
const injection = require('@tadashi/injection');
(async () => {
await injection('./input.html', './output.html', '\/\\*\\sinject:\\s([\\w./]+)\\s\\*\\/')
})()
```
Result: `output.html`
```html
const a = 'Horray';alert(a);
```
### API
#### injection(input[, output][, pattern])
Name | Type | Required | Default | Description
----------- | -------------------- | :---------: | :---------------------------------: | ------------
input | string | yes | - | Source file
output | string | no | ./out | Result file
pattern | string | no | `` | RegExp pattern
## License
MIT © [Thiago Lagden](https://github.com/lagden)