aboutsummaryrefslogtreecommitdiffstats
path: root/utils/util.ts
blob: cc500e05ea981cf4ebd087d7ff617f9d9f59821b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const COLOR_CODE_REGEX = /&([0-9a-fk-or]|#[0-9A-F]{6})/ig;

export function stripColorCodes(str: string): string {
  return str.replace(COLOR_CODE_REGEX, '');
}

export function navigateToEditorPane(type: 'quest' | 'category' | 'item' | null, id?: string) {
  if (id) {
    if (type === 'category') {
      navigateTo({ path: '/category/' + id })
    } else if (type === 'quest') {
      navigateTo({ path: '/quest/' + id })
    } else if (type === 'item') {
      navigateTo({ path: '/item/' + id })
    }
  } else if (!id && !type) {
    navigateTo({ path: '/' })
  }
}

export type BrowserCapabilities = {
  canUseFsApi: boolean
}

export function getBrowserCapabilities(): BrowserCapabilities {
  return {
    canUseFsApi: typeof (window as any)?.showDirectoryPicker === 'function'
  }
}