UMD snippets
JavaScript Universal Module Definition snippets for Sublime Text
Details
Installs
- Total 333
- Win 135
- Mac 146
- Linux 52
Nov 21 | Nov 20 | Nov 19 | Nov 18 | Nov 17 | Nov 16 | Nov 15 | Nov 14 | Nov 13 | Nov 12 | Nov 11 | Nov 10 | Nov 9 | Nov 8 | Nov 7 | Nov 6 | Nov 5 | Nov 4 | Nov 3 | Nov 2 | Nov 1 | Oct 31 | Oct 30 | Oct 29 | Oct 28 | Oct 27 | Oct 26 | Oct 25 | Oct 24 | Oct 23 | Oct 22 | Oct 21 | Oct 20 | Oct 19 | Oct 18 | Oct 17 | Oct 16 | Oct 15 | Oct 14 | Oct 13 | Oct 12 | Oct 11 | Oct 10 | Oct 9 | Oct 8 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Windows | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Mac | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Linux | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Readme
- Source
- raw.githubusercontent.com
Sublime UMD Snippets
JavaScript snippets for the Universal Module Definition.
Installation
Use Package Control. Search for “UMD Snippets.”
Alternatively, clone this repository into your Packages
folder.
Usage
Each snippet is described below, with a title that you can search for in the Command Palette (prefixed by “UMD—”) and with a tab trigger.
The snippets mirror (with a couple tiny differences) the templates provided in the UMD repo, with fields for making it easier to configure module names and dependencies. For detailed explanations of each UMD variant, see the corresponding template in the UMD repo.
AMD or browser global
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['b'], factory);
} else {
// Browser globals
root.amdWeb = factory(root.b);
}
}(this, function (b) {
function amdWeb () {
}
return amdWeb;
}));
Tab trigger: umda
Fields:
- module name
- factory dependencies
- module parameters
- module code
Reference: amdWeb
AMD with global export
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['b'], function (b) {
// Also create a global in case some scripts
// that are loaded still are looking for
// a global even when an AMD loader is in use.
return (root.amdWebGlobal = factory(b));
});
} else {
// Browser globals
root.amdWebGlobal = factory(root.b);
}
}(this, function (b) {
function amdWebGlobal () {
}
return amdWebGlobal;
}));
Tab trigger: umdag
Fields:
- module name
- factory dependencies
- module parameters
- module code
Reference: amdWebGlobal
CommonJS adapter
// Help Node out by setting up define.
if (typeof exports === 'object' && typeof define !== 'function') {
define = function (factory) {
factory(require, exports, module);
};
}
define(function (require, exports, module) {
var b = require('b');
// Only attach properties to the exports object to define
// the module's properties.
exports.action = function () {
};
});
Tab trigger: umdca
Fields:
- name of property on the
exports
object - optional dependency
- module parameters
- module code
Reference: commonjsAdapter
CommonJS strict
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['exports', 'b'], factory);
} else if (typeof exports === 'object') {
// CommonJS
factory(exports, require('b'));
} else {
// Browser globals
factory((root.commonJsStrict = {}), root.b);
}
}(this, function (exports, b) {
// attach properties to the exports object to define
// the exported module properties.
exports.action = function () {
};
}));
Tab trigger: umdcs
Fields:
- global module name
- name of property on
exports
object - factory dependencies
- module parameters
- module code
Reference: commonjsStrict
CommonJS strict with global
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['exports', 'b'], function (exports, b) {
factory((root.commonJsStrictGlobal = exports), b);
});
} else if (typeof exports === 'object') {
// CommonJS
factory(exports, require('b'));
} else {
// Browser globals
factory((root.commonJsStrictGlobal = {}), root.b);
}
}(this, function (exports, b) {
// attach properties to the exports object to define
// the exported module properties.
exports.action = function () {
};
}));
Tab trigger: umdcg
Fields:
- global module name
- name of property on
exports
object - factory dependencies
- module parameters
- module code
Reference: commonjsStrictGlobal
jQuery plugin
(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
} else {
// Browser globals
factory(jQuery);
}
}(function ($) {
$.fn.jqueryPlugin = function () {
};
}));
Tab trigger: umdj
Fields:
- plugin name
- factory dependencies
- plugin parameters
- plugin code
Reference: jqueryPlugin
jQuery plugin with CommonJS
(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
} else {
// Browser globals
factory(jQuery);
}
}(function ($) {
$.fn.jqueryPlugin = function () {
};
}));
Tab trigger: umdjc
Fields:
- plugin name
- factory dependencies
- plugin parameters
- plugin code
Reference: jqueryPluginCommonjs
Node adapter
// Help Node out by setting up define.
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function (require, exports, module) {
var b = require('b');
return function () {
};
});
Tab trigger: umdn
Fields:
- optional dependency
- module parameters
- module code
Reference: nodeAdapter
AMD, Node, or browser global
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['b'], factory);
} else if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like enviroments that support module.exports,
// like Node.
module.exports = factory(require('b'));
} else {
// Browser globals (root is window)
root.returnExports = factory(root.b);
}
}(this, function (b) {
function returnExports () {
}
return returnExports;
}));
Tab trigger: umdr
Fields:
- module name
- factory dependencies
- module parameters
- module code
Reference: returnExports
AMD with global, Node, or global
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['b'], function (b) {
// Also create a global in case some scripts
// that are loaded still are looking for
// a global even when an AMD loader is in use.
return (root.returnExportsGlobal = factory(b));
});
} else if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like enviroments that support module.exports,
// like Node.
module.exports = factory(require('b'));
} else {
// Browser globals (root is window)
root.returnExportsGlobal = factory(root.b);
}
}(this, function (b) {
function returnExportsGlobal () {
}
return returnExportsGlobal;
}));
Tab trigger: umdrg
Fields:
- module name
- factory dependencies
- module parameters
- module code
Reference: returnExports
Contributing
Pull requests for improving the snippets are welcome. If you want to make changes to the module definitions themselves, please send those requests to the UMD repo.
License
The Sublime UMD Snippets package is released under the MIT License. See LICENSE.txt for details.