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

amd-to-es6-lukepage

v0.0.14

Published

Convert AMD modules into ES6 modules

Downloads

8

Readme

AMD to ES6 module transpiler

Build Status

What is it?

A simple tool for converting AMD modules into ES6 modules, either via the command line or programmatically.

Why?

AMD and RequireJS are great, but ES6 modules provide a nicer syntax for writing JS modules and there are so many great tools available now for converting ES6 to ES5 which also allow you to use ES6 syntax/features.

Installing

npm install amd-to-es6 -g

Usage

To convert a single file (compiled output sent to stdout):

amdtoes6 my-amd-module.js > my-awesome-es6-module.js

To convert a whole directory:

amdtoes6 --dir src/ --out es6/

If you want to modify the original files just set --out to the same as --dir.

amdtoes6 --dir src --out src

If you want some files to be ignored use the --ignore flag which accepts a glob pattern that is relative to --dir.

amdtoes6 --dir src --ignore libs/**/*.js

If you want the indentation to be "fixed" then use the --beautify option which just runs the output through jsbeautify.

If a file cannot be compiled an message will be printed explaining the error and it will be skipped.

Examples

Modules without dependencies.

AMD

define(function () {
    return {};
});

ES6

export default {};

Modules with dependencies.

AMD

define(['path/to/a', 'path/to/b'], function (a, b) {
    return function (x) {
        return a(b(x));
    };
});

ES6

import a from 'path/to/a';
import b from 'path/to/b';

export default function (x) {
    return a(b(x));
};

If you have AMD modules that look like this, where not all dependencies are assigned to parameters but accessed in the module using require, amdtoes6 will have to create some variable names. You wil probably want to change these.

AMD

define(['require', 'path/to/a', 'path/to/b'], function (require) {
    return function (x) {
        var a = require('a');
        var b = require('b');
        return a(b(x));
    };
});

ES6

import $__path_to_a from 'path/to/a';
import $__path_to_b from 'path/to/b';

export default function (x) {
    var a = $__path_to_a;
    var b = $__path_to_b;
    return a(b(x));
};

Imports for side-effects.

AMD

define(['path/to/a', 'path/to/b'], function () {
    return {};
});

ES6

import 'path/to/a';
import 'path/to/b';

export default {};

Without the --beautify option.

AMD

define(['path/to/a', 'path/to/b'], function (a, b) {
    return function (x) {
        return a(b(x));
    };
});

ES6

import a from 'path/to/a';
import b from 'path/to/b';

    export default function (x) {
        return a(b(x));
    };

Options


  Usage: amdtoes6 [options]

  Options:

    -h, --help          output usage information
    -d --dir <dirname>  Use this option to specify a directory to compile.
    -o --out <dirname>  If using the --dir option this specifies the output directory.
    -i --ignore <glob>  If using the --dir options this specifies to exclude eg. libs/**/*
    -b --beautify       Run the output through jsbeautify (mainly useful for fixing indentation)

Not Supported

  • Named define modules eg. define('my-module', function () {})
  • Files with multiple module definitions
  • UMD style modules where the callback passed to define is not a function literal eg. define(factoryFn)