mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 12:50:38 -07:00
fix: use realpath for fs.contains (#867)
* fix: use realpath for fs.contains * chore: reset file mode changes Made-with: Cursor * fix: Windows compat for contains/containsSync and toLiquidAsync arg order Made-with: Cursor
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> (
|
||||
asyncFn: (...args: Parameters<F>) => Promise<ReturnType<F>>,
|
||||
syncFn?: F
|
||||
): LiquidAsync<F> {
|
||||
const syncImpl = syncFn || asyncFn as any
|
||||
return (sync: boolean, ...args: any[]) => {
|
||||
return sync ? syncImpl(...args as Parameters<F>) : asyncFn(...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