Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
amd-to-es6-lukepage
Advanced tools
A simple tool for converting AMD modules into ES6 modules, either via the command line or programmatically.
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.
npm install amd-to-es6 -g
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.
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));
};
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)
define('my-module', function () {})
define
is not a function literal eg. define(factoryFn)
FAQs
Convert AMD modules into ES6 modules
The npm package amd-to-es6-lukepage receives a total of 10 weekly downloads. As such, amd-to-es6-lukepage popularity was classified as not popular.
We found that amd-to-es6-lukepage demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.