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.

utils.js 967B

123456789101112131415161718192021222324252627282930313233343536
  1. // transform /path/to/file.ext to file.ext
  2. export function basename(path = '') {
  3. return path ? path.replace(/^.*\//, '') : '';
  4. }
  5. // transform /path/to/file.ext to .ext
  6. export function extname(path = '') {
  7. const [_, ext] = /.+(\.[^.]+)$/.exec(path) || [];
  8. return ext || '';
  9. }
  10. // test whether a variable is an object
  11. export function isObject(obj) {
  12. return Object.prototype.toString.call(obj) === '[object Object]';
  13. }
  14. // returns whether a dark theme is enabled
  15. export function isDarkTheme() {
  16. return document.documentElement.classList.contains('theme-arc-green');
  17. }
  18. // removes duplicate elements in an array
  19. export function uniq(arr) {
  20. return Array.from(new Set(arr));
  21. }
  22. const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  23. // generate a random string
  24. export function random(length) {
  25. let str = '';
  26. for (let i = 0; i < length; i++) {
  27. str += chars.charAt(Math.floor(Math.random() * chars.length));
  28. }
  29. return str;
  30. }