1 |
|
2 | const _options = {};
|
3 |
|
4 |
|
5 | function mergeOption(v, defaultValue){
|
6 | if (typeof v === 'undefined' || v === null){
|
7 | return defaultValue;
|
8 | }else{
|
9 | return v;
|
10 | }
|
11 | }
|
12 |
|
13 | module.exports = {
|
14 |
|
15 | parse: function parse(rawOptions, preset){
|
16 |
|
17 |
|
18 | const opt = Object.assign({}, preset, rawOptions);
|
19 |
|
20 |
|
21 | _options.throttleTime = 1000 / (mergeOption(opt.fps, 10));
|
22 |
|
23 |
|
24 | _options.stream = mergeOption(opt.stream, process.stderr);
|
25 |
|
26 |
|
27 | _options.terminal = mergeOption(opt.terminal, null);
|
28 |
|
29 |
|
30 | _options.clearOnComplete = mergeOption(opt.clearOnComplete, false);
|
31 |
|
32 |
|
33 | _options.stopOnComplete = mergeOption(opt.stopOnComplete, false);
|
34 |
|
35 |
|
36 | _options.barsize = mergeOption(opt.barsize, 40);
|
37 |
|
38 |
|
39 | _options.align = mergeOption(opt.align, 'left');
|
40 |
|
41 |
|
42 | _options.hideCursor = mergeOption(opt.hideCursor, false);
|
43 |
|
44 |
|
45 | _options.linewrap = mergeOption(opt.linewrap, false);
|
46 |
|
47 |
|
48 | _options.barCompleteString = (new Array(_options.barsize + 1 ).join(opt.barCompleteChar || '='));
|
49 | _options.barIncompleteString = (new Array(_options.barsize + 1 ).join(opt.barIncompleteChar || '-'));
|
50 |
|
51 |
|
52 | _options.barGlue = mergeOption(opt.barGlue, '');
|
53 |
|
54 |
|
55 | _options.format = mergeOption(opt.format, 'progress [{bar}] {percentage}% | ETA: {eta}s | {value}/{total}');
|
56 |
|
57 |
|
58 | _options.formatTime = mergeOption(opt.formatTime, null);
|
59 |
|
60 |
|
61 | _options.formatValue = mergeOption(opt.formatValue, null);
|
62 |
|
63 |
|
64 | _options.formatBar = mergeOption(opt.formatBar, null);
|
65 |
|
66 |
|
67 | _options.etaBufferLength = mergeOption(opt.etaBuffer, 10);
|
68 |
|
69 |
|
70 | _options.synchronousUpdate = mergeOption(opt.synchronousUpdate, true);
|
71 |
|
72 |
|
73 | _options.noTTYOutput = mergeOption(opt.noTTYOutput, false);
|
74 |
|
75 |
|
76 | _options.notTTYSchedule = mergeOption(opt.notTTYSchedule, 2000);
|
77 |
|
78 |
|
79 | _options.emptyOnZero = mergeOption(opt.emptyOnZero, false);
|
80 |
|
81 |
|
82 | _options.forceRedraw = mergeOption(opt.forceRedraw, false);
|
83 |
|
84 |
|
85 | _options.autopadding = mergeOption(opt.autopadding, false);
|
86 |
|
87 |
|
88 | _options.autopaddingChar = _options.autopadding ? mergeOption(opt.autopaddingChar, ' ') : '';
|
89 |
|
90 | return _options;
|
91 | },
|
92 |
|
93 |
|
94 | getOptions: function getOptions(){
|
95 | return _options;
|
96 | }
|
97 | }; |
\ | No newline at end of file |