crspr

2.0.0 • Public • Published

crspr

Self modifying files toolkit

Dependencies

No dependencies!

Installation (node.js)

$ npm install crspr

Usage

Replace this;

function registerGlobal(moduleName, asName) {
 
    if (!global[asName]) {
        console.info('reistered global', moduleName, 'as', asName);
        global[asName] = require(moduleName);
    }
}
 
var preGlobals = [
    ['Path', 'path'],
    ['Url', 'url'],
    ['Promise', 'bluebird'],
    ['Enum', 'enum'],
    ['FS', 'fs']
];
 
preGlobals.forEach(function(pair){
    registerGlobal(pair[1], pair[0]);
})

...with this;

/*** A-START ***/
/*** T-END ***/
 
var preGlobals = [
    ['Path', 'path'],
    ['Url', 'url'],
    ['Promise', 'bluebird'],
    ['Enum', 'enum'],
    ['FS', 'fs']
];
 
var crspr = require('crspr');
var util = require('util');
var replaceMentLines = preGlobals.map(function (pair) {
                                         var asName = pair[0], moduleName = pair[1];
                                         return util.format('global[\'%s\'] = require(\'%s\');', asName, moduleName);
                                     });
 
crspr('/*** A-START ***/', '/*** T-END ***/', replaceMentLines);

...and rUN!

Readme

Keywords

none

Package Sidebar

Install

npm i crspr

Weekly Downloads

1

Version

2.0.0

License

ISC

Last publish

Collaborators

  • chinwo