2020-05-14 16:06:01 +00:00
|
|
|
// transform /path/to/file.ext to file.ext
|
|
|
|
export function basename(path = '') {
|
|
|
|
return path ? path.replace(/^.*\//, '') : '';
|
|
|
|
}
|
|
|
|
|
|
|
|
// transform /path/to/file.ext to .ext
|
|
|
|
export function extname(path = '') {
|
|
|
|
const [_, ext] = /.+(\.[^.]+)$/.exec(path) || [];
|
|
|
|
return ext || '';
|
|
|
|
}
|
|
|
|
|
|
|
|
// test whether a variable is an object
|
|
|
|
export function isObject(obj) {
|
|
|
|
return Object.prototype.toString.call(obj) === '[object Object]';
|
|
|
|
}
|
|
|
|
|
|
|
|
// returns whether a dark theme is enabled
|
|
|
|
export function isDarkTheme() {
|
|
|
|
return document.documentElement.classList.contains('theme-arc-green');
|
|
|
|
}
|
2020-05-21 02:00:43 +00:00
|
|
|
|
2020-12-17 16:39:12 +00:00
|
|
|
// returns if mobile device
|
|
|
|
export function isMobile() {
|
|
|
|
return /Mobi/.test(navigator.userAgent);
|
|
|
|
}
|
|
|
|
|
2020-05-21 02:00:43 +00:00
|
|
|
// removes duplicate elements in an array
|
|
|
|
export function uniq(arr) {
|
|
|
|
return Array.from(new Set(arr));
|
|
|
|
}
|
2020-07-27 06:24:09 +00:00
|
|
|
|
|
|
|
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
|
|
|
|
|
|
// generate a random string
|
|
|
|
export function random(length) {
|
|
|
|
let str = '';
|
|
|
|
for (let i = 0; i < length; i++) {
|
|
|
|
str += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|