INIT
This commit is contained in:
+15
@@ -0,0 +1,15 @@
|
||||
import type { MaybeGetter } from "../../internal/types.js";
|
||||
/**
|
||||
* Resolves a value that may be a getter function or a direct value.
|
||||
*
|
||||
* If the input is a function, it will be invoked to retrieve the actual value.
|
||||
* If the resolved value (or the input itself) is `undefined`, the optional
|
||||
* `defaultValue` is returned instead.
|
||||
*
|
||||
* @template T - The expected return type.
|
||||
* @param value - A value or a function that returns a value.
|
||||
* @param defaultValue - A fallback value returned if the resolved value is `undefined`.
|
||||
* @returns The resolved value or the default.
|
||||
*/
|
||||
export declare function extract<T>(value: MaybeGetter<T>): T;
|
||||
export declare function extract<T>(value: MaybeGetter<T | undefined>, defaultValue: T): T;
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
import { isFunction } from "../../internal/utils/is.js";
|
||||
export function extract(value, defaultValue) {
|
||||
if (isFunction(value)) {
|
||||
const getter = value;
|
||||
const gotten = getter();
|
||||
if (gotten === undefined)
|
||||
return defaultValue;
|
||||
return gotten;
|
||||
}
|
||||
if (value === undefined)
|
||||
return defaultValue;
|
||||
return value;
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
export { extract } from "./extract.svelte.js";
|
||||
+1
@@ -0,0 +1 @@
|
||||
export { extract } from "./extract.svelte.js";
|
||||
Reference in New Issue
Block a user