2022-05-26 15:18:53 +08:00
|
|
|
export const isMobile = () => {
|
2023-01-26 18:53:57 +08:00
|
|
|
return document.getElementById("sidebar") ? true : false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const isWindow = () => {
|
|
|
|
|
return document.getElementById("toolbar") ? false : true;
|
2022-05-26 15:18:53 +08:00
|
|
|
};
|
|
|
|
|
|
2022-11-02 18:46:34 +08:00
|
|
|
export const isTouchDevice = () => {
|
2022-11-09 10:25:56 +08:00
|
|
|
return ("ontouchstart" in window) && navigator.maxTouchPoints > 1;
|
2022-11-02 18:46:34 +08:00
|
|
|
};
|
|
|
|
|
|
2022-09-13 23:31:12 +08:00
|
|
|
export const isArrayEqual = (arr1: string[], arr2: string[]) => {
|
|
|
|
|
return arr1.length === arr2.length && arr1.every((item) => arr2.includes(item));
|
2022-09-14 11:18:44 +08:00
|
|
|
};
|
2022-09-13 23:31:12 +08:00
|
|
|
|
2022-05-26 15:18:53 +08:00
|
|
|
export const getRandom = (min: number, max: number) => {
|
|
|
|
|
return Math.floor(Math.random() * (max - min + 1)) + min; //含最大值,含最小值
|
|
|
|
|
};
|
2022-07-27 07:17:45 +08:00
|
|
|
|
2023-01-19 20:57:33 +08:00
|
|
|
export const getSearch = (key: string, link = window.location.search) => {
|
|
|
|
|
const params = link.substring(link.indexOf("?"));
|
|
|
|
|
const hashIndex = params.indexOf("#");
|
2023-01-19 20:46:53 +08:00
|
|
|
// REF https://developer.mozilla.org/zh-CN/docs/Web/API/URLSearchParams
|
2023-01-19 20:57:33 +08:00
|
|
|
const urlSearchParams = new URLSearchParams(params.substring(0, hashIndex >= 0 ? hashIndex : undefined));
|
2023-01-19 20:46:53 +08:00
|
|
|
return urlSearchParams.get(key);
|
2022-05-26 15:18:53 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const isBrowser = () => {
|
|
|
|
|
/// #if BROWSER
|
|
|
|
|
return true;
|
|
|
|
|
/// #else
|
|
|
|
|
return false;
|
|
|
|
|
/// #endif
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const isDynamicRef = (text: string) => {
|
|
|
|
|
return /^\(\(\d{14}-\w{7} '.*'\)\)$/.test(text);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const isFileAnnotation = (text: string) => {
|
|
|
|
|
return /^<<assets\/.+\/\d{14}-\w{7} ".+">>$/.test(text);
|
|
|
|
|
};
|
2022-12-25 10:27:02 +08:00
|
|
|
|
|
|
|
|
// REF https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/eval
|
|
|
|
|
export const looseJsonParse = (text: string) => {
|
|
|
|
|
return Function(`"use strict";return (${text})`)();
|
2022-12-25 10:31:01 +08:00
|
|
|
};
|