sandpit
Version:
A playground for creative coding using JavaScript and the canvas element
83 lines (68 loc) • 3.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* A utility for testing the type of a reference
*/
var Is = function () {
function Is() {
_classCallCheck(this, Is);
}
_createClass(Is, null, [{
key: 'element',
/**
* Tests if the object is a HTMLElement
* @param {object} object - The object to test
* @returns {boolean} If set to true, the object is a HTMLElement
*/
value: function element(object) {
// Credit: http://stackoverflow.com/a/384380
try {
// Using W3 DOM2 (works for FF, Opera and Chrom)
return object instanceof window.HTMLElement;
} catch (e) {
// Browsers not supporting W3 DOM2 don't have HTMLElement and
// an exception is thrown and we end up here. Testing some
// properties that all elements have. (works on IE7)
return (typeof object === 'undefined' ? 'undefined' : _typeof(object)) === 'object' && object.nodeType === 1 && _typeof(object.style) === 'object' && _typeof(object.ownerDocument) === 'object';
}
}
/**
* Tests if the object is an array
* @param {object} object - The object to test
* @returns {boolean} If set to true, the object is an array
*/
}, {
key: 'array',
value: function array(object) {
return Object.prototype.toString.call(object) === '[object Array]';
}
/**
* Tests if the object is an object, not an array
* @param {object} object - The object to test
* @returns {boolean} If set to true, the object is an object
*/
}, {
key: 'object',
value: function object(_object) {
return (typeof _object === 'undefined' ? 'undefined' : _typeof(_object)) === 'object' && !this.array(_object);
}
/**
* Tests if the object is a canvas
* @param {object} object - The object to test
* @returns {boolean} If set to true, the object is a canvas
*/
}, {
key: 'canvas',
value: function canvas(object) {
return !!object.getContext;
}
}]);
return Is;
}();
exports.default = Is;
module.exports = exports['default'];