@antdv/pro-utils
Version:
@antdv/pro-utils
119 lines (118 loc) • 3.09 kB
JavaScript
import { Comment, Fragment, isVNode, Text } from "vue";
function isNumeric(value) {
return !Number.isNaN(Number.parseFloat(value)) && Number.isFinite(value);
}
function isNil(value) {
return value === null || value === void 0;
}
function isValidValue(val) {
return val !== void 0 && val !== null;
}
function isValid(value) {
return value !== void 0 && value !== null && value !== "";
}
function isWindow(obj) {
return obj !== null && obj !== void 0 && obj === obj.window;
}
function isFunction(value) {
return typeof value === "function";
}
const isArray = Array.isArray;
const isString = (val) => typeof val === "string";
const isSymbol = (val) => typeof val === "symbol";
const isObject = (val) => val !== null && typeof val === "object";
function isFragment(node) {
return isVNode(node) && node.type === Fragment;
}
function isText(node) {
return isVNode(node) && node.type === Text;
}
function isComment(node) {
return isVNode(node) && node.type === Comment;
}
const TEMPLATE = "template";
function isTemplate(node) {
return isVNode(node) && node.type === TEMPLATE;
}
function isValidElementNode(node) {
return isVNode(node) && !isFragment(node) && !isComment(node);
}
function isEmptyContent(c) {
return c === void 0 || c === null || c === "" || Array.isArray(c) && c.length === 0;
}
function isEmptyElement(c) {
return c && (c.type === Comment || c.type === Fragment && c.children.length === 0 || c.type === Text && c.children.trim() === "");
}
function isEmptySlot(c) {
return !c || c().every(isEmptyElement);
}
function isStringElement(c) {
return c && c.type === Text;
}
function isValidElement(element) {
if (Array.isArray(element) && element.length === 1)
element = element[0];
return element && element.__v_isVNode && typeof element.type !== "symbol";
}
function isVisible(element) {
if (!element)
return false;
if (element.offsetParent)
return true;
if (element.getBBox) {
const box = element.getBBox();
if (box.width || box.height)
return true;
}
if (element.getBoundingClientRect) {
const box = element.getBoundingClientRect();
if (box.width || box.height)
return true;
}
return false;
}
function isImg(path) {
return /\w.(png|jpg|jpeg|svg|webp|gif|bmp)$/i.test(path);
}
function isUrl(path) {
if (!path) return false;
if (!path.startsWith("http")) {
return false;
}
try {
const url = new URL(path);
return !!url;
} catch (error) {
return false;
}
}
const isNode = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
function isBrowser() {
return typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.matchMedia !== "undefined" && !isNode;
}
export {
isArray,
isBrowser,
isComment,
isEmptyContent,
isEmptyElement,
isEmptySlot,
isFragment,
isFunction,
isImg,
isNil,
isNumeric,
isObject,
isString,
isStringElement,
isSymbol,
isTemplate,
isText,
isUrl,
isValid,
isValidElement,
isValidElementNode,
isValidValue,
isVisible,
isWindow
};