Plato on Github
Report Home
node_modules\atropa-header\src\atropa-header.js
Maintainability
66.94
Lines of code
109
Difficulty
27.00
Estimated Errors
0.33
Function weight
By Complexity
By SLOC
/// <reference path="../docs/vsdoc/OpenLayersAll.js"/> /*jslint indent: 4, maxerr: 50, white: true, browser: true, devel: true, plusplus: true, regexp: true */ /*global XPathResult */ // end header /** * Container for all Glorious classes, functions, etc. * @author <a href="mailto:matthewkastor@gmail.com"> * Matthew Christopher Kastor-Inare III </a><br /> * ☭ Hial Atropa!! ☭ * @namespace Container for all Glorious classes, functions, etc. */ var atropa = {}; /** * Checks whether this class has been marked as unsupported and throws an * error if it has. * @author <a href="mailto:matthewkastor@gmail.com"> * Matthew Christopher Kastor-Inare III </a><br /> * ☭ Hial Atropa!! ☭ * @version 20130308 * @param {String} className The name of the class. * @param {String} errorMessage Optional. A custom error message. Defaults to * atropa.data[className].error */ atropa.supportCheck = function (className, errorMessage) { "use strict"; className = String(className); errorMessage = errorMessage || atropa.data[className].error; errorMessage = String(errorMessage); if(atropa.data[className].support === 'unsupported') { throw new Error(errorMessage); } }; /** * Pushes a requirement check into atropa.data.requirements. The test * tests whether the class is supported in this environment. Sets * atropa.data[className]'s support to unsupported and error to errorMessage * if the requirementFn returns false. The requirement checks will all be run * after the library has loaded. * @author <a href="mailto:matthewkastor@gmail.com"> * Matthew Christopher Kastor-Inare III </a><br /> * ☭ Hial Atropa!! ☭ * @version 20130308 * @param {String} className The name of the class. * @param {Function} requirementFn A function to test whether or not the class * is supported in this environment. If supported, returns true otherwise * return false. * @param {String} errorMessage The error message to use when this class or its * methods are called in unsupported environments. Defaults to: * 'The atropa.' + className + ' class is unsupported in this environment.'; */ atropa.requires = function (className, requirementFn, errorMessage) { "use strict"; var check = function () { var test = false; if(typeof className !== 'string') { throw new Error('atropa.requires requires the class name to be ' + 'specified'); } if(atropa.data[className] === undefined) { atropa.data[className] = {}; if(typeof requirementFn !== 'function') { requirementFn = false; } errorMessage = errorMessage || 'The atropa.' + className + ' class is unsupported in this environment.'; try { test = requirementFn(); } catch (e) { test = false; } atropa.data[className].error = errorMessage; if(test === false) { atropa.data[className].support = 'unsupported'; } } }; atropa.data.requirements.push(check); }; /** * Container for gobal data related to the classes and functions. * @author <a href="mailto:matthewkastor@gmail.com"> * Matthew Christopher Kastor-Inare III </a><br /> * ☭ Hial Atropa!! ☭ * @namespace Container for gobal data related to the classes and functions. */ atropa.data = {}; atropa.data.requirements = []; atropa.nop = function nop () { "use strict"; return null; }; module.exports = atropa;