2.0.1 • Published 3 years ago

@tadashi/injection v2.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
3 years ago

Injection

NPM version Build Status Coverage Status XO code style

Inject data into file

Install

$ npm i -S @tadashi/injection

Sample

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

const a = 'Horray';
alert(a);

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

<body>
  <script>/* inject: ./script.js */</script>
</body>

Making injection specifying the output file

const injection = require('@tadashi/injection');

(async () => {
  await injection('./input.html', './output.html', '\/\\*\\sinject:\\s([\\w./]+)\\s\\*\\/')
})()

Result: output.html

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

API

injection(input, output)

NameTypeRequiredDefaultDescription
inputstringyes-Source file
outputstringno./outResult file
patternstringno<!--\\sinject:\\s([\\w./]+)\\s-->RegExp pattern

License

MIT © Thiago Lagden