Skip to content

Instantly share code, notes, and snippets.

@ChrisBAshton
Last active February 11, 2024 23:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChrisBAshton/421663416c721f023bc0 to your computer and use it in GitHub Desktop.
Save ChrisBAshton/421663416c721f023bc0 to your computer and use it in GitHub Desktop.
Best base for a JavaScript library
// shamelessly taken from Imager - https://github.com/BBC-News/Imager.js/blob/master/Imager.js
// develop your JavaScript library to support RequireJS/CommonJS/vanilla JavaScript
;(function (window, document) {
'use strict';
var Imager = function () {
};
Imager.prototype = {
};
/* global module, exports: true, define */
if (typeof module === 'object' && typeof module.exports === 'object') {
// CommonJS, just export
module.exports = exports = Imager;
} else if (typeof define === 'function' && define.amd) {
// AMD support
define(function () { return Imager; });
} else if (typeof window === 'object') {
// If no AMD and we are in the browser, attach to window
window.Imager = Imager;
}
/* global -module, -exports, -define */
}(window, document));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment