( interceptors: Interceptor<TOptions, TResult>[], options: NoInfer<TOptions>, main: NoInfer<(options: TOptions) => TResult>, )
| 97 | } |
| 98 | |
| 99 | export function intercept<TOptions extends InterceptableOptions, TResult>( |
| 100 | interceptors: Interceptor<TOptions, TResult>[], |
| 101 | options: NoInfer<TOptions>, |
| 102 | main: NoInfer<(options: TOptions) => TResult>, |
| 103 | ): TResult { |
| 104 | const next = (options: TOptions, index: number): TResult => { |
| 105 | const interceptor = interceptors[index] |
| 106 | |
| 107 | if (!interceptor) { |
| 108 | return main(options) |
| 109 | } |
| 110 | |
| 111 | return interceptor({ |
| 112 | ...options, |
| 113 | next: (newOptions: TOptions = options) => next(newOptions, index + 1), |
| 114 | }) |
| 115 | } |
| 116 | |
| 117 | return next(options, 0) |
| 118 | } |
no test coverage detected