This repository has been archived by the owner on Aug 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
/
index.d.ts
143 lines (121 loc) · 4.14 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// Type definitions for thunks
// Project: https://github.com/thunks/thunks
// Definitions by: zensh <https://github.com/zensh>
// Import: `import * as thunks from 'thunks'`
// Import: `import { thunk, thunks, isGeneratorFn } from 'thunks'`
type primitives = boolean | number | string | Array<any> | Object | void;
type thunkable = ThunkLikeFunction | GeneratorFunction | AsyncFunction | PromiseLike | ToThunk | ToPromise | Generator;
type FunctionWithCallback = FnWithCb0 | FnWithCb1 | FnWithCb2 | FnWithCb3 | FnWithCb4 | FnWithCb5;
type ThunkOptions = ScopeOnerror | ScopeOptions | thunks.Scope
interface Callback {
(err?: Error, res?: primitives): primitives | thunkable;
}
interface ThunkLikeFunction {
(fn: Callback): void;
}
interface ThunkFunction<T> {
(fn?: Callback | GeneratorFunction | AsyncFunction): ThunkFunction<T>;
}
interface NodeCallback {
(err?: Error, ...args: Array<any>): void;
}
interface FnWithCb0 {
(callback: NodeCallback): void;
}
interface FnWithCb1 {
(arg1: any, callback: NodeCallback): void;
}
interface FnWithCb2 {
(arg1: any, arg2: any, callback: NodeCallback): void;
}
interface FnWithCb3 {
(arg1: any, arg2: any, arg3: any, callback: NodeCallback): void;
}
interface FnWithCb4 {
(arg1: any, arg2: any, arg3: any, arg4: any, callback: NodeCallback): void;
}
interface FnWithCb5 {
(arg1: any, arg2: any, arg3: any, arg4: any, arg5: any, callback: NodeCallback): void;
}
interface ToThunk {
toThunk(): ThunkLikeFunction;
}
interface ToPromise {
toPromise(): PromiseLike;
}
interface GeneratorFunction extends Function {
(err?: Error, res?: primitives): Generator;
}
interface GeneratorFunctionConstructor {
new (...args: string[]): GeneratorFunction;
(...args: string[]): GeneratorFunction;
prototype: GeneratorFunction;
}
interface IteratorResult {
done: boolean;
value: primitives | thunkable;
}
interface Generator {
constructor: GeneratorFunctionConstructor;
next(value?: primitives | thunkable): IteratorResult;
throw(err?: Error): IteratorResult;
return(value?: primitives | thunkable): IteratorResult;
}
interface AsyncFunction extends Function {
(err?: Error, res?: primitives): Promise<any>;
}
interface AsyncFunctionConstructor {
new (...args: string[]): AsyncFunction;
(...args: string[]): AsyncFunction;
prototype: AsyncFunction;
}
interface PromiseLike {
then(onfulfilled?: (value: primitives | thunkable) => primitives | thunkable, onrejected?: (reason: Error) => primitives | thunkable): PromiseLike;
}
interface SigStop {
message: string;
status: number;
code: string;
}
interface ScopeOnerror {
(error: Error): Error | boolean | void;
}
interface ScopeOptions {
onerror?: ScopeOnerror;
onstop?: (sig: SigStop) => void;
debug?: (value: any) => void;
}
interface Thunk {
<T>(thunkable?: primitives | thunkable): ThunkFunction<T>;
all<T>(...args: Array<thunkable>): ThunkFunction<T>;
all<T>(array: Array<thunkable>): ThunkFunction<T>;
all<T>(object: Object): ThunkFunction<T>;
seq<T>(...args: Array<thunkable>): ThunkFunction<T>;
seq<T>(array: Array<thunkable>): ThunkFunction<T>;
race<T>(...args: Array<thunkable>): ThunkFunction<T>;
race<T>(array: Array<thunkable>): ThunkFunction<T>;
persist<T>(thunkable: thunkable): ThunkFunction<T>;
promise<T>(thunkable: thunkable): Promise<T>;
thunkify<T>(FnWithCb: FunctionWithCallback): (...args: Array<primitives>) => ThunkFunction<T>;
lift<T>(fn: (...args: Array<primitives>) => primitives): (...args: Array<thunkable>) => ThunkFunction<T>;
delay(Time?: number): ThunkFunction<null>;
stop(message?: string): void;
cancel(): void;
}
declare function thunks (options?: ThunkOptions): Thunk;
declare namespace thunks {
export const NAME: string;
export const VERSION: string;
export const pruneErrorStack: boolean;
export const thunk: Thunk;
export const promise: Thunk["promise"];
export const thunkify: Thunk["thunkify"];
export function thunks (options?: ThunkOptions): Thunk;
export function isGeneratorFn(fn: any): boolean;
export function isAsyncFn(fn: any): boolean;
export function isThunkableFn(fn: any): boolean;
export class Scope {
constructor(options?: ThunkOptions);
}
}
export = thunks;