1
1
mirror of https://github.com/go-gitea/gitea synced 2024-11-06 02:04:26 +00:00
gitea/web_src/js/utils.js

26 lines
806 B
JavaScript
Raw Normal View History

// retrieve a HTML string for given SVG icon name and size in pixels
export function svg(name, size) {
return `<svg class="svg ${name}" width="${size}" height="${size}" aria-hidden="true"><use xlink:href="#${name}"/></svg>`;
}
// 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');
}