项目作者: lagden

项目描述 :
Inject data into file
高级语言: JavaScript
项目地址: git://github.com/lagden/injection.git
创建时间: 2018-10-17T07:32:44Z
项目社区:https://github.com/lagden/injection

开源协议:MIT License

下载


Injection

@tadashi/injection"">NPM version
Build Status
Coverage Status
XO code style

Inject data into file

Install

  1. $ npm i -S @tadashi/injection

Sample

This is the file that will be inject: script.js

  1. const a = 'Horray';
  2. alert(a);

This is the source file with the markup showing where is the place will be injected: input.html

  1. <body>
  2. <script>/* inject: ./script.js */</script>
  3. </body>

Making injection specifying the output file

  1. const injection = require('@tadashi/injection');
  2. (async () => {
  3. await injection('./input.html', './output.html', '\/\\*\\sinject:\\s([\\w./]+)\\s\\*\\/')
  4. })()

Result: output.html

  1. <body><script>const a = 'Horray';alert(a);</script></body>

API

injection(input[, output][, pattern])

Name Type Required Default Description
input string yes - Source file
output string no ./out Result file
pattern string no <!--\\sinject:\\s([\\w./]+)\\s--> RegExp pattern

License

MIT © Thiago Lagden