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

es6ify

v1.6.0

Published

browserify v2 transform to compile JavaScript.next (ES6) to JavaScript.current (ES5) on the fly.

Downloads

1,865

Readme

es6ify build status

NPM

browserify >=v2 transform to compile JavaScript.next (ES6) to JavaScript.current (ES5) on the fly.

browserify({ debug: true })
  .add(es6ify.runtime)
  .transform(es6ify)
  .require(require.resolve('./src/main.js'), { entry: true })
  .bundle()
  .pipe(fs.createWriteStream(bundlePath));

Find the full version of this example here.

Installation

npm install es6ify

What You Get

screenshot

Try it live

Table of Contents generated with DocToc

Enabling sourcemaps and related posts

API

generated with docme

Examples

es6ify.configure(filePattern : Regex)

The default file pattern includes all JavaScript files, but you may override it in order to only transform files coming from a certain directory, with a specific file name and/or extension, etc.

By configuring the regex to exclude ES5 files, you can optimize the performance of the transform. However transforming ES5 JavaScript will work since it is a subset of ES6.

browserify({ debug: true })
  .add(require('es6ify').runtime)
   // compile all .js files except the ones coming from node_modules
  .transform(require('es6ify').configure(/^(?!.*node_modules)+.+\.js$/))
  .require(require.resolve('./src/main.js'), { entry: true })
  .bundle()
  .pipe(fs.createWriteStream(bundlePath));

es6ify.traceurOverrides

Some features supported by traceur are still experimental: either nonstandard, proposed but not yet standardized, or just too slow to use for most code. Therefore Traceur disables them by default. They can be enabled by overriding these options.

For instance to support the async functions (async/await) feature you'd do the following.

var es6ify = require('es6ify');
es6ify.traceurOverrides = { asyncFunctions: true };
browserify({ debug: true })
  .add(es6ify.runtime)
  .require(require.resolve('./src/main.js'), { entry: true })
  .bundle()
  .pipe(fs.createWriteStream(bundlePath));

Caching

When es6ify is run on a development server to help generate the browserify bundle on the fly, it makes sense to only recompile ES6 files that changed. Therefore es6ify caches previously compiled files and just pulls them from there if no changes were made to the file.

Source Maps

es6ify instructs the traceur transpiler to generate source maps. It then inlines all original sources and adds the resulting source map base64 encoded to the bottom of the transformed content. This allows debugging the original ES6 source when using the debug flag with browserify.

If the debug flag is not set, these source maps will be removed by browserify and thus will not be contained inside your production bundle.

Supported ES6 features

arrowFunctions

var log = msg => console.log(msg);

full example

classes

class Character {
  constructor(x, y, name) {
    this.x = x;
    this.y = y;
  }
  attack(character) {
    console.log('attacking', character);
  }
}

class Monster extends Character {
  constructor(x, y, name) {
    super(x, y);
    this.name = name;
    this.health_ = 100;
  }

  attack(character) {
    super.attack(character);
  }

  get isAlive() { return this.health > 0; }
  get health() { return this.health_; }
  set health(value) {
    if (value < 0) throw new Error('Health must be non-negative.');
    this.health_ = value;
  }
}

full example

defaultParameters

function logDeveloper(name, codes = 'JavaScript', livesIn = 'USA') {
  console.log('name: %s, codes: %s, lives in: %s', name, codes, livesIn);
};

full example

destructuring

var [a, [b], c, d] = ['hello', [', ', 'junk'], ['world']];
console.log(a + b + c); // hello, world

full example

forOf

for (let element of [1, 2, 3]) {
  console.log('element:', element);
}

full example

propertyMethods

var object = {
  prop: 42,
  // No need for function
  method() {
    return this.prop;
  }
};

propertyNameShorthand

var foo = 'foo';
var bar = 'bar';
var obj = { foo, bar };

templateLiterals

var x = 5, y = 10;
console.log(`${x} + ${y} = ${ x + y}`)
// 5 + 10 = 15

restParameters

function printList(listname, ...items) {
  console.log('list %s has the following items', listname);
  items.forEach(function (item) { console.log(item); });
};

full example

spread

function add(x, y) {
  console.log('%d + %d = %d', x, y, x + y);
}
var numbers = [5, 10]
add(...numbers);
// 5 + 10 = 15
};

full example

generators

// A binary tree class.
function Tree(left, label, right) {
  this.left = left;
  this.label = label;
  this.right = right;
}

// A recursive generator that iterates the Tree labels in-order.
function* inorder(t) {
  if (t) {
    yield* inorder(t.left);
    yield t.label;
    yield* inorder(t.right);
  }
}

// Make a tree
function make(array) {
  // Leaf node:
  if (array.length == 1) return new Tree(null, array[0], null);
  return new Tree(make(array[0]), array[1], make(array[2]));
}


let tree = make([[['a'], 'b', ['c']], 'd', [['e'], 'f', ['g']]]);
console.log('generating tree labels in order:');

// Iterate over it
for (let node of inorder(tree)) {
  console.log(node); // a, b, c, d, ...
}

full example

block scoping

{
  let tmp = 5;
}
console.log(typeof tmp === 'undefined'); // true

NOTE: Traceur has a pretty bad bug that makes the above code not work correctly for now: google/traceur-compiler#1358.

modules

Imports and exports are converted to commonjs style require and module.exports statements to seamlessly integrate with browserify.