Skip to content
/ jsmod Public

JS Code Modification Utility for rapid code changes

License

Notifications You must be signed in to change notification settings

tHBp/jsmod

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jsmod

Module to replace contents of javascript file using AST traversal! 🚀

Getting Started

$ npm install jsmod

Usage

const jsmod = require("jsmod");

const { count, files } = await jsmod({
    files: ["/path/to/file-1", "/path/to/file-2", "/path/to/file-3"],
    filterFiles: ({ fileContents }) => fileContents.match("var a = 42;"),
    traverseOptions: {
        enter: function(node, parent) {
            if (node.type === "Literal" && node.value === "somePropertyName") {
                node.value = "some_property_name";
            }
        }
    },
    generateOptions: {
        format: {
            quotes: "double"
        }
    }
});

API

jsmod(options)

Reads and modifies an array of files and returns a promise that resolves when everything completes.

options.files

Type: Array
Default: none
Required: yes

Array of files paths to be read.

options.traverseOptions

Type: Object
Default: none
Required: yes

Traverse options passed to estraverse.

options.filterFiles({ fileName, fileContents })

Type: Function
Default: none
Required: no

Filter function to filter/ignore files based on file name or file contents.

This can be used to remove files which don't match certain criteria which you may wish to ignore.

Return true if file is to be considered for traversal/replacement, else return false if file is to be ignored.

options.generateOptions

Type: Object
Default: none
Required: no

Generate options passed to escodegen.

License

MIT © The Half Blood Prince

About

JS Code Modification Utility for rapid code changes

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published