asp-smart-ui-plus-test
Version:
A Component Library for Vue 3
133 lines (129 loc) • 3.81 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
const aspDebounce = (func, wait, immediate) => {
let timeout, args, context, timestamp, result;
const later = () => {
const last = Date.now() - timestamp;
if (last < wait && last > 0) {
timeout = window.setTimeout(later, wait - last);
} else {
timeout = null;
if (!immediate) {
result = func.apply(context, args);
if (!timeout)
context = args = null;
}
}
};
return function(...args2) {
context = this;
timestamp = Date.now();
const callNow = immediate && !timeout;
if (!timeout)
timeout = window.setTimeout(later, wait);
if (callNow) {
result = func.apply(context, args2);
}
return result;
};
};
const _timeQueue = {};
function aspDebounceMulti(func, wait, immediate, namespace = "_") {
clearTimeout(_timeQueue[namespace]);
if (immediate) {
func();
} else {
_timeQueue[namespace] = window.setTimeout(() => {
func();
}, wait);
}
}
function aspDeepClone(source) {
if (source === null) {
return null;
}
if (typeof source !== "object") {
throw new TypeError("error arguments");
}
if (Array.isArray(source)) {
return source.map((item) => aspDeepClone(item));
} else {
return Object.keys(source).reduce((targetObj, key) => {
const _key = key;
if (source[_key] !== null) {
targetObj[_key] = typeof source[_key] === "object" ? aspDeepClone(source[_key]) : source[_key];
}
return targetObj;
}, {});
}
}
const aspRandomNumber = (min, max) => {
return Math.floor(Math.random() * (max - min + 1)) + min;
};
const asprandomNumString = (min, max, bitNumber, radix) => {
let result = "";
for (let i = 0; i < bitNumber; i++) {
result += aspRandomNumber(min, max).toString(radix);
}
return result.toUpperCase();
};
const aspGenerateUUID = () => {
let d = Date.now();
if (window.performance && typeof window.performance.now === "function") {
d += performance.now();
}
const uuid = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
const r = Math.trunc((d + Math.random() * 16) % 16);
d = Math.floor(d / 16);
return (c === "x" ? r : r & 3 | 8).toString(16);
});
return uuid;
};
const aspTimestampChange = (num = 0, date = false) => {
let timestamp = 0;
if (!date) {
timestamp = Date.now();
} else if (typeof date === "string") {
timestamp = new Date(date).getTime();
}
timestamp += 86400 * 1e3 * num;
return timestamp;
};
const aspGetQueryString = (name) => {
if (window) {
const reg = new RegExp(`(^|&)${name}=([^&]*)(&|$)`, "i");
const search = window.location.search ? window.location.search : window.location.hash.split("?")[1];
const r = search ? search.slice(1).match(reg) : null;
if (r != null)
return decodeURI(r[2]);
}
return null;
};
function aspGetBase64ByBlob(data, imageType) {
const blob = new Blob([data], { type: imageType });
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(blob);
reader.onload = () => resolve(reader.result);
reader.onerror = (error) => reject(error);
});
}
var common = {
aspDebounce,
aspDeepClone,
aspRandomNumber,
aspGenerateUUID,
aspTimestampChange,
aspGetQueryString,
aspGetBase64ByBlob
};
exports.aspDebounce = aspDebounce;
exports.aspDebounceMulti = aspDebounceMulti;
exports.aspDeepClone = aspDeepClone;
exports.aspGenerateUUID = aspGenerateUUID;
exports.aspGetBase64ByBlob = aspGetBase64ByBlob;
exports.aspGetQueryString = aspGetQueryString;
exports.aspRandomNumber = aspRandomNumber;
exports.aspTimestampChange = aspTimestampChange;
exports.asprandomNumString = asprandomNumString;
exports["default"] = common;