Skip to content

Commit

Permalink
feat(pwa-helper): get config utils
Browse files Browse the repository at this point in the history
  • Loading branch information
njfamirm committed Feb 1, 2023
1 parent bfa4221 commit df0b593
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions ui/pwa-helper/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
declare global {
// eslint-disable-next-line no-var
var appConfig: Record<string, string | number | boolean | undefined> | undefined;
}

const debugConfig = localStorage.getItem('DEBUG_CONFIG');
if (debugConfig != null) {
globalThis.appConfig = JSON.parse(debugConfig);
}

export function getConfKey<T extends string | number | boolean>(key: string): T {
const val = globalThis.appConfig?.[key];
if (val == null) throw new Error('invalid_app_config', {cause: {key, val}});
return val as T;
}

0 comments on commit df0b593

Please sign in to comment.