Skip to content

lagden/injection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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][, 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