derequire
npm install derequire
var derequire = require('derequire');
var transformedCode = derequire(code, '_dereq_', 'require');
takes a string of code and replaces all instances of the identifier tokenFrom
(default 'require') and replaces them with tokenTo (default '_dereq_') but only if they are functional arguments or variable declerations and subsequent uses of said argument, then returnes the code.
For multiple renames at the same times accepts the syntax
derequire(code, [
{
from: 'require',
to: '_dereq_'
},
{
from: 'define',
to: '_defi_'
}
]);
Note: in order to avoid quite a few headaches the token you're changing from and the token you're changing to need to be the same length.