Convert JavaScript AMD modules to UMD modules
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
MIT-LICENSE.txt
README.md
package.json
umdify.js

README.md

umdify

umdify is a small JavaScript library for converting modules authored in AMD format to UMD format. It's useful for distributing libraries with wide compatibility in mind. Output UMD is compatible with AMD loaders, CommonJS loaders (like node.js), and (optionally) browser globals.

Based on and shares the same "modify as little as possible" philosophy with nodefy.

Installation

Using npm:

npm install umdify

Usage

String umdify( String contents, String [moduleName] )

Converts contents (a valid AMD JavaScript module) to UMD format. moduleName is only required if you want to support browser globals, and will be the name of the exported window property.

Example (node.js):

var fs = require('fs');
var umdify = require('umdify');

var contents = fs.readFileSync('src/myModule.js', 'utf8');
contents = umdify(contents);
fs.writeFileSync('dist/myModule.js', contents);

Want to do a bulk convert? I won't stand in your way. How about node-glob?

var fs = require('fs');
var path = require('path');
var glob = require('glob');
var umdify = require('umdify');

var files = glob.sync('src/**/*.js');
files.forEach(function(file) {
    var contents = fs.readFileSync(file, 'utf8');
    contents = umdify(contents);
    var dest = path.join('dist', file.replace(/^src\//, ''));
    fs.writeFileSync(dest, contents);
});

License

Released under the MIT License.