UNPKG

birdpaper-ui

Version:

一个通用的 vue3 UI组件库。A common vue3 UI component library.

74 lines (73 loc) 2.07 kB
"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const isNull = (data) => !data && data != 0; const isString = (data) => typeof data === "string"; function throttle(func, delay = 20) { let lastExecution = 0; return function(...args) { const now = Date.now(); if (now - lastExecution >= delay) { lastExecution = now; func(...args); } }; } const on = function(element, event, handler, useCapture = false) { if (element && event && handler) { element.addEventListener(event, handler, useCapture); } }; const off = function(element, event, handler, useCapture = false) { if (element && event && handler) { element.removeEventListener(event, handler, useCapture); } }; const warn = (module2, info) => { console.warn(`[ A warning of birdpaper-ui ] - ${module2}: ` + info); }; const isArray = (obj) => { return obj && typeof obj == "object" && obj instanceof Array; }; function deepClone(tSource, tTarget) { if (isArray(tSource)) { tTarget = tTarget || []; } else { tTarget = tTarget || {}; } for (const key in tSource) { if (Object.prototype.hasOwnProperty.call(tSource, key)) { if (typeof tSource[key] === "object" && typeof tSource[key] !== null) { tTarget[key] = isArray(tSource[key]) ? [] : {}; deepClone(tSource[key], tTarget[key]); } else { tTarget[key] = tSource[key]; } } } return tTarget; } function arrayIndexOf(arr, field, fieldValue) { for (let i = 0; i < arr.length; i++) { const element = arr[i]; if (element[field] === fieldValue) return i; } return -1; } function generateArray(len) { const result = []; for (let i = 0; i < len; i++) { result.push(i.toString().padStart(2, "0")); } return result; } exports.arrayIndexOf = arrayIndexOf; exports.deepClone = deepClone; exports.generateArray = generateArray; exports.isArray = isArray; exports.isNull = isNull; exports.isString = isString; exports.off = off; exports.on = on; exports.throttle = throttle; exports.warn = warn;