diff options
Diffstat (limited to 'web_src/js/utils.js')
-rw-r--r-- | web_src/js/utils.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/web_src/js/utils.js b/web_src/js/utils.js index b000c1af77..b511c9981d 100644 --- a/web_src/js/utils.js +++ b/web_src/js/utils.js @@ -1,3 +1,25 @@ +// 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'); +} |