node-vitals
Version:
Do more with less. A simple, high-performing, functional JavaScript library.
95 lines (82 loc) • 2.57 kB
JavaScript
/**
* -----------------------------------------------------------------------------
* VITALS JS - EXPORT FOR ALL ENVIRONMENTS
* -----------------------------------------------------------------------------
* @version 4.1.3
* @see [vitals]{@link https://github.com/imaginate/vitals}
*
* @author Adam Smith <adam@imaginate.life> (https://github.com/imaginate)
* @copyright 2017 Adam A Smith <adam@imaginate.life> (https://github.com/imaginate)
*
* Annotations:
* @see [JSDoc3](http://usejsdoc.org)
* @see [Closure Compiler JSDoc Syntax](https://developers.google.com/closure/compiler/docs/js-for-compiler)
*/
////////////////////////////////////////////////////////////////////////////////
// EXPORT VITALS
////////////////////////////////////////////////////////////////////////////////
;(function(/** Object= */ root, /** !Object */ vitals) {
/** @type {!Object} */
var checks = {
exp: isObj(typeof exports) && getObj(exports, true),
mod: isObj(typeof module) && getObj(module, true),
glo: isObj(typeof global, true) && getObj(global),
win: isObj(typeof window) && getObj(window),
sel: isObj(typeof self) && getObj(self),
roo: isObj(typeof root) && getObj(root)
};
checks.glo = checks.exp && checks.mod && checks.glo;
root = ( checks.glo ?
global : checks.win && window !== (root && root.window) ?
window : checks.sel ?
self : checks.roo ?
root : Function('return this')()
);
// window | self | global | this
checks.win && setVitals(window);
checks.sel && setVitals(self);
setVitals(root);
// exports
if (checks.exp && checks.mod) {
if (module.exports === exports) {
module.exports = vitals;
}
else {
setVitals(exports);
}
}
// AMD
if (typeof define === 'function' && define.amd &&
typeof define.amd === 'object') {
define(function() {
return vitals;
});
}
/**
* @private
* @param {string} typeOf
* @param {boolean=} noFunc
* @return {boolean}
*/
function isObj(typeOf, noFunc) {
return typeOf === 'object' || (!noFunc && typeOf === 'function');
}
/**
* @private
* @param {(Object|?function)} obj
* @param {boolean=} testNodeType
* @return {boolean}
*/
function getObj(obj, testNodeType) {
obj = obj && testNodeType && obj.nodeType ? false : obj;
return obj && !testNodeType && obj.Object !== Object ? false : !!obj;
}
/**
* @private
* @param {!Object} obj
*/
function setVitals(obj) {
obj.vitals = vitals;
obj.Vitals = vitals;
}
})(this,