Files
parcoursup/node_modules/@riotjs/util/checks.cjs
T

97 lines
2.3 KiB
JavaScript

'use strict';
var constants = require('./constants.cjs');
/**
* Quick type checking
* @param {*} element - anything
* @param {string} type - type definition
* @returns {boolean} true if the type corresponds
*/
function checkType(element, type) {
return typeof element === type
}
/**
* Check if an element is part of an svg
* @param {HTMLElement} el - element to check
* @returns {boolean} true if we are in an svg context
*/
function isSvg(el) {
const owner = el.ownerSVGElement;
return !!owner || owner === null
}
/**
* Check if an element is a template tag
* @param {HTMLElement} el - element to check
* @returns {boolean} true if it's a <template>
*/
function isTemplate(el) {
return el.tagName.toLowerCase() === 'template'
}
/**
* Check that will be passed if its argument is a function
* @param {*} value - value to check
* @returns {boolean} - true if the value is a function
*/
function isFunction(value) {
return checkType(value, 'function')
}
/**
* Check if a value is a Boolean
* @param {*} value - anything
* @returns {boolean} true only for the value is a boolean
*/
function isBoolean(value) {
return checkType(value, 'boolean')
}
/**
* Check if a value is an Object
* @param {*} value - anything
* @returns {boolean} true only for the value is an object
*/
function isObject(value) {
return !isNil(value) && value.constructor === Object
}
/**
* Check if a value is null or undefined
* @param {*} value - anything
* @returns {boolean} true only for the 'undefined' and 'null' types
*/
function isNil(value) {
return value === null || value === undefined
}
/**
* Detect node js environment
* @returns {boolean} true if the runtime is node
*/
function isNode() {
return typeof globalThis.process !== 'undefined'
}
/**
* Check if an attribute is a DOM handler
* @param {string} attribute - attribute string
* @returns {boolean} true only for dom listener attribute nodes
*/
function isEventAttribute(attribute) {
return constants.EVENT_ATTRIBUTE_RE.test(attribute)
}
exports.checkType = checkType;
exports.isBoolean = isBoolean;
exports.isEventAttribute = isEventAttribute;
exports.isFunction = isFunction;
exports.isNil = isNil;
exports.isNode = isNode;
exports.isObject = isObject;
exports.isSvg = isSvg;
exports.isTemplate = isTemplate;