Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

esnext

Package Overview
Dependencies
Maintainers
1
Versions
116
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

esnext

Update your project to the latest ECMAScript syntax.

  • 1.17.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11K
increased by6.32%
Maintainers
1
Weekly downloads
 
Created
Source

esnext Build Status

Bring your JavaScript into the future.

Installation

$ 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) { return item.name; });

// ↑ becomes ↓

list.map(item => item.name);

Declarations

Convert var declarations to let or const as appropriate:

var arr = [];
for (var i = 0; i < 5; i++) {
  arr.push(i);
}

// ↑ becomes ↓

const arr = [];
for (let i = 0; i < 5; i++) {
  arr.push(i);
}

Objects

Use shorthand syntax for various object constructs:

let person = {
  first: first,
  last: last,
  
  fullName: function() {
    return `${first} ${last}`;
  }
};

// ↑ becomes ↓

let person = {
  first,
  last,
  
  fullName() {
    return `${first} ${last}`;
  }
};

Strings

Convert string concatenation to string or template literals:

let name = 'Brian' + ' ' + 'Donovan';
let greeting = 'Hello, ' + name;

// ↑ becomes ↓

let name = 'Brian Donovan';
let greeting = `Hello, ${name}`;

Destructuring

Convert assignments and declarations to use object destructuring syntax:

let a = 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:

var readFile = require('fs').readFile;
const MagicString = require('magic-string');
let { ok, strictEqual: eq } = require('assert');

exports.doSomething = function() {
  ok(1);
};

// ↑ becomes ↓

import { readFile } from 'fs';
import MagicString from 'magic-string';
import { ok, strictEqual as eq } from 'assert';

export function doSomething() {
  ok(1);
}

Options

{
  'declarations.block-scope': {
    /**
     * Set this to `true` to only turn `var` into `let`, never `const`.
     */
    disableConst: boolean
  },
  /**
   * Pass a custom function to parse the code as desired. Most likely you'll
   * want to use `babel-eslint` to parse any valid babel code. To set this
   * option in code, do something like this:
   *
   *   import { parse } from 'babel-eslint';
   *   convert(code, { parse: parse });
   *
   * To set this option from the command-line interface, make sure your custom
   * parser is installed, then use it like so:
   *
   *   $ esnext -I index.js --parser babel-eslint
   */
  parse: (source: string) => AST
}

Keywords

FAQs

Package last updated on 06 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc