2020-05-15 01:06:01 +09:00
|
|
|
// retrieve a HTML string for given SVG icon name and size in pixels
|
2020-02-12 10:53:18 +09:00
|
|
|
export function svg(name, size) {
|
2020-02-18 15:07:58 +09:00
|
|
|
return `<svg class="svg ${name}" width="${size}" height="${size}" aria-hidden="true"><use xlink:href="#${name}"/></svg>`;
|
2020-02-12 10:53:18 +09:00
|
|
|
}
|
2020-05-15 01:06:01 +09: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 11:00:43 +09:00
|
|
|
|
|
|
|
// removes duplicate elements in an array
|
|
|
|
export function uniq(arr) {
|
|
|
|
return Array.from(new Set(arr));
|
|
|
|
}
|