mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-19 14:30:38 -07:00
fix: use realpath for fs.contains
This commit is contained in:
@@ -1,5 +1,18 @@
|
||||
import { isPromise, isIterator } from './underscore'
|
||||
|
||||
export type LiquidAsync<F extends (...args: any[]) => any> =
|
||||
(sync: boolean, ...args: Parameters<F>) => ReturnType<F> | Promise<ReturnType<F>>
|
||||
|
||||
export function toLiquidAsync<F extends (...args: any[]) => any> (
|
||||
syncFn: F,
|
||||
asyncFn?: (...args: Parameters<F>) => Promise<ReturnType<F>>
|
||||
): LiquidAsync<F> {
|
||||
const asyncImpl = asyncFn || syncFn as any
|
||||
return (sync: boolean, ...args: any[]) => {
|
||||
return sync ? syncFn(...args as Parameters<F>) : asyncImpl(...args as Parameters<F>)
|
||||
}
|
||||
}
|
||||
|
||||
// convert an async iterator to a Promise
|
||||
export async function toPromise<T> (val: Generator<unknown, T, unknown> | Promise<T> | T): Promise<T> {
|
||||
if (!isIterator(val)) return val
|
||||
|
||||
Reference in New Issue
Block a user