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]) /**