rewrite-module
Rewrite a module's exports by applying string transformations, then return for immediate use! No
eval()
!
Install
$ npm install --save rewrite-module
Usage
// foobar.jsexportsfoo = 'FOOBAR_foo';exportsbar = 'FOOBAR_bar';
const join = ;const read = readFileSync;const rewriteModule = ; const file = ;const data = ; ;//=> {foo: 'foobar_foo', bar: 'foobar_bar'}
API
rewriteModule(options)
Returns a new, useable module that's comprised of the contents
you provided. The return-module directly reflects the input given; so any defined exports
will be available as object keys.
Note: You can receive a
function
instead of anobject
if that's what you defined. Perhaps a refresher on exports?
options.data
Type: string
Required: true
The transformed string to be evaluated in a new VM.
options.file
Type: string
The original module's filepath.
License
MIT © Luke Edwards