You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
914 B

  1. // retrieve a HTML string for given SVG icon name and size in pixels
  2. export function svg(name, size) {
  3. return `<svg class="svg ${name}" width="${size}" height="${size}" aria-hidden="true"><use xlink:href="#${name}"/></svg>`;
  4. }
  5. // transform /path/to/file.ext to file.ext
  6. export function basename(path = '') {
  7. return path ? path.replace(/^.*\//, '') : '';
  8. }
  9. // transform /path/to/file.ext to .ext
  10. export function extname(path = '') {
  11. const [_, ext] = /.+(\.[^.]+)$/.exec(path) || [];
  12. return ext || '';
  13. }
  14. // test whether a variable is an object
  15. export function isObject(obj) {
  16. return Object.prototype.toString.call(obj) === '[object Object]';
  17. }
  18. // returns whether a dark theme is enabled
  19. export function isDarkTheme() {
  20. return document.documentElement.classList.contains('theme-arc-green');
  21. }
  22. // removes duplicate elements in an array
  23. export function uniq(arr) {
  24. return Array.from(new Set(arr));
  25. }