npm.io
0.1.0 • Published 10 years ago

tapc-amd-wrap

Licence
WTFPL
Version
0.1.0
Deps
0
Vulns
0
Weekly
0
Stars
12

Simple Wrapping of CommonJS to AMD

All this module does is wrap your CommonJS modules into the simplified CommonJS wrapper format, i.e.:

define(function (require, exports, module) {
    // your CommonJS code here
});

It takes in a string and gives back a string:

var amdWrap = require("amd-wrap");

// wrap define around string
var wrapped = amdWrap("module.exports = 5;");

// wrap define around the string from file
var wrapThis = amdWrap(fs.readFileSync(__filename));

// wrap define and moduleName
var wrapped = amdWrap("moduleName","module.exports = 5;");

// wrap define with moduleName and requires
var wrapped = amdWrap("moduleName","module.exports = 5;", ["moduleName1"]);

Line numbers will line up, although the first column will be shifted by "define (function (require, exports, module) {".length characters.

See also: amd-wrap-legacy, which has a few more affordances for use when transitioning a larger codebase from CommonJS to AMD.

Keywords