Skip to content

Repository files navigation

resugar

Rewrite your JavaScript & TypeScript source code with sweet new features.

TODO: Below is the README for esnext, the project this one came from. It will be replaced in time.


Installation

$ yarn global add esnext
# or, with `npm`:
$ npm install -g esnext

Usage

After installing, run esnext -h for comprehensive usage instructions.

Features

Functions

Translate some regular functions to arrow functions:

list.map(function(item){returnitem.name;});// ↑ becomes ↓list.map(item=>item.name);

Declarations

Convert var declarations to let or const as appropriate:

vararr=[];for(vari=0;i<5;i++){arr.push(i);}// ↑ becomes ↓constarr=[];for(leti=0;i<5;i++){arr.push(i);}

Objects

Use shorthand syntax for various object constructs:

letperson={first: first,last: last,fullName: function(){return`${first}${last}`;}};// ↑ becomes ↓letperson={
first,
last,fullName(){return`${first}${last}`;}};

Strings

Convert string concatenation to string or template literals:

letname='Brian'+' '+'Donovan';letgreeting='Hello, '+name;// ↑ becomes ↓letname='Brian Donovan';letgreeting=`Hello, ${name}`;

Destructuring

Convert assignments and declarations to use object destructuring syntax:

leta=obj.a,b=obj.b;(a=obj2.a),(b=obj2.b);// ↑ becomes ↓let{ a, b }=obj;({ a, b }=obj2);

Modules

Translate CommonJS modules into ES6 modules:

varreadFile=require('fs').readFile;constMagicString=require('magic-string');let{ ok,strictEqual: eq}=require('assert');exports.doSomething=function(){ok(1);};// ↑ becomes ↓import{readFile}from'fs';importMagicStringfrom'magic-string';import{ok,strictEqualaseq}from'assert';exportfunctiondoSomething(){ok(1);}

Options

{'declarations.block-scope': {/** * Set this to `true` to only turn `var` into `let`, never `const`. */disableConst: boolean}}

About

Rewrite your JavaScript & TypeScript source code with sweet new features.

Resources

Stars

692 stars

Watchers

21 watching

Forks

Releases

Packages

Used by

Contributors

Languages