diff --git a/src/js/config.ts b/src/js/config.ts index c02ce2e4..f993fb6c 100644 --- a/src/js/config.ts +++ b/src/js/config.ts @@ -1,9 +1,11 @@ +import { stringToBoolean } from '@/utils/strings'; + interface PublicConfig { CLIENT_NAME: string; PORTAL_URL: string; TRANSLATED: boolean; BEACON_URL: string; - BEACON_UI_ENABLED: boolean; + BEACON_UI_ENABLED: string; PUBLIC_URL: string; CLIENT_ID: string; OPENID_CONFIG_URL: string; @@ -17,7 +19,9 @@ export const CLIENT_NAME = BENTO_PUBLIC_CONFIG.CLIENT_NAME ?? process.env.BENTO_ export const PORTAL_URL = BENTO_PUBLIC_CONFIG.PORTAL_URL ?? process.env.BENTO_PUBLIC_PORTAL_URL; export const TRANSLATED = BENTO_PUBLIC_CONFIG.TRANSLATED ?? process.env.BENTO_PUBLIC_TRANSLATED; export const BEACON_URL = BENTO_PUBLIC_CONFIG.BEACON_URL ?? process.env.BEACON_URL; -export const BEACON_UI_ENABLED = BENTO_PUBLIC_CONFIG.BEACON_UI_ENABLED ?? process.env.BENTO_BEACON_UI_ENABLED; +export const BEACON_UI_ENABLED = stringToBoolean( + BENTO_PUBLIC_CONFIG.BEACON_UI_ENABLED ?? process.env.BENTO_BEACON_UI_ENABLED +); // Authentication export const PUBLIC_URL = BENTO_PUBLIC_CONFIG.PUBLIC_URL ?? process.env.BENTO_PUBLIC_URL ?? ''; diff --git a/src/js/utils/strings.ts b/src/js/utils/strings.ts index a30bd27d..ed81489f 100644 --- a/src/js/utils/strings.ts +++ b/src/js/utils/strings.ts @@ -1,4 +1,6 @@ import { DOI_PATTERN, URL_PATTERN } from '@/constants/patterns'; +export const stringToBoolean = (s: string) => ['true', 't', '1', 'yes'].includes((s || '').toLocaleLowerCase()); + export const stringIsDOI = (s: string) => !!s.match(DOI_PATTERN); export const stringIsURL = (s: string) => !!s.match(URL_PATTERN);