mock-service-cli 3.7.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/utils.js ADDED
@@ -0,0 +1,857 @@
1
+ var __getOwnPropNames = Object.getOwnPropertyNames;
2
+ var __commonJS = (cb, mod) => function __require() {
3
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
4
+ };
5
+
6
+ // node_modules/colors/lib/styles.js
7
+ var require_styles = __commonJS({
8
+ "node_modules/colors/lib/styles.js"(exports2, module2) {
9
+ var styles = {};
10
+ module2["exports"] = styles;
11
+ var codes = {
12
+ reset: [0, 0],
13
+ bold: [1, 22],
14
+ dim: [2, 22],
15
+ italic: [3, 23],
16
+ underline: [4, 24],
17
+ inverse: [7, 27],
18
+ hidden: [8, 28],
19
+ strikethrough: [9, 29],
20
+ black: [30, 39],
21
+ red: [31, 39],
22
+ green: [32, 39],
23
+ yellow: [33, 39],
24
+ blue: [34, 39],
25
+ magenta: [35, 39],
26
+ cyan: [36, 39],
27
+ white: [37, 39],
28
+ gray: [90, 39],
29
+ grey: [90, 39],
30
+ brightRed: [91, 39],
31
+ brightGreen: [92, 39],
32
+ brightYellow: [93, 39],
33
+ brightBlue: [94, 39],
34
+ brightMagenta: [95, 39],
35
+ brightCyan: [96, 39],
36
+ brightWhite: [97, 39],
37
+ bgBlack: [40, 49],
38
+ bgRed: [41, 49],
39
+ bgGreen: [42, 49],
40
+ bgYellow: [43, 49],
41
+ bgBlue: [44, 49],
42
+ bgMagenta: [45, 49],
43
+ bgCyan: [46, 49],
44
+ bgWhite: [47, 49],
45
+ bgGray: [100, 49],
46
+ bgGrey: [100, 49],
47
+ bgBrightRed: [101, 49],
48
+ bgBrightGreen: [102, 49],
49
+ bgBrightYellow: [103, 49],
50
+ bgBrightBlue: [104, 49],
51
+ bgBrightMagenta: [105, 49],
52
+ bgBrightCyan: [106, 49],
53
+ bgBrightWhite: [107, 49],
54
+ // legacy styles for colors pre v1.0.0
55
+ blackBG: [40, 49],
56
+ redBG: [41, 49],
57
+ greenBG: [42, 49],
58
+ yellowBG: [43, 49],
59
+ blueBG: [44, 49],
60
+ magentaBG: [45, 49],
61
+ cyanBG: [46, 49],
62
+ whiteBG: [47, 49]
63
+ };
64
+ Object.keys(codes).forEach(function(key) {
65
+ var val = codes[key];
66
+ var style = styles[key] = [];
67
+ style.open = "\x1B[" + val[0] + "m";
68
+ style.close = "\x1B[" + val[1] + "m";
69
+ });
70
+ }
71
+ });
72
+
73
+ // node_modules/colors/lib/system/has-flag.js
74
+ var require_has_flag = __commonJS({
75
+ "node_modules/colors/lib/system/has-flag.js"(exports2, module2) {
76
+ "use strict";
77
+ module2.exports = function(flag, argv) {
78
+ argv = argv || process.argv;
79
+ var terminatorPos = argv.indexOf("--");
80
+ var prefix = /^-{1,2}/.test(flag) ? "" : "--";
81
+ var pos = argv.indexOf(prefix + flag);
82
+ return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos);
83
+ };
84
+ }
85
+ });
86
+
87
+ // node_modules/colors/lib/system/supports-colors.js
88
+ var require_supports_colors = __commonJS({
89
+ "node_modules/colors/lib/system/supports-colors.js"(exports2, module2) {
90
+ "use strict";
91
+ var os = require("os");
92
+ var hasFlag = require_has_flag();
93
+ var env = process.env;
94
+ var forceColor = void 0;
95
+ if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false")) {
96
+ forceColor = false;
97
+ } else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
98
+ forceColor = true;
99
+ }
100
+ if ("FORCE_COLOR" in env) {
101
+ forceColor = env.FORCE_COLOR.length === 0 || parseInt(env.FORCE_COLOR, 10) !== 0;
102
+ }
103
+ function translateLevel(level) {
104
+ if (level === 0) {
105
+ return false;
106
+ }
107
+ return {
108
+ level,
109
+ hasBasic: true,
110
+ has256: level >= 2,
111
+ has16m: level >= 3
112
+ };
113
+ }
114
+ function supportsColor(stream) {
115
+ if (forceColor === false) {
116
+ return 0;
117
+ }
118
+ if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
119
+ return 3;
120
+ }
121
+ if (hasFlag("color=256")) {
122
+ return 2;
123
+ }
124
+ if (stream && !stream.isTTY && forceColor !== true) {
125
+ return 0;
126
+ }
127
+ var min = forceColor ? 1 : 0;
128
+ if (process.platform === "win32") {
129
+ var osRelease = os.release().split(".");
130
+ if (Number(process.versions.node.split(".")[0]) >= 8 && Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
131
+ return Number(osRelease[2]) >= 14931 ? 3 : 2;
132
+ }
133
+ return 1;
134
+ }
135
+ if ("CI" in env) {
136
+ if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI"].some(function(sign) {
137
+ return sign in env;
138
+ }) || env.CI_NAME === "codeship") {
139
+ return 1;
140
+ }
141
+ return min;
142
+ }
143
+ if ("TEAMCITY_VERSION" in env) {
144
+ return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
145
+ }
146
+ if ("TERM_PROGRAM" in env) {
147
+ var version = parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
148
+ switch (env.TERM_PROGRAM) {
149
+ case "iTerm.app":
150
+ return version >= 3 ? 3 : 2;
151
+ case "Hyper":
152
+ return 3;
153
+ case "Apple_Terminal":
154
+ return 2;
155
+ }
156
+ }
157
+ if (/-256(color)?$/i.test(env.TERM)) {
158
+ return 2;
159
+ }
160
+ if (/^screen|^xterm|^vt100|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
161
+ return 1;
162
+ }
163
+ if ("COLORTERM" in env) {
164
+ return 1;
165
+ }
166
+ if (env.TERM === "dumb") {
167
+ return min;
168
+ }
169
+ return min;
170
+ }
171
+ function getSupportLevel(stream) {
172
+ var level = supportsColor(stream);
173
+ return translateLevel(level);
174
+ }
175
+ module2.exports = {
176
+ supportsColor: getSupportLevel,
177
+ stdout: getSupportLevel(process.stdout),
178
+ stderr: getSupportLevel(process.stderr)
179
+ };
180
+ }
181
+ });
182
+
183
+ // node_modules/colors/lib/custom/trap.js
184
+ var require_trap = __commonJS({
185
+ "node_modules/colors/lib/custom/trap.js"(exports2, module2) {
186
+ module2["exports"] = function runTheTrap(text, options) {
187
+ var result = "";
188
+ text = text || "Run the trap, drop the bass";
189
+ text = text.split("");
190
+ var trap = {
191
+ a: ["@", "\u0104", "\u023A", "\u0245", "\u0394", "\u039B", "\u0414"],
192
+ b: ["\xDF", "\u0181", "\u0243", "\u026E", "\u03B2", "\u0E3F"],
193
+ c: ["\xA9", "\u023B", "\u03FE"],
194
+ d: ["\xD0", "\u018A", "\u0500", "\u0501", "\u0502", "\u0503"],
195
+ e: [
196
+ "\xCB",
197
+ "\u0115",
198
+ "\u018E",
199
+ "\u0258",
200
+ "\u03A3",
201
+ "\u03BE",
202
+ "\u04BC",
203
+ "\u0A6C"
204
+ ],
205
+ f: ["\u04FA"],
206
+ g: ["\u0262"],
207
+ h: ["\u0126", "\u0195", "\u04A2", "\u04BA", "\u04C7", "\u050A"],
208
+ i: ["\u0F0F"],
209
+ j: ["\u0134"],
210
+ k: ["\u0138", "\u04A0", "\u04C3", "\u051E"],
211
+ l: ["\u0139"],
212
+ m: ["\u028D", "\u04CD", "\u04CE", "\u0520", "\u0521", "\u0D69"],
213
+ n: ["\xD1", "\u014B", "\u019D", "\u0376", "\u03A0", "\u048A"],
214
+ o: [
215
+ "\xD8",
216
+ "\xF5",
217
+ "\xF8",
218
+ "\u01FE",
219
+ "\u0298",
220
+ "\u047A",
221
+ "\u05DD",
222
+ "\u06DD",
223
+ "\u0E4F"
224
+ ],
225
+ p: ["\u01F7", "\u048E"],
226
+ q: ["\u09CD"],
227
+ r: ["\xAE", "\u01A6", "\u0210", "\u024C", "\u0280", "\u042F"],
228
+ s: ["\xA7", "\u03DE", "\u03DF", "\u03E8"],
229
+ t: ["\u0141", "\u0166", "\u0373"],
230
+ u: ["\u01B1", "\u054D"],
231
+ v: ["\u05D8"],
232
+ w: ["\u0428", "\u0460", "\u047C", "\u0D70"],
233
+ x: ["\u04B2", "\u04FE", "\u04FC", "\u04FD"],
234
+ y: ["\xA5", "\u04B0", "\u04CB"],
235
+ z: ["\u01B5", "\u0240"]
236
+ };
237
+ text.forEach(function(c) {
238
+ c = c.toLowerCase();
239
+ var chars = trap[c] || [" "];
240
+ var rand = Math.floor(Math.random() * chars.length);
241
+ if (typeof trap[c] !== "undefined") {
242
+ result += trap[c][rand];
243
+ } else {
244
+ result += c;
245
+ }
246
+ });
247
+ return result;
248
+ };
249
+ }
250
+ });
251
+
252
+ // node_modules/colors/lib/custom/zalgo.js
253
+ var require_zalgo = __commonJS({
254
+ "node_modules/colors/lib/custom/zalgo.js"(exports2, module2) {
255
+ module2["exports"] = function zalgo(text, options) {
256
+ text = text || " he is here ";
257
+ var soul = {
258
+ "up": [
259
+ "\u030D",
260
+ "\u030E",
261
+ "\u0304",
262
+ "\u0305",
263
+ "\u033F",
264
+ "\u0311",
265
+ "\u0306",
266
+ "\u0310",
267
+ "\u0352",
268
+ "\u0357",
269
+ "\u0351",
270
+ "\u0307",
271
+ "\u0308",
272
+ "\u030A",
273
+ "\u0342",
274
+ "\u0313",
275
+ "\u0308",
276
+ "\u034A",
277
+ "\u034B",
278
+ "\u034C",
279
+ "\u0303",
280
+ "\u0302",
281
+ "\u030C",
282
+ "\u0350",
283
+ "\u0300",
284
+ "\u0301",
285
+ "\u030B",
286
+ "\u030F",
287
+ "\u0312",
288
+ "\u0313",
289
+ "\u0314",
290
+ "\u033D",
291
+ "\u0309",
292
+ "\u0363",
293
+ "\u0364",
294
+ "\u0365",
295
+ "\u0366",
296
+ "\u0367",
297
+ "\u0368",
298
+ "\u0369",
299
+ "\u036A",
300
+ "\u036B",
301
+ "\u036C",
302
+ "\u036D",
303
+ "\u036E",
304
+ "\u036F",
305
+ "\u033E",
306
+ "\u035B",
307
+ "\u0346",
308
+ "\u031A"
309
+ ],
310
+ "down": [
311
+ "\u0316",
312
+ "\u0317",
313
+ "\u0318",
314
+ "\u0319",
315
+ "\u031C",
316
+ "\u031D",
317
+ "\u031E",
318
+ "\u031F",
319
+ "\u0320",
320
+ "\u0324",
321
+ "\u0325",
322
+ "\u0326",
323
+ "\u0329",
324
+ "\u032A",
325
+ "\u032B",
326
+ "\u032C",
327
+ "\u032D",
328
+ "\u032E",
329
+ "\u032F",
330
+ "\u0330",
331
+ "\u0331",
332
+ "\u0332",
333
+ "\u0333",
334
+ "\u0339",
335
+ "\u033A",
336
+ "\u033B",
337
+ "\u033C",
338
+ "\u0345",
339
+ "\u0347",
340
+ "\u0348",
341
+ "\u0349",
342
+ "\u034D",
343
+ "\u034E",
344
+ "\u0353",
345
+ "\u0354",
346
+ "\u0355",
347
+ "\u0356",
348
+ "\u0359",
349
+ "\u035A",
350
+ "\u0323"
351
+ ],
352
+ "mid": [
353
+ "\u0315",
354
+ "\u031B",
355
+ "\u0300",
356
+ "\u0301",
357
+ "\u0358",
358
+ "\u0321",
359
+ "\u0322",
360
+ "\u0327",
361
+ "\u0328",
362
+ "\u0334",
363
+ "\u0335",
364
+ "\u0336",
365
+ "\u035C",
366
+ "\u035D",
367
+ "\u035E",
368
+ "\u035F",
369
+ "\u0360",
370
+ "\u0362",
371
+ "\u0338",
372
+ "\u0337",
373
+ "\u0361",
374
+ " \u0489"
375
+ ]
376
+ };
377
+ var all = [].concat(soul.up, soul.down, soul.mid);
378
+ function randomNumber(range) {
379
+ var r = Math.floor(Math.random() * range);
380
+ return r;
381
+ }
382
+ function isChar(character) {
383
+ var bool = false;
384
+ all.filter(function(i) {
385
+ bool = i === character;
386
+ });
387
+ return bool;
388
+ }
389
+ function heComes(text2, options2) {
390
+ var result = "";
391
+ var counts;
392
+ var l;
393
+ options2 = options2 || {};
394
+ options2["up"] = typeof options2["up"] !== "undefined" ? options2["up"] : true;
395
+ options2["mid"] = typeof options2["mid"] !== "undefined" ? options2["mid"] : true;
396
+ options2["down"] = typeof options2["down"] !== "undefined" ? options2["down"] : true;
397
+ options2["size"] = typeof options2["size"] !== "undefined" ? options2["size"] : "maxi";
398
+ text2 = text2.split("");
399
+ for (l in text2) {
400
+ if (isChar(l)) {
401
+ continue;
402
+ }
403
+ result = result + text2[l];
404
+ counts = { "up": 0, "down": 0, "mid": 0 };
405
+ switch (options2.size) {
406
+ case "mini":
407
+ counts.up = randomNumber(8);
408
+ counts.mid = randomNumber(2);
409
+ counts.down = randomNumber(8);
410
+ break;
411
+ case "maxi":
412
+ counts.up = randomNumber(16) + 3;
413
+ counts.mid = randomNumber(4) + 1;
414
+ counts.down = randomNumber(64) + 3;
415
+ break;
416
+ default:
417
+ counts.up = randomNumber(8) + 1;
418
+ counts.mid = randomNumber(6) / 2;
419
+ counts.down = randomNumber(8) + 1;
420
+ break;
421
+ }
422
+ var arr = ["up", "mid", "down"];
423
+ for (var d in arr) {
424
+ var index = arr[d];
425
+ for (var i = 0; i <= counts[index]; i++) {
426
+ if (options2[index]) {
427
+ result = result + soul[index][randomNumber(soul[index].length)];
428
+ }
429
+ }
430
+ }
431
+ }
432
+ return result;
433
+ }
434
+ return heComes(text, options);
435
+ };
436
+ }
437
+ });
438
+
439
+ // node_modules/colors/lib/maps/america.js
440
+ var require_america = __commonJS({
441
+ "node_modules/colors/lib/maps/america.js"(exports2, module2) {
442
+ module2["exports"] = function(colors2) {
443
+ return function(letter, i, exploded) {
444
+ if (letter === " ") return letter;
445
+ switch (i % 3) {
446
+ case 0:
447
+ return colors2.red(letter);
448
+ case 1:
449
+ return colors2.white(letter);
450
+ case 2:
451
+ return colors2.blue(letter);
452
+ }
453
+ };
454
+ };
455
+ }
456
+ });
457
+
458
+ // node_modules/colors/lib/maps/zebra.js
459
+ var require_zebra = __commonJS({
460
+ "node_modules/colors/lib/maps/zebra.js"(exports2, module2) {
461
+ module2["exports"] = function(colors2) {
462
+ return function(letter, i, exploded) {
463
+ return i % 2 === 0 ? letter : colors2.inverse(letter);
464
+ };
465
+ };
466
+ }
467
+ });
468
+
469
+ // node_modules/colors/lib/maps/rainbow.js
470
+ var require_rainbow = __commonJS({
471
+ "node_modules/colors/lib/maps/rainbow.js"(exports2, module2) {
472
+ module2["exports"] = function(colors2) {
473
+ var rainbowColors = ["red", "yellow", "green", "blue", "magenta"];
474
+ return function(letter, i, exploded) {
475
+ if (letter === " ") {
476
+ return letter;
477
+ } else {
478
+ return colors2[rainbowColors[i++ % rainbowColors.length]](letter);
479
+ }
480
+ };
481
+ };
482
+ }
483
+ });
484
+
485
+ // node_modules/colors/lib/maps/random.js
486
+ var require_random = __commonJS({
487
+ "node_modules/colors/lib/maps/random.js"(exports2, module2) {
488
+ module2["exports"] = function(colors2) {
489
+ var available = [
490
+ "underline",
491
+ "inverse",
492
+ "grey",
493
+ "yellow",
494
+ "red",
495
+ "green",
496
+ "blue",
497
+ "white",
498
+ "cyan",
499
+ "magenta",
500
+ "brightYellow",
501
+ "brightRed",
502
+ "brightGreen",
503
+ "brightBlue",
504
+ "brightWhite",
505
+ "brightCyan",
506
+ "brightMagenta"
507
+ ];
508
+ return function(letter, i, exploded) {
509
+ return letter === " " ? letter : colors2[available[Math.round(Math.random() * (available.length - 2))]](letter);
510
+ };
511
+ };
512
+ }
513
+ });
514
+
515
+ // node_modules/colors/lib/colors.js
516
+ var require_colors = __commonJS({
517
+ "node_modules/colors/lib/colors.js"(exports2, module2) {
518
+ var colors2 = {};
519
+ module2["exports"] = colors2;
520
+ colors2.themes = {};
521
+ var util = require("util");
522
+ var ansiStyles = colors2.styles = require_styles();
523
+ var defineProps = Object.defineProperties;
524
+ var newLineRegex = new RegExp(/[\r\n]+/g);
525
+ colors2.supportsColor = require_supports_colors().supportsColor;
526
+ if (typeof colors2.enabled === "undefined") {
527
+ colors2.enabled = colors2.supportsColor() !== false;
528
+ }
529
+ colors2.enable = function() {
530
+ colors2.enabled = true;
531
+ };
532
+ colors2.disable = function() {
533
+ colors2.enabled = false;
534
+ };
535
+ colors2.stripColors = colors2.strip = function(str) {
536
+ return ("" + str).replace(/\x1B\[\d+m/g, "");
537
+ };
538
+ var stylize = colors2.stylize = function stylize2(str, style) {
539
+ if (!colors2.enabled) {
540
+ return str + "";
541
+ }
542
+ var styleMap = ansiStyles[style];
543
+ if (!styleMap && style in colors2) {
544
+ return colors2[style](str);
545
+ }
546
+ return styleMap.open + str + styleMap.close;
547
+ };
548
+ var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;
549
+ var escapeStringRegexp = function(str) {
550
+ if (typeof str !== "string") {
551
+ throw new TypeError("Expected a string");
552
+ }
553
+ return str.replace(matchOperatorsRe, "\\$&");
554
+ };
555
+ function build(_styles) {
556
+ var builder = function builder2() {
557
+ return applyStyle.apply(builder2, arguments);
558
+ };
559
+ builder._styles = _styles;
560
+ builder.__proto__ = proto;
561
+ return builder;
562
+ }
563
+ var styles = function() {
564
+ var ret = {};
565
+ ansiStyles.grey = ansiStyles.gray;
566
+ Object.keys(ansiStyles).forEach(function(key) {
567
+ ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), "g");
568
+ ret[key] = {
569
+ get: function() {
570
+ return build(this._styles.concat(key));
571
+ }
572
+ };
573
+ });
574
+ return ret;
575
+ }();
576
+ var proto = defineProps(function colors3() {
577
+ }, styles);
578
+ function applyStyle() {
579
+ var args = Array.prototype.slice.call(arguments);
580
+ var str = args.map(function(arg) {
581
+ if (arg != null && arg.constructor === String) {
582
+ return arg;
583
+ } else {
584
+ return util.inspect(arg);
585
+ }
586
+ }).join(" ");
587
+ if (!colors2.enabled || !str) {
588
+ return str;
589
+ }
590
+ var newLinesPresent = str.indexOf("\n") != -1;
591
+ var nestedStyles = this._styles;
592
+ var i = nestedStyles.length;
593
+ while (i--) {
594
+ var code = ansiStyles[nestedStyles[i]];
595
+ str = code.open + str.replace(code.closeRe, code.open) + code.close;
596
+ if (newLinesPresent) {
597
+ str = str.replace(newLineRegex, function(match) {
598
+ return code.close + match + code.open;
599
+ });
600
+ }
601
+ }
602
+ return str;
603
+ }
604
+ colors2.setTheme = function(theme) {
605
+ if (typeof theme === "string") {
606
+ console.log("colors.setTheme now only accepts an object, not a string. If you are trying to set a theme from a file, it is now your (the caller's) responsibility to require the file. The old syntax looked like colors.setTheme(__dirname + '/../themes/generic-logging.js'); The new syntax looks like colors.setTheme(require(__dirname + '/../themes/generic-logging.js'));");
607
+ return;
608
+ }
609
+ for (var style in theme) {
610
+ (function(style2) {
611
+ colors2[style2] = function(str) {
612
+ if (typeof theme[style2] === "object") {
613
+ var out = str;
614
+ for (var i in theme[style2]) {
615
+ out = colors2[theme[style2][i]](out);
616
+ }
617
+ return out;
618
+ }
619
+ return colors2[theme[style2]](str);
620
+ };
621
+ })(style);
622
+ }
623
+ };
624
+ function init() {
625
+ var ret = {};
626
+ Object.keys(styles).forEach(function(name) {
627
+ ret[name] = {
628
+ get: function() {
629
+ return build([name]);
630
+ }
631
+ };
632
+ });
633
+ return ret;
634
+ }
635
+ var sequencer = function sequencer2(map2, str) {
636
+ var exploded = str.split("");
637
+ exploded = exploded.map(map2);
638
+ return exploded.join("");
639
+ };
640
+ colors2.trap = require_trap();
641
+ colors2.zalgo = require_zalgo();
642
+ colors2.maps = {};
643
+ colors2.maps.america = require_america()(colors2);
644
+ colors2.maps.zebra = require_zebra()(colors2);
645
+ colors2.maps.rainbow = require_rainbow()(colors2);
646
+ colors2.maps.random = require_random()(colors2);
647
+ for (map in colors2.maps) {
648
+ (function(map2) {
649
+ colors2[map2] = function(str) {
650
+ return sequencer(colors2.maps[map2], str);
651
+ };
652
+ })(map);
653
+ }
654
+ var map;
655
+ defineProps(colors2, init());
656
+ }
657
+ });
658
+
659
+ // node_modules/colors/safe.js
660
+ var require_safe = __commonJS({
661
+ "node_modules/colors/safe.js"(exports2, module2) {
662
+ var colors2 = require_colors();
663
+ module2["exports"] = colors2;
664
+ }
665
+ });
666
+
667
+ // src/lib/utils.js
668
+ var fs = require("fs");
669
+ var colors = require_safe();
670
+ var path = require("path");
671
+ var getLogger = function(logFileDirPath) {
672
+ const options = {
673
+ flags: "a",
674
+ // append模式
675
+ encoding: "utf8"
676
+ // utf8编码
677
+ };
678
+ const output = fs.createWriteStream(
679
+ path.resolve(logFileDirPath ? logFileDirPath : path.resolve(process.cwd()), "./stdout.log"),
680
+ options
681
+ );
682
+ const errorOutput = fs.createWriteStream(
683
+ path.resolve(logFileDirPath ? logFileDirPath : path.resolve(process.cwd()), "./stderr.log"),
684
+ options
685
+ );
686
+ const logger2 = new console.Console(output, errorOutput);
687
+ return {
688
+ log: (...args) => logger2.log.call(null, `[${dateFormat("YYYY-mm-dd HH:MM:SS:fff")}] - `, ...args),
689
+ error: (...args) => logger2.error.call(null, `[${dateFormat("YYYY-mm-dd HH:MM:SS:fff")}] - `, ...args)
690
+ };
691
+ };
692
+ function dateFormat(fmt, date = /* @__PURE__ */ new Date()) {
693
+ let ret;
694
+ const opt = {
695
+ "Y+": date.getFullYear().toString(),
696
+ // 年
697
+ "m+": (date.getMonth() + 1).toString(),
698
+ // 月
699
+ "d+": date.getDate().toString(),
700
+ // 日
701
+ "H+": date.getHours().toString(),
702
+ // 时
703
+ "M+": date.getMinutes().toString(),
704
+ // 分
705
+ "S+": date.getSeconds().toString(),
706
+ // 秒
707
+ "f+": date.getMilliseconds().toString()
708
+ // 毫秒
709
+ // 有其他格式化字符需求可以继续添加,必须转化成字符串
710
+ };
711
+ for (const k in opt) {
712
+ ret = new RegExp("(" + k + ")").exec(fmt);
713
+ if (ret) {
714
+ fmt = fmt.replace(ret[1], ret[1].length === 1 ? opt[k] : opt[k].padStart(ret[1].length, "0"));
715
+ }
716
+ }
717
+ return fmt;
718
+ }
719
+ function logger(isSilent = false) {
720
+ let logObj = null;
721
+ if (!isSilent) {
722
+ logObj = {
723
+ info: console.log,
724
+ assert: console.assert
725
+ };
726
+ } else {
727
+ logObj = {
728
+ info: function() {
729
+ },
730
+ assert: function() {
731
+ }
732
+ };
733
+ }
734
+ return logObj;
735
+ }
736
+ var SupportMethods = ["GET", "POST", "PUT", "DELETE", "HEAD", "PATCH", "OPTIONS", "COPY", "LINK", "UNLINK", "PURGE"];
737
+ var DefaultHeaders = "Authorization,Content-Type,Accept,Origin,User-Agent,DNT,Cache-Control,X-Mx-ReqToken,X-Data-Type,X-Requested-With,X-Data-Type,X-Auth-Token,Token";
738
+ var isValidMethod = function(m) {
739
+ return SupportMethods.includes(String(m).toLocaleUpperCase());
740
+ };
741
+ var getFileLatestContent = function(filePath) {
742
+ try {
743
+ delete require.cache[require.resolve(filePath)];
744
+ return require(path.resolve(process.cwd(), filePath));
745
+ } catch (error) {
746
+ console.error(colors.red("[error]:"), error);
747
+ return "getFileLatestContent_ERROR";
748
+ }
749
+ };
750
+ var filePath2ApiUrl = function(filePath) {
751
+ return filePath.split(path.sep).join("/");
752
+ };
753
+ var getDataType = function(data) {
754
+ return Object.prototype.toString.call(data).slice(8, -1).toLowerCase();
755
+ };
756
+ var isEmptyObj = function(obj) {
757
+ return getDataType(obj) === "object" && Object.keys(obj).length === 0;
758
+ };
759
+ var writeStream = function(filePath, data) {
760
+ return new Promise((resolve, reject) => {
761
+ const writerStream = fs.createWriteStream(filePath);
762
+ writerStream.write(data, "utf-8");
763
+ writerStream.end();
764
+ writerStream.on("finish", () => {
765
+ });
766
+ writerStream.on("close", () => {
767
+ setTimeout(() => {
768
+ resolve(data);
769
+ });
770
+ });
771
+ writerStream.on("error", (err) => {
772
+ getLogger(path.resolve(process.cwd())).error(filePath, require.cache[require.resolve(filePath)], err);
773
+ reject(err);
774
+ });
775
+ });
776
+ };
777
+ var readStream = function(filePath) {
778
+ let data = "";
779
+ return new Promise((resovle, reject) => {
780
+ const readerStream = fs.createReadStream(filePath);
781
+ readerStream.setEncoding("UTF8");
782
+ readerStream.on("data", function(chunk) {
783
+ data += chunk;
784
+ });
785
+ readerStream.on("end", function() {
786
+ resovle(data);
787
+ });
788
+ readerStream.on("error", function(err) {
789
+ reject(err);
790
+ console.log(err.stack);
791
+ });
792
+ });
793
+ };
794
+ var debounce = (func, wait) => {
795
+ let timeout;
796
+ let canceled = false;
797
+ const f = function(...args) {
798
+ if (canceled) return;
799
+ clearTimeout(timeout);
800
+ timeout = setTimeout(() => {
801
+ func.call(this, ...args);
802
+ }, wait);
803
+ };
804
+ f.cancel = () => {
805
+ clearTimeout(timeout);
806
+ canceled = true;
807
+ };
808
+ return f;
809
+ };
810
+ var throttle = (func, wait, immediate) => {
811
+ let timeout;
812
+ let canceled = false;
813
+ let lastCalledTime = 0;
814
+ const f = function(...args) {
815
+ if (canceled) return;
816
+ const now = Date.now();
817
+ const call = () => {
818
+ lastCalledTime = now;
819
+ func.call(this, ...args);
820
+ };
821
+ if (lastCalledTime === 0) {
822
+ if (immediate) {
823
+ return call();
824
+ }
825
+ lastCalledTime = now;
826
+ return;
827
+ }
828
+ const remain = lastCalledTime + wait - now;
829
+ if (remain > 0) {
830
+ clearTimeout(timeout);
831
+ timeout = setTimeout(() => call(), wait);
832
+ } else {
833
+ call();
834
+ }
835
+ };
836
+ f.cancel = () => {
837
+ clearTimeout(timeout);
838
+ canceled = true;
839
+ };
840
+ return f;
841
+ };
842
+ module.exports = {
843
+ getLogger,
844
+ dateFormat,
845
+ logger,
846
+ SupportMethods,
847
+ DefaultHeaders,
848
+ isValidMethod,
849
+ getFileLatestContent,
850
+ filePath2ApiUrl,
851
+ getDataType,
852
+ isEmptyObj,
853
+ writeStream,
854
+ readStream,
855
+ debounce,
856
+ throttle
857
+ };