X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=ui%2Fweb%2Fsrc%2Fcomposables%2FUtils.ts;h=0c8a83996e905c7e046d624ad9a8bd64124d1df1;hb=cffc32b7bc5a6569525e92b562af8a93760bc339;hp=8db8851ad646819e43a6fa4dbb53bf245d06badd;hpb=39cd8fcbac08d293817365362ee90260a07b189d;p=e-mobility-charging-stations-simulator.git diff --git a/ui/web/src/composables/Utils.ts b/ui/web/src/composables/Utils.ts index 8db8851a..0c8a8399 100644 --- a/ui/web/src/composables/Utils.ts +++ b/ui/web/src/composables/Utils.ts @@ -35,15 +35,15 @@ export const convertToInt = (value: unknown): number => { return changedValue } -export const setToLocalStorage = (key: string, value: T): void => { - localStorage.setItem(key, JSON.stringify(value)) -} - export const getFromLocalStorage = (key: string, defaultValue: T): T => { const item = localStorage.getItem(key) return item != null ? (JSON.parse(item) as T) : defaultValue } +export const setToLocalStorage = (key: string, value: T): void => { + localStorage.setItem(key, JSON.stringify(value)) +} + export const deleteFromLocalStorage = (key: string): void => { localStorage.removeItem(key) } @@ -56,6 +56,12 @@ export const randomUUID = (): `${string}-${string}-${string}-${string}-${string} return crypto.randomUUID() } +export const validateUUID = ( + uuid: `${string}-${string}-${string}-${string}-${string}` +): uuid is `${string}-${string}-${string}-${string}-${string}` => { + return /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test(uuid) +} + export const useUIClient = (): UIClient => { return UIClient.getInstance() }