Lebab is like Babel, just the opposite

    We all love the goodies we got with the ES6. These were tiny but amazing features such as class support, arrow functions, constants, etc.

    Modern browsers support most of these syntax enhancements, but you have to use Babel to support legacy browsers. Although there are situations where you can not worry about supporting old browsers and start living .
    It can be some kind of internal project or just server-side JS code. Let me remind you that the latest stable version of NodeJS supports ES6 at 99%. In such cases, you can safely write all the code on ES6.

    OK, but what about Legacy? For such cases, Lebab comes to the rescue. This is a program that transforms traditional JavaScript syntax into brilliant new ES6 syntax. You can install it through npm:

    npm install -g lebab

    You can convert a single file or list of files from a folder:

    $ lebab main.js -o main-es6.js --transform arrow
    $ lebab --replace 'src/js/**/*.jsx' --transform arrow

    Let's try in action:



    Sadly, only one type of conversion can be performed from the console at a time. However, you can write a simple script to fix this situation:

    import lebab from 'lebab';
    const {code, warnings} = lebab.transform('var f = function(){};', ['let', 'arrow']);
    console.log(code); // -> "const f = () => {};"

    The list of available conversions and their reliability is described in the documentation .

    Do you decide to test Lebab on your own project?

    Also popular now: