UNPKG

@thepassle/app-tools

Version:

Collection of tools I regularly use to build apps. Maybe they're useful to somebody else. Maybe not. Most of these are thin wrappers around native API's, like the native `<dialog>` element, `fetch` API, and `URLPattern`.

21 lines (20 loc) 591 B
import { setAbortableTimeout } from '../../utils/async.js'; /** * @param {Response | (() => Response) | (() => Promise<Response>)} response * @returns {import('../index.js').Plugin} */ export function mock(response) { return { name: 'mock', beforeFetch: (meta) => { meta.fetchFn = function mock(_, opts) { return new Promise(r => setAbortableTimeout( () => r(typeof response === 'function' ? response() : response), Math.random() * 1000, opts?.signal ? { signal: opts.signal } : {} )) } return meta; } } }