CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-lebab

JavaScript ES5 to ES6/ES7 transpiler that performs the opposite function of Babel

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

index.mddocs/

Lebab

Lebab is a JavaScript transpiler that converts ES5 code to modern ES6/ES7 syntax. It performs the opposite function of Babel, helping developers modernize legacy JavaScript codebases by automatically upgrading syntax patterns to use contemporary language features.

Package Information

  • Package Name: lebab
  • Package Type: npm
  • Language: JavaScript/Node.js
  • Installation: npm install -g lebab (CLI) or npm install lebab (programmatic)

Core Imports

const { transform } = require("lebab");

For ES6 modules:

import { transform } from "lebab";

Alternative CommonJS usage:

const lebab = require("lebab");
// Then use: lebab.transform(code, transforms)

Basic Usage

Programmatic API

const { transform } = require("lebab");

// Transform ES5 code to modern JavaScript
const { code, warnings } = transform(
  'var f = function(a) { return a; };',
  ['let', 'arrow', 'arrow-return']
);

console.log(code); // 'const f = a => a;'
console.log(warnings); // []

Command Line Interface

# Transform a single file
lebab es5.js -o es6.js --transform let,arrow

# Transform entire directory in-place
lebab --replace src/js/ --transform arrow

# Transform with glob patterns
lebab --replace 'src/js/**/*.jsx' --transform arrow

Architecture

Lebab is built around a modular transformation system:

  • Transform Engine: Core transformation pipeline using AST manipulation
  • Parser/Printer: Uses Recast for code parsing and generation with source map support
  • Transform Registry: 19 individual transforms organized into safe and unsafe categories
  • CLI Interface: Command-line tool for batch file processing
  • Warning System: Detailed feedback about transformation limitations and failures

Capabilities

Transform Function

Main programmatic API for converting ES5 code to modern JavaScript syntax.

/**
 * Transforms ES5 code to ES6/ES7 using specified transforms
 * @param {string} code - The ES5 code to transform
 * @param {string[]} transformNames - Array of transform names to apply
 * @returns {TransformResult} Object with 'code' and 'warnings' properties
 */
function transform(code, transformNames);

Safe Transforms

High-confidence transforms with minimal risk of breaking existing functionality. These transforms use strict rules and produce nearly equivalent code.

// Available safe transform names
type SafeTransforms = 
  | "arrow"           // Callbacks to arrow functions  
  | "arrow-return"    // Drop return statements in arrow functions
  | "for-of"          // For loops to for-of loops
  | "for-each"        // For loops to Array.forEach()
  | "arg-rest"        // Arguments to function(...args)
  | "arg-spread"      // apply() to spread operator
  | "obj-method"      // Function values in objects to methods
  | "obj-shorthand"   // {foo: foo} to {foo}
  | "no-strict"       // Remove "use strict" directives
  | "exponent"        // Math.pow() to ** operator (ES7)
  | "multi-var";      // Single var declarations to multiple

Safe Transforms

Unsafe Transforms

Transforms that use heuristics and may require manual review. Apply with caution as they can potentially change code behavior.

// Available unsafe transform names
type UnsafeTransforms =
  | "let"             // var to let/const
  | "class"           // Function/prototypes to classes
  | "commonjs"        // CommonJS modules to ES6 modules
  | "template"        // String concatenation to template strings
  | "default-param"   // Default parameters instead of a = a || 2
  | "destruct-param"  // Destructuring parameters
  | "includes";       // indexOf() to includes()

Unsafe Transforms

Transform Result

The result object returned by the transform function.

interface TransformResult {
  /** The transformed code */
  code: string;
  /** Array of warnings about transformation issues */
  warnings: Warning[];
}

interface Warning {
  /** Line number where warning occurred */
  line: number;
  /** Warning message */
  msg: string;
  /** Transform type that generated the warning */
  type: string;
}

CLI Interface

Command-line interface for batch processing of JavaScript files.

# Basic usage
lebab <input-file> -o <output-file> --transform <transforms>

# Options:
# --transform, -t  Comma-separated list of transforms to apply
# --replace, -r    In-place transformation using glob patterns  
# --help, -h       Show help
# --version, -v    Show version

CLI Usage

Types

// All available transform names
type TransformName = SafeTransforms | UnsafeTransforms;

// Transform names as defined in TypeScript definitions
type TransformTypes =
  | "class" | "template" | "arrow" | "arrow-return" | "let" 
  | "default-param" | "destruct-param" | "arg-spread" | "arg-rest"
  | "obj-method" | "obj-shorthand" | "no-strict" | "commonjs" 
  | "exponent" | "multi-var" | "for-of" | "for-each" | "includes";

docs

cli-usage.md

index.md

safe-transforms.md

unsafe-transforms.md

tile.json