Socket
Book a DemoInstallSign in
Socket

import-modify

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

import-modify

Modify the source of an imported module

latest
Source
npmnpm
Version
3.0.0
Version published
Maintainers
1
Created
Source

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

Keywords

import

FAQs

Package last updated on 21 May 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts