UNPKG

@sanity/import

Version:

Import documents to a Sanity dataset

31 lines (24 loc) 666 B
import {type ProgressEvent} from '../types.js' interface ProgressStepperOptions { step: string total: number } function progressStepper<T>( onProgress: (event: ProgressEvent) => void, options: ProgressStepperOptions, ): (inp?: T) => T { let current = -1 // Stepper function which increments progress up to defined total and returns // input argument verbatim so it may be used in the middle of a promise chain const step = (inp?: T): T => { onProgress({ current: Math.min(++current, options.total), step: options.step, total: options.total, }) return inp as T } step() return step } export {progressStepper}