README
wrapfor
Wrap code for usage as an amd/cjs/whatever module.
Examples
var input = "var method = function () { return true; };"
Generate an AMD module:
wrapfor.amd(input, {exports:'method'});
// ^ returns a string containing
define(function(require) {
var method = function() { return true; };
return method;
});
Generate an AMD module with dependencies inline:
wrapfor.amd(input, {
deps: {
"_": "lodash"
},
exports: "method"
});
// ^ returns a string containing
define(function(require) {
var _ = require('lodash');
var method = function() { return true; };
return method;
});
Generate a CommonJS module:
wrapfor.cjs(input, {exports:'method'});
// ^ returns a string containing
var method = function() { return true; };
module.exports = method;
Generate a CommonJS module with dependencies inline:
wrapfor.cjs(input, {
deps: {
"_": "lodash"
},
exports: "method"
});
// ^ returns a string containing
var _ = require('lodash');
var method = function() { return true; };
module.exports = method;
Usage
wrapfor.cjs(input, opts)
wrapfor.amd(input, opts)
input
Type: String
Default: 'none'
A string containing javascript to be wrapped.
opts
Type: Object
Default: {}
A configuration object supporting the following keys:
exports
: the variable to exportdeps
: an object listing dependencies to load and which variable to store them in
Release History
- 2013-11-04 - v0.1 - initial release