Skip to content
Change the contents of files according to rules
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


changer reads in files and modifies them according to rules that you specify. It can be used to automatically modify code, change text, or anything else.


npm install changer

To use changer you need to create some rules. A rule is a just a function, and it returns the (possibly modified) line of text. Here's an example rules file:

exports.replaceEvens = function( lineNumber, text ) {
    if( lineNumber % 2 == 2 )
        text.replace( "Hello", "Goodbye" );

    return text;

exports.commentOut = function( lineNumber, text ) {
    if( lineNumber > 50 && lineNumber < 60 )
        text = "// " + text;

    return text;

Then in another file, we can apply the rules to some files

var change = require("changer").change,
    rules = require("./ruleSet");

// An array of filepaths
var files = [

// Batch process the files
for( var iFile=0; iFile<files.length; ++iFile ) {
    change( rules.replaceEvens, files[iFile] );
    change( rules.commentOut, files[iFile] );

// Do one more for good measure
change( rules.replaceEvens, "anotherfile.csv" );
Something went wrong with that request. Please try again.