From 866b140a96c45b74bcc0d0bb2143eda6358d7c8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pete=20An=C3=B8ther?= Date: Tue, 12 Mar 2024 08:01:27 -0300 Subject: [PATCH] EZQMS-649: Moved some common utilities from Uberflow to Platform (#4927) Signed-off-by: Petr Vyazovetskiy --- packages/core/src/utils.ts | 11 +++++++++++ packages/ui/src/location.ts | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/packages/core/src/utils.ts b/packages/core/src/utils.ts index f85d13d44a..fe9773ad7a 100644 --- a/packages/core/src/utils.ts +++ b/packages/core/src/utils.ts @@ -49,6 +49,11 @@ export function generateId (join: string = ''): Ref { return (timestamp() + join + random + join + count()) as Ref } +/** @public */ +export function isId (value: any): value is Ref { + return typeof value === 'string' && /^[0-9a-f]{24,24}$/.test(value) +} + let currentAccount: Account /** @@ -531,3 +536,9 @@ export function cutObjectArray (obj: any): any { } return r } + +export const isEnum = + (e: T) => + (token: any): token is T[keyof T] => { + return typeof token === 'string' && Object.values(e as Record).includes(token) + } diff --git a/packages/ui/src/location.ts b/packages/ui/src/location.ts index 066313e07e..d92a663858 100644 --- a/packages/ui/src/location.ts +++ b/packages/ui/src/location.ts @@ -132,6 +132,11 @@ if (!embeddedPlatform) { export const location = derived(locationWritable, (loc) => justClone(loc)) +/** + * Unlike {@link location}, exposes raw browser location as seen in URL + */ +export const rawLocation = derived(locationWritable, () => getCurrentLocation()) + export const workspaceId = derived(location, (loc) => loc.path[1]) /**