UNPKG

@sv-use/core

Version:

A collection of Svelte 5 utilities.

23 lines (22 loc) 716 B
export const noop = () => { }; export function toArray(v) { // @ts-expect-error Bypass type error return Array.isArray(v) ? v : [v]; } /** If function, return function value. Else, return value. */ export function normalizeValue(v) { // Using instanceof instead of typeof // https://github.com/microsoft/TypeScript/issues/37663 return v instanceof Function ? v() : v; } /** `true` if the value is not `null` nor `undefined`. `false` otherwise. */ export function notNullish(v) { return v !== null && v !== undefined; } export function asyncEffectRoot(cb) { let promise; const cleanup = $effect.root(() => { promise = cb(); }); return () => promise.finally(cleanup); }