npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

babel-preset-node6-es6

v11.2.5

Published

Babel preset for Node 6.x (ECMAScript stage 0 and up)

Downloads

767

Readme

Babel 6.x presets for Node 6.x (updated regularly!)

Node 6.x brings ~95% native ES6/ES2015 coverage.

This preset for Babel 6 attempts to bridge the gap for the much of the remaining 5% of the evolving ECMAScript spec using Babel plug-ins, from stage 0 and up.

Motivation

Babel 6.x is awesome, but simply including the ES2015 preset means you're transpiling features that your Node 6.x installation can already do faster and natively, replacing them with inferior / old code.

This preset complements existing V8-native functionality - it doesn't work around it.

The end result is nearly always a faster build and script execution time.

Key features:

Note: This package originally shipped with the React preset, but to avoid bloat, doesn't any longer. If you want to add that, please install babel-preset-react too

Usage instructions

Installation

Install via NPM the usual way:

npm i babel-preset-node6-es6

Usage

Via .babelrc (recommended)

Create a .babelrc file in your project root, and include 'node6-es6' in your preset path:

{
  "presets": [
    "node6-es6"
  ]
}

Now whenever you run babel-node, it will polyfill your app with the ES2015 features that Node 6 is missing.

Via CLI

$ babel script.js --presets node6-es6

Via Node API

If you don't want to use a project-wide .babelrc file (as above):

require("babel-core").transform("code", {
  presets: ["node6-es6"]
});

And if you do, and you want to use vanilla node instead of babel-node as your CLI, you can create an entry script that references your pre-transpiled code like so:

require('babel-register');
require('path/to/es6/script');

... which will then run everywhere Node can.

Of course, make sure to npm i -S babel-core or npm i -S babel-register respectively, to grab the NPM packages you'll need to transpile on-the-fly.

Webpack, Gulp, Browserify, etc

Follow vendor instructions and include node6-es6 in your babel "preset" list.

How to add React support

Babel has a ready-made preset for React, and you now need to install it separately.

Just grab it via NPM:

npm i babel-preset-react

And then add it to your "presets" list in .babelrc:

{
  "presets": [
    "node6-es6",
    "react"
  ]
}

How to use async/await

The async/await proposal allows you to wait on a Promise, and write asynchronous code that looks synchronous.

Here's an example:

async function getUsers(howMany) {
  try {
    const response = await fetch(`http://jsonplaceholder.typicode.com/users/${howMany}`); // <-- a Promise
    return response.json(); // <-- Another promise.
  } catch(e) {
    console.log('some kind of error occurred: ', e)
  }
}

getUsers(10).then(users => {
  // "users" contains the result of `response.json()`. Async functions *always*
  // return a promise, even if that means wrapping a non-Promise in Promise.resolve
})

In the above example, fetch returns a promise. By prefixing the function with async and prefixing every Promise with await, we avoid the typical .then() chain inside of the function block and can reason about the flow of the application a little more clearly.

We can also wrap promises in try/catch blocks, instead of bolting on .catch() chains.

The necessary babel plug-ins to use async/await are included in this package, so you can use this syntax right away.