EZQMS-649: Moved some common utilities from Uberflow to Platform (#4927)

Signed-off-by: Petr Vyazovetskiy <develop.pit@gmail.com>
This commit is contained in:
Pete Anøther 2024-03-12 08:01:27 -03:00 committed by GitHub
parent aac81144fe
commit 866b140a96
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 0 deletions

View File

@ -49,6 +49,11 @@ export function generateId<T extends Doc> (join: string = ''): Ref<T> {
return (timestamp() + join + random + join + count()) as Ref<T>
}
/** @public */
export function isId (value: any): value is Ref<any> {
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 =
<T>(e: T) =>
(token: any): token is T[keyof T] => {
return typeof token === 'string' && Object.values(e as Record<string, any>).includes(token)
}

View File

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