es-async

1.1.0 • Public • Published

*nix build status Windows build status Tests coverage npm version

es-async

ES2017 async functions compiler

Backed by nodent-compiler, compiles async/await syntax into valid ES2016 code.

Installation

$ npm install es-async

CLI usage

Compile JS file using async/await into ES2016 compliant JS file:

npx es-async path-to-es2017-file.js > path-to-es2016-file.js

Programmatical usage

Compile async code directly

const compileAsync = require("es-async");

const es2016Code = compileAsync(es2017Code);

Compile specific file

const compileAsyncFromFile = require("es-async/from-file");

compileFromFile(es2017Filename).then(es2016Code => {
	// Process compiled code
});

Result examples

See online demo. Compilation is handled by preconfigured (to reflect native behavior backed by native promises) nodent-compiler

ES2017 ES016
async function asyncAdd(left) {
  return left + (await right);
}
function asyncAdd(left) {
    return new Promise(($return, $error) =>
      Promise.resolve(right).then($await_1 => {
        try {
            return $return(left + $await_1);
        } catch ($boundEx) {
            return $error($boundEx);
        }
      }, $error)
    );
}

Tests

$ npm test

Project cross-browser compatibility supported by:

Package Sidebar

Install

npm i es-async

Weekly Downloads

1

Version

1.1.0

License

ISC

Unpacked Size

9.74 kB

Total Files

12

Last publish

Collaborators

  • medikoo