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 [options] [files...]
lebab --stdin [options]
lebab --dir <src-dir> --out-dir <dest-dir> [options]
lebab --help
lebab --version

PARAMETERS

--help
    Display help message with available options and transforms.

--version
    Display the version number of the lebab command.

--transform
    Specify a comma-separated list of transforms to apply (e.g., arrow,let,class). Use all to apply all available transforms.

--skip
    Specify a comma-separated list of transforms to skip (e.g., commonjs). Useful when using --transform all.

--dir
    Specify the input directory containing source JavaScript files to transpile.

--out-dir
    Specify the output directory for the transformed JavaScript files. Requires --dir.

--replace
    Overwrite the original source files in the input directory with the transformed output. Use with extreme caution!

--stdin
    Read input JavaScript code from standard input (stdin).

--stdout
    Write output JavaScript code to standard output (stdout). Default when --stdin is used.

--add-module-exports
    Add module.exports to converted CommonJS modules for better interoperability.

--keep-class-names
    Prevent mangling or renaming of class names during the transformation process.

--config
    Specify a path to a JSON configuration file (e.g., .lebabrc.json) for custom settings.

DESCRIPTION

lebab is a command-line tool designed to transpile modern JavaScript (ECMAScript 2015 / ES6 and newer) syntax into older, widely compatible ES5 syntax. Unlike other transpilers that prioritize strict spec adherence, lebab focuses on generating human-readable and idiomatic ES5 code. This often involves converting const and let declarations to var, arrow functions to regular function expressions, and various other ES6+ features into their ES5 equivalents. It's built on Node.js and distributed through npm, making it a popular choice for developers looking for a simpler, more opinionated transformation process. lebab is particularly useful for projects that need to ensure backward compatibility with older JavaScript environments without sacrificing the benefits of writing modern code. Its modular design allows users to specify exactly which transformations to apply or skip, providing fine-grained control over the output.

CAVEATS

lebab is a JavaScript transpiler, not a native Linux utility. It requires Node.js and npm for installation (npm install -g lebab). Its primary focus is readability over absolute performance or lossless transformation. The --replace option overwrites source files, so always use it with version control or backups. It performs syntax transformations, not polyfills for missing browser APIs.

INSTALLATION

lebab is installed globally using the Node Package Manager: npm install -g lebab. This command makes the lebab executable available in your system's PATH, assuming Node.js is already installed. If Node.js is not installed, it must be set up first.

AVAILABLE TRANSFORMS

lebab offers a comprehensive set of transformations, each targeting specific ES6+ features. Key transforms include arrow (arrow functions), let and const (block-scoped declarations), for-of (for-of loops), template-strings, commonjs (ESM to CommonJS), class (ES6 classes), and many others. You can view the full list of available transforms by running lebab --help.

HISTORY

lebab emerged as a lightweight, opinionated alternative to more complex JavaScript transpilers like Babel. Its development was motivated by a desire to produce cleaner, more readable ES5 output from modern JavaScript, focusing on common and safe transformations. It aims to simplify the transpilation process for developers who prefer idiomatic ES5 output without extensive configuration, making it suitable for quick conversions and maintaining backward compatibility.

SEE ALSO

babel(1), node(1), npm(1), eslint(1)

Copied to clipboard