@humanspeak/svelte-motion
Version:
Framer Motion for Svelte 5. Declarative motion.<tag> components with AnimatePresence exit animations, gestures (hover, tap, drag, focus, in-view), variants, FLIP layout animations, shared-layout transitions, spring physics, and scroll-linked motion values
33 lines (32 loc) • 1.09 kB
JavaScript
/**
* Returns true if the provided value appears to be Promise-like.
*
* A value is considered Promise-like if it is a non-null object that exposes a
* callable `then` function. This conservative check avoids throwing on
* primitives and is resilient to different Promise implementations.
*
* @param value Value to test.
* @return Whether `value` is Promise-like.
*/
export const isPromiseLike = (value) => {
return (typeof value === 'object' &&
value !== null &&
'then' in value &&
typeof value.then === 'function');
};
/**
* Narrows to objects that expose a `finished` Promise.
*
* Motion's `animate` may return an object with a `finished` Promise, or a
* then-able control. This helper provides a safe type-guard for the former.
*
* @typeParam T Input object type.
* @param value Value to inspect.
* @return Whether `value.finished` is a Promise.
*/
export const hasFinishedPromise = (value) => {
return (typeof value === 'object' &&
value !== null &&
'finished' in value &&
isPromiseLike(value.finished));
};