This commit is contained in:
2026-01-05 12:47:14 +08:00
commit 1fc846fae3
1614 changed files with 162035 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
import { isPromise } from './is'
export type Interceptor = (...args: any[]) => Promise<boolean> | boolean | undefined | void
export function funInterceptor(interceptor: Interceptor | undefined, {
args = [],
done,
canceled,
}: {
args?: unknown[]
done: (val?: any) => void
canceled?: () => void
}) {
if (interceptor) {
const returnVal = interceptor(null, ...args)
if (isPromise(returnVal)) {
returnVal
.then((value) => {
if (value)
done(value)
else if (canceled)
canceled()
})
.catch(() => {})
}
else if (returnVal) {
done()
}
else if (canceled) {
canceled()
}
}
else {
done()
}
}