These are common utility methods. This is a plugin for shift-refactor.
$ npm install refactor-plugin-common
const {refactor} = require('shift-refactor');
const commonMethods = require('refactor-plugin-common');
const src = `/* js source */`;
const $script = refactor(src, commonMethods);debug()compressConditonalExpressions()compressCommaOperators()convertComputedToStatic()unshorten()expandBoolean()normalizeIdentifiers()
Insert a debugger statement into a function.
$script(fnSelector).debug();Transform conditional expressions that have been reduced to testing only a literal value into the appropriate branch, e.g. var a = true ? 1 : 2; into var a = 1;
$script.compressConditonalExpressions();For comma operator expressions that include literal values, eliminate all but the rightmost expression, e.g. var a = true, false, 1, 2, "hello"; into var a = "hello";
$script.compressCommaOperators();Turn computed member expressions into static member expressions, e.g. window["document"] into window.document
$script.convertComputedToStatic();Remove declaration statements like var r = require; and transform all references to the shortened identifier into the original.
$script(targetDeclaration).unshorten();Expands !1 and !0 into false and true
$script.expandBoolean();Transform all identifiers into consistent, memorable identifiers like $$abruptBrother
$script.normalizeIdentifiers();