- Harmony modules to AMD, Node.js, or Revealing Module Pattern
- Shorthand properties
- Method definitions
- Arrow functions (requires
- Class declarations
- Maintains line numbers
Look in the demo directory or try it here.
$ npm install harmonizr
$ ./node_modules/.bin/harmonizr [options] path/to/input
If you install Harmonizr globally or have ./node_modules/.bin in your PATH, you can omit the path to the harmonizr script.
--revealing to transform Harmony-style
This transpiles src/foo.js into a Node.js-compatible version at lib/foo.js:
$ harmonizr --node --output lib/foo.js src/foo.js
--module to implicitly wrap the entire file in a module
declaration. The name of the module is required, but only appears in
the output when using
--node to indicate what modules should be
loaded from the local directory and not the node_modules directory.
For example, if a
foo module needs to load
from the same directory as it (not from node_modules), you could do
$ harmonizr --node --relatives bar,baz --output lib/foo.js src/foo.js
- No nested modules.
import * from module;.
exportis only allowed when in front of a simple function or variable declaration.
- Probably bugged.
Harmonizr uses the excellent Esprima parser. A copy of Esprima from its "harmony" branch is embedded into Harmonizr in the lib directory.
The actual source code for Harmonizr is in the src directory. The Makefile transpiles that into a Node.js-style module in lib, AMD-style in demo, and Revealing Module Pattern-style in test.
Harmonizr transpiles itself. Since Node.js doesn't support the newer syntax harmonizr.js uses in the src directory, it loads the harmonizr module out of the lib directory. Be careful when building.
Tests are in the test directory. Run them with
npm test or by opening
If you'd like to contribute, please try to include tests, ensure the code coverage stays at 100%, and that JSHint doesn't complain.
make to build, run JSHint, and run the tests (with code