Download src/lib/spells/extract.svelte.ts from huggingface/inference-playground: direct link, hf CLI and curl.
- Browser
- Download file 670 Bytes
-
https://huggingface.co/spaces/huggingface/inference-playground/resolve/main/src/lib/spells/extract.svelte.ts
- Command line
-
hf download hf://spaces/huggingface/inference-playground/src/lib/spells/extract.svelte.ts
-
curl -L -o extract.svelte.ts https://huggingface.co/spaces/huggingface/inference-playground/resolve/main/src/lib/spells/extract.svelte.ts
670 Bytes
| import { isFunction } from "$lib/utils/is.js"; | |
| import type { MaybeGetter } from "$lib/types.js"; | |
| /** | |
| * Extracts the value from a getter or a value. | |
| * Optionally, a default value can be provided. | |
| */ | |
| export function extract<T, D extends T>( | |
| value: MaybeGetter<T>, | |
| defaultValue?: D, | |
| ): D extends undefined | null ? T : Exclude<T, undefined | null> | D { | |
| if (isFunction(value)) { | |
| const getter = value; | |
| const gotten = getter(); | |
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | |
| return (gotten ?? defaultValue ?? gotten) as any; | |
| } | |
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | |
| return (value ?? defaultValue ?? value) as any; | |
| } | |