JSPM

import-modify

3.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q26677F
  • License MIT

Modify the source of an imported module

Package Exports

  • import-modify

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (import-modify) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

import-modify Build Status

Modify the source of an imported module

Install

$ npm install --save import-modify

Usage

Replace some text

// greet.js
module.exports = () => {
    console.log('hello');
};
const importModify = require('import-modify');

const greet = importModify('./greet', source => {
    return source.replace('hello', 'yo');
});

greet();
//=> 'yo'

Expose a local variable

// greet.js
const greet = () => {
    console.log('hello');
};
const importModify = require('import-modify');

const greet = importModify('./greet', source => {
    return `${source}\nmodule.exports = greet;`;
});

greet();
//=> 'hello'

API

importModify(moduleId, modify)

moduleId

Type: string

Same as you would use in require().

modify(source)

Type: function

Function where you modify the source and return the new one.

License

MIT © Sindre Sorhus