1 | declare namespace mockjs {
|
2 | type N = number;
|
3 | type S = string;
|
4 | type B = boolean;
|
5 |
|
6 |
|
7 | interface Mockjs {
|
8 | mock: MockjsMock;
|
9 | setup: MockjsSetup;
|
10 | Random: MockjsRandom;
|
11 | valid: MockjsValid;
|
12 | toJSONSchema: MockjsToJSONSchema;
|
13 | version: number;
|
14 | }
|
15 |
|
16 | interface MockjsRequestOptions {
|
17 | url: string;
|
18 | type: string;
|
19 | body: any;
|
20 | }
|
21 |
|
22 | type templateOrFn = ((options: MockjsRequestOptions) => any) | object;
|
23 |
|
24 | // Mockjs.mock()
|
25 | // see https://github.com/nuysoft/Mock/wiki/Mock.mock()
|
26 | interface MockjsMock {
|
27 | (rurl: S | RegExp, rtype: S, template: templateOrFn): Mockjs;
|
28 |
|
29 | (rurl: S | RegExp, template: templateOrFn): Mockjs;
|
30 |
|
31 | (template: any): any;
|
32 | }
|
33 |
|
34 | interface MockjsSetupSettings {
|
35 | timeout?: number | S | undefined;
|
36 | }
|
37 |
|
38 | // Mockjs.setup()
|
39 | // see https://github.com/nuysoft/Mock/wiki/Mock.setup()
|
40 | type MockjsSetup = (settings: MockjsSetupSettings) => void;
|
41 |
|
42 |
|
43 |
|
44 | interface MockjsRandomBasic {
|
45 |
|
46 | boolean(min: N, max: N, current: B): B;
|
47 | boolean(): B;
|
48 |
|
49 |
|
50 | natural(min?: N, max?: N): N;
|
51 |
|
52 |
|
53 | integer(min?: N, max?: N): N;
|
54 |
|
55 |
|
56 | float(min?: N, max?: N, dmin?: N, dmax?: N): N;
|
57 |
|
58 |
|
59 | character(pool: "lower" | "upper" | "number" | "symbol"): S;
|
60 | character(pool?: S): S;
|
61 |
|
62 |
|
63 | string(pool?: S | N, min?: N, max?: N): S;
|
64 |
|
65 |
|
66 | range(start?: N, stop?: N, step?: N): N[];
|
67 | }
|
68 |
|
69 |
|
70 |
|
71 | type RandomDateUtilString = "year" | "month" | "week" | "day" | "hour" | "minute" | "second" | "week";
|
72 | interface MockjsRandomDate {
|
73 |
|
74 | date(format?: S): S;
|
75 |
|
76 |
|
77 | time(format?: S): S;
|
78 |
|
79 |
|
80 | datetime(format?: S): S;
|
81 |
|
82 |
|
83 | now(util: RandomDateUtilString, format?: S): S;
|
84 | now(format?: S): S;
|
85 | }
|
86 |
|
87 |
|
88 |
|
89 | type RandomImageFormatString = "png" | "gif" | "jpg";
|
90 | interface MockjsRandomImage {
|
91 |
|
92 | image(size?: S, background?: S, foreground?: S, format?: RandomImageFormatString | S, text?: S): S;
|
93 |
|
94 |
|
95 | dataImage(size?: S, text?: S): S;
|
96 | }
|
97 |
|
98 |
|
99 |
|
100 | interface MockjsRandomColor {
|
101 |
|
102 | color(): S;
|
103 |
|
104 |
|
105 | hex(): S;
|
106 |
|
107 |
|
108 | rgb(): S;
|
109 |
|
110 |
|
111 | rgba(): S;
|
112 |
|
113 |
|
114 | hsl(): S;
|
115 | }
|
116 |
|
117 |
|
118 |
|
119 | interface MockjsRandomText {
|
120 |
|
121 | paragraph(min?: N, max?: N): S;
|
122 |
|
123 |
|
124 | cparagraph(min?: N, max?: N): S;
|
125 |
|
126 |
|
127 | sentence(min?: N, max?: N): S;
|
128 |
|
129 |
|
130 | csentence(min?: N, max?: N): S;
|
131 |
|
132 |
|
133 | word(min?: N, max?: N): S;
|
134 |
|
135 |
|
136 | cword(pool?: S | N, min?: N, max?: N): S;
|
137 |
|
138 |
|
139 | title(min?: N, max?: N): S;
|
140 |
|
141 |
|
142 | ctitle(min?: N, max?: N): S;
|
143 | }
|
144 |
|
145 |
|
146 |
|
147 | interface MockjsRandomName {
|
148 |
|
149 | first(): S;
|
150 |
|
151 |
|
152 | last(): S;
|
153 |
|
154 |
|
155 | name(middle?: B): S;
|
156 |
|
157 |
|
158 | cfirst(): S;
|
159 |
|
160 |
|
161 | clast(): S;
|
162 |
|
163 |
|
164 | cname(): S;
|
165 | }
|
166 |
|
167 |
|
168 |
|
169 | type RandomWebProtocal =
|
170 | | "http"
|
171 | | "ftp"
|
172 | | "gopher"
|
173 | | "mailto"
|
174 | | "mid"
|
175 | | "cid"
|
176 | | "news"
|
177 | | "nntp"
|
178 | | "prospero"
|
179 | | "telnet"
|
180 | | "rlogin"
|
181 | | "tn3270"
|
182 | | "wais";
|
183 | interface MockjsRandomWeb {
|
184 |
|
185 | url(protocol?: S, host?: S): S;
|
186 |
|
187 |
|
188 | protocal(): RandomWebProtocal;
|
189 |
|
190 |
|
191 | domain(): S;
|
192 |
|
193 |
|
194 | dtl(): S;
|
195 |
|
196 |
|
197 | email(domain?: S): S;
|
198 |
|
199 |
|
200 | ip(): S;
|
201 | }
|
202 |
|
203 |
|
204 |
|
205 | interface MockjsRandomAddress {
|
206 |
|
207 | region(): S;
|
208 |
|
209 |
|
210 | province(): S;
|
211 |
|
212 |
|
213 | city(prefix?: B): S;
|
214 |
|
215 |
|
216 | county(prefix?: B): S;
|
217 |
|
218 |
|
219 | zip(prefix?: B): S;
|
220 | }
|
221 |
|
222 |
|
223 |
|
224 | interface MockjsRandomHelper {
|
225 |
|
226 | capitalize(word: S): S;
|
227 |
|
228 |
|
229 | upper(str: S): S;
|
230 |
|
231 |
|
232 | lower(str: S): S;
|
233 |
|
234 |
|
235 | pick(arr: any[]): any;
|
236 |
|
237 |
|
238 | shuffle(arr: any[]): any[];
|
239 | }
|
240 |
|
241 |
|
242 |
|
243 | interface MockjsRandomMiscellaneous {
|
244 |
|
245 | guid(): S;
|
246 |
|
247 |
|
248 | id(): S;
|
249 |
|
250 |
|
251 | increment(step?: N): N;
|
252 | }
|
253 |
|
254 | interface MockjsRandomExtendOption {
|
255 | [randomType: string]: (...args: any[]) => any;
|
256 | }
|
257 |
|
258 |
|
259 |
|
260 | interface MockjsRandom
|
261 | extends
|
262 | MockjsRandomBasic,
|
263 | MockjsRandomDate,
|
264 | MockjsRandomImage,
|
265 | MockjsRandomColor,
|
266 | MockjsRandomAddress,
|
267 | MockjsRandomHelper,
|
268 | MockjsRandomMiscellaneous,
|
269 | MockjsRandomName,
|
270 | MockjsRandomText,
|
271 | MockjsRandomWeb,
|
272 | MockjsRandomExtendOption
|
273 | {
|
274 |
|
275 | extend(extendOption: MockjsRandomExtendOption): MockjsRandom;
|
276 | }
|
277 |
|
278 | interface MockjsValidRsItem {
|
279 | action: S;
|
280 | actual: S;
|
281 | expected: S;
|
282 | message: S;
|
283 | path: S[];
|
284 | type: S;
|
285 | }
|
286 |
|
287 |
|
288 |
|
289 | type MockjsValid = (template: any, data: any) => MockjsValidRsItem[];
|
290 |
|
291 | interface MockjsToJSONSchemaRs {
|
292 | name: S | undefined;
|
293 | template: any;
|
294 | type: S;
|
295 | rule: object;
|
296 | path: S[];
|
297 | properties?: MockjsToJSONSchemaRs[] | undefined;
|
298 | items?: MockjsToJSONSchemaRs[] | undefined;
|
299 | }
|
300 |
|
301 |
|
302 |
|
303 | type MockjsToJSONSchema = (template: any) => MockjsToJSONSchemaRs;
|
304 |
|
305 | let mock: MockjsMock;
|
306 | let setup: MockjsSetup;
|
307 | let Random: MockjsRandom;
|
308 | let valid: MockjsValid;
|
309 | let toJSONSchema: MockjsToJSONSchema;
|
310 | let version: number;
|
311 | }
|
312 |
|
313 | export = mockjs;
|