refactor-plugin-common
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

Shift Refactor Plugin: Common methods

These are common utility methods. This is a plugin for shift-refactor.

Installation

$ npm install refactor-plugin-common

Usage

const {refactor} = require('shift-refactor');
const commonMethods = require('refactor-plugin-common');
 
const src = `/* js source */`;
 
const $script = refactor(src, commonMethods);

API

Methods

.debug()

Insert a debugger statement into a function.

Example

$script(fnSelector).debug();

.compressConditonalExpressions()

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;

Example

$script.compressConditonalExpressions();

.compressCommaOperators()

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";

Example

$script.compressCommaOperators();

.convertComputedToStatic()

Turn computed member expressions into static member expressions, e.g. window["document"] into window.document

Example

$script.convertComputedToStatic();

.unshorten()

Remove declaration statements like var r = require; and transform all references to the shortened identifier into the original.

Example

$script(targetDeclaration).unshorten();

.expandBoolean()

Expands !1 and !0 into false and true

Example

$script.expandBoolean();

.normalizeIdentifiers()

Transform all identifiers into consistent, memorable identifiers like $$abruptBrother

Example

$script.normalizeIdentifiers();

Readme

Keywords

none

Package Sidebar

Install

npm i refactor-plugin-common

Weekly Downloads

0

Version

2.0.1

License

ISC

Unpacked Size

151 kB

Total Files

31

Last publish

Collaborators

  • jsoverson