LinuxCommandLibrary

lebab

Convert legacy JavaScript to modern ES6+

TLDR

Transpile using one or more comma-separated transformations

$ lebab --transform [transformation1,transformation2,...]
copy

Transpile a file to stdout
$ lebab [path/to/input_file]
copy

Transpile a file to the specified output file
$ lebab [path/to/input_file] --out-file [path/to/output_file]
copy

Replace all .js files in-place in the specified directory, glob, or file
$ lebab --replace [directory|glob|file]
copy

Display help
$ lebab --help
copy

SYNOPSIS

lebab [-o|--output DIR] [-r|--replace] [-t|--transform TRANSFORMS] [FILE|DIR|GLOB]...

PARAMETERS

-o, --output


    Specify output directory; defaults to input filename with .modern.js suffix

-r, --replace
    Replace input files in-place instead of creating new files

-t, --transform
    Comma-separated list of transforms: arrow, async-await, class, commonjs, default-params, destructuring, exponent, includes, let, objmethod, rest-spread, template (all by default)

-e, --editorconfig
    Respect .editorconfig for indentation and formatting

--dry
    Dry run: show changes without writing files

--diff
    Show unified diff of changes

--force
    Overwrite output files without prompting

-v, --version
    Display version info

-h, --help
    Show help

DESCRIPTION

Lebab is a command-line tool designed to automatically refactor and modernize JavaScript code from ES5 syntax to contemporary ES6+ features. It applies a series of targeted transformations such as converting function expressions to arrow functions, replacing var with let and const, introducing classes, template literals, destructuring, rest/spread operators, async/await, and more.

Unlike full transpilers like Babel, Lebab focuses on one-way upgrades from legacy to modern syntax without preserving ES5 compatibility. It's particularly useful for migrating large codebases to modern JavaScript standards, improving readability and leveraging new language features. The tool processes files or directories, supports glob patterns, and respects .editorconfig for consistent formatting.

Installation requires Node.js: npm install -g lebab. It's lightweight, fast, and configurable via transform selection, making it ideal for developers upgrading projects incrementally.

CAVEATS

Lebab performs one-way transformations; original ES5 code is not preserved. Some transforms may require manual review for semantic changes, like commonjs to ES modules. Not suitable for production code without testing. Requires Node.js ≥ 10.

AVAILABLE TRANSFORMS

Full list: arrow (arrow funcs), async-await, class (classes), commonjs (ES modules), default-params, destructuring (destructure), exponent (**), includes, let, objmethod (methods), rest-spread, template (literals). Run lebab --help for details.

INSTALLATION

npm install -g lebab. Use locally: npx lebab ....

HISTORY

Created by Ricky Reusser in 2015 as an ES5-to-ES6 migrator. Actively maintained on GitHub with contributions expanding transforms to ES2017+. Gained popularity for browserify projects; latest v1.4.0 (2023) supports modern Node.

SEE ALSO

node(1), npm(1), jscodeshift(1)

Copied to clipboard