jscrewit 2.41.0 → 3.1.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/Features.md +49 -182
- package/{readme.md → README.md} +32 -30
- package/api-doc/JScrewIt/namespaces/EncodeOptions/README.md +9 -0
- package/api-doc/{type-aliases → JScrewIt/namespaces/EncodeOptions/type-aliases}/RunAs.md +3 -2
- package/api-doc/README.md +5 -4
- package/api-doc/interfaces/CustomFeature.md +3 -3
- package/api-doc/interfaces/ElementaryFeature.md +2 -2
- package/api-doc/interfaces/{encode.md → EncodeInterface.md} +2 -2
- package/api-doc/interfaces/EncodeOptions.md +4 -4
- package/api-doc/interfaces/Feature.md +3 -3
- package/api-doc/interfaces/FeatureAll.md +75 -585
- package/api-doc/interfaces/FeatureConstructor.md +103 -824
- package/api-doc/interfaces/PredefinedFeature.md +2 -2
- package/api-doc/interfaces/default.md +1 -1
- package/api-doc/type-aliases/ElementaryFeatureName.md +1 -1
- package/api-doc/type-aliases/PredefinedFeatureName.md +1 -1
- package/lib/encode.d.ts +12 -10
- package/lib/feature-all.d.ts +91 -435
- package/lib/feature.d.ts +20 -22
- package/lib/jscrewit.d.ts +6 -6
- package/lib/jscrewit.js +776 -2447
- package/lib/jscrewit.min.js +2 -2
- package/package.json +6 -3
- package/screw.js +87 -103
- package/tools/cli.js +84 -158
- package/tools/time-utils.js +10 -26
- package/ui/ui.js +1 -1
- package/api-doc/variables/Feature.md +0 -7
- package/api-doc/variables/encode.md +0 -7
- package/tools/text-utils.js +0 -37
- /package/{license.txt → LICENSE.txt} +0 -0
package/screw.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
/* eslint-env node */
|
|
4
|
-
|
|
5
3
|
'use strict';
|
|
6
4
|
|
|
5
|
+
const cli = require('./tools/cli');
|
|
6
|
+
|
|
7
7
|
function fail()
|
|
8
8
|
{
|
|
9
9
|
process.exit(1);
|
|
@@ -11,21 +11,21 @@ function fail()
|
|
|
11
11
|
|
|
12
12
|
function getBasename()
|
|
13
13
|
{
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
const path = require('node:path');
|
|
15
|
+
const basename = path.basename(process.argv[1]);
|
|
16
16
|
return basename;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
function printErrorMessage(errorMessage)
|
|
20
20
|
{
|
|
21
|
-
|
|
21
|
+
const basename = getBasename();
|
|
22
22
|
console.error
|
|
23
23
|
('%s: %s.\nTry "%s --help" for more information.', basename, errorMessage, basename);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
function printHelpMessage()
|
|
27
27
|
{
|
|
28
|
-
|
|
28
|
+
const message =
|
|
29
29
|
'Usage: %s [OPTION]... [SOURCE [DESTINATION]]\n' +
|
|
30
30
|
'Encodes JavaScript with JScrewIt.\n' +
|
|
31
31
|
'\n' +
|
|
@@ -55,14 +55,14 @@ function printHelpMessage()
|
|
|
55
55
|
' none (none available)\n' +
|
|
56
56
|
'\n' +
|
|
57
57
|
'See the JScrewIt feature documentation for a list of all supported features.\n';
|
|
58
|
-
|
|
58
|
+
const basename = getBasename();
|
|
59
59
|
console.log(message, basename);
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
function printVersion()
|
|
63
63
|
{
|
|
64
|
-
|
|
65
|
-
console.log(
|
|
64
|
+
const { version } = require('./package.json');
|
|
65
|
+
console.log(`JScrewIt ${version}`);
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
function prompt()
|
|
@@ -70,114 +70,98 @@ function prompt()
|
|
|
70
70
|
process.stdout.write('SCREW> ');
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
let command;
|
|
74
|
+
try
|
|
74
75
|
{
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (command === 'version')
|
|
93
|
-
{
|
|
94
|
-
printVersion();
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
var inputFileName = command.inputFileName;
|
|
99
|
-
var outputFileName = command.outputFileName;
|
|
100
|
-
var options = command.options;
|
|
76
|
+
command = cli.parseCommandLine(process.argv);
|
|
77
|
+
}
|
|
78
|
+
catch (error)
|
|
79
|
+
{
|
|
80
|
+
printErrorMessage(error.message);
|
|
81
|
+
fail();
|
|
82
|
+
}
|
|
83
|
+
if (command === 'help')
|
|
84
|
+
{
|
|
85
|
+
printHelpMessage();
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (command === 'version')
|
|
89
|
+
{
|
|
90
|
+
printVersion();
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
101
93
|
|
|
102
|
-
|
|
94
|
+
const { inputFileName, outputFileName, options } = command;
|
|
95
|
+
const JScrewIt = require('.');
|
|
103
96
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
{
|
|
109
|
-
var output;
|
|
110
|
-
try
|
|
111
|
-
{
|
|
112
|
-
output = JScrewIt.encode(input, options);
|
|
113
|
-
}
|
|
114
|
-
catch (error)
|
|
115
|
-
{
|
|
116
|
-
console.error('%s', error.message);
|
|
117
|
-
}
|
|
118
|
-
return output;
|
|
119
|
-
};
|
|
120
|
-
if (tryEncode('') == null) // validate options
|
|
121
|
-
fail();
|
|
122
|
-
var readline = require('readline');
|
|
123
|
-
var rl = readline.createInterface({ input: process.stdin, terminal: false });
|
|
124
|
-
rl.on
|
|
125
|
-
(
|
|
126
|
-
'line',
|
|
127
|
-
function (input)
|
|
128
|
-
{
|
|
129
|
-
if (input)
|
|
130
|
-
{
|
|
131
|
-
var output = tryEncode(input);
|
|
132
|
-
if (output != null)
|
|
133
|
-
console.log(output);
|
|
134
|
-
}
|
|
135
|
-
prompt();
|
|
136
|
-
}
|
|
137
|
-
);
|
|
138
|
-
prompt();
|
|
139
|
-
}
|
|
140
|
-
else
|
|
97
|
+
if (inputFileName == null)
|
|
98
|
+
{
|
|
99
|
+
const tryEncode =
|
|
100
|
+
input =>
|
|
141
101
|
{
|
|
142
|
-
|
|
143
|
-
var timeUtils = require('./tools/time-utils');
|
|
144
|
-
|
|
145
|
-
var input;
|
|
146
|
-
var output;
|
|
147
|
-
var encodingTime;
|
|
102
|
+
let output;
|
|
148
103
|
try
|
|
149
104
|
{
|
|
150
|
-
|
|
151
|
-
encodingTime =
|
|
152
|
-
timeUtils.timeThis
|
|
153
|
-
(
|
|
154
|
-
function ()
|
|
155
|
-
{
|
|
156
|
-
output = JScrewIt.encode(input, options);
|
|
157
|
-
}
|
|
158
|
-
);
|
|
159
|
-
if (outputFileName != null)
|
|
160
|
-
fs.writeFileSync(outputFileName, output);
|
|
161
|
-
else
|
|
162
|
-
console.log(output);
|
|
105
|
+
output = JScrewIt.encode(input, options);
|
|
163
106
|
}
|
|
164
107
|
catch (error)
|
|
165
108
|
{
|
|
166
109
|
console.error('%s', error.message);
|
|
167
|
-
fail();
|
|
168
110
|
}
|
|
169
|
-
|
|
111
|
+
return output;
|
|
112
|
+
};
|
|
113
|
+
if (tryEncode('') == null) // validate options
|
|
114
|
+
fail();
|
|
115
|
+
const { createInterface } = require('node:readline');
|
|
116
|
+
const rl = createInterface({ input: process.stdin, terminal: false });
|
|
117
|
+
rl.on
|
|
118
|
+
(
|
|
119
|
+
'line',
|
|
120
|
+
input =>
|
|
170
121
|
{
|
|
171
|
-
|
|
172
|
-
var perfLog = perfInfo && perfInfo.perfLog;
|
|
173
|
-
if (perfLog)
|
|
122
|
+
if (input)
|
|
174
123
|
{
|
|
175
|
-
|
|
176
|
-
|
|
124
|
+
const output = tryEncode(input);
|
|
125
|
+
if (output != null)
|
|
126
|
+
console.log(output);
|
|
177
127
|
}
|
|
178
|
-
|
|
179
|
-
|
|
128
|
+
prompt();
|
|
129
|
+
},
|
|
130
|
+
);
|
|
131
|
+
prompt();
|
|
132
|
+
}
|
|
133
|
+
else
|
|
134
|
+
{
|
|
135
|
+
const fs = require('node:fs');
|
|
136
|
+
const timeUtils = require('./tools/time-utils');
|
|
137
|
+
|
|
138
|
+
let input;
|
|
139
|
+
let output;
|
|
140
|
+
let encodingTime;
|
|
141
|
+
try
|
|
142
|
+
{
|
|
143
|
+
input = fs.readFileSync(inputFileName);
|
|
144
|
+
encodingTime =
|
|
145
|
+
timeUtils.timeThis(() => { output = JScrewIt.encode(input, options); });
|
|
146
|
+
if (outputFileName != null)
|
|
147
|
+
fs.writeFileSync(outputFileName, output);
|
|
148
|
+
else
|
|
149
|
+
console.log(output);
|
|
150
|
+
}
|
|
151
|
+
catch (error)
|
|
152
|
+
{
|
|
153
|
+
console.error('%s', error.message);
|
|
154
|
+
fail();
|
|
155
|
+
}
|
|
156
|
+
if (outputFileName != null)
|
|
157
|
+
{
|
|
158
|
+
const perfLog = options.perfInfo?.perfLog;
|
|
159
|
+
if (perfLog)
|
|
160
|
+
{
|
|
161
|
+
const diagnosticReport = cli.createDiagnosticReport(perfLog);
|
|
162
|
+
console.log(diagnosticReport);
|
|
180
163
|
}
|
|
164
|
+
const report = cli.createReport(input.length, output.length, encodingTime);
|
|
165
|
+
console.log(report);
|
|
181
166
|
}
|
|
182
167
|
}
|
|
183
|
-
)();
|
package/tools/cli.js
CHANGED
|
@@ -1,66 +1,56 @@
|
|
|
1
|
-
/* eslint-env node */
|
|
2
|
-
/* global padLeft, padRight, repeat */
|
|
3
|
-
|
|
4
1
|
'use strict';
|
|
5
2
|
|
|
6
|
-
require('
|
|
7
|
-
|
|
3
|
+
const { parseArgs } = require('node:util');
|
|
4
|
+
const timeUtils = require('./time-utils');
|
|
8
5
|
|
|
9
6
|
function byteCount(size, width)
|
|
10
7
|
{
|
|
11
|
-
|
|
8
|
+
const str = `${String(size).padStart(width)}${size === 1 ? ' byte' : ' bytes'}`;
|
|
12
9
|
return str;
|
|
13
10
|
}
|
|
14
11
|
|
|
15
12
|
function createDiagnosticReport(perfLog)
|
|
16
13
|
{
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
(
|
|
22
|
-
function (str, perfInfoList)
|
|
23
|
-
{
|
|
24
|
-
str += formatPerfInfoList(perfInfoList, '', ['', '']);
|
|
25
|
-
return str;
|
|
26
|
-
},
|
|
27
|
-
''
|
|
28
|
-
);
|
|
14
|
+
const reportParts =
|
|
15
|
+
perfLog.map(perfInfoList => formatPerfInfoList(perfInfoList, '', ['', '']));
|
|
16
|
+
reportParts.unshift
|
|
17
|
+
(`\nStrategy Status Length Time (ms)\n${'─'.repeat(60)}\n`);
|
|
18
|
+
const report = reportParts.join('');
|
|
29
19
|
return report;
|
|
30
20
|
}
|
|
31
21
|
|
|
32
22
|
function createReport(originalSize, screwedSize, encodingTime)
|
|
33
23
|
{
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
24
|
+
const width = Math.max(widthOf(originalSize), widthOf(screwedSize));
|
|
25
|
+
const expansionFactorStr = originalSize ? (screwedSize / originalSize).toFixed(2) : '-';
|
|
26
|
+
const encodingTimeStr = timeUtils.formatDuration(encodingTime);
|
|
27
|
+
const report =
|
|
28
|
+
`Original size: ${byteCount(originalSize, width)
|
|
29
|
+
}\nScrewed size: ${byteCount(screwedSize, width)
|
|
30
|
+
}\nExpansion factor: ${expansionFactorStr
|
|
31
|
+
}\nEncoding time: ${encodingTimeStr}`;
|
|
42
32
|
return report;
|
|
43
33
|
}
|
|
44
34
|
|
|
45
35
|
function formatCodingLog(perfLog, padding, nextCodingLog)
|
|
46
36
|
{
|
|
47
37
|
padding += nextCodingLog ? '│' : ' ';
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
for (
|
|
38
|
+
let str = '';
|
|
39
|
+
const count = perfLog.length;
|
|
40
|
+
for (let index = 0; index < count; ++index)
|
|
51
41
|
{
|
|
52
|
-
|
|
53
|
-
|
|
42
|
+
const perfInfoList = perfLog[index];
|
|
43
|
+
const nextPerfInfoList = index < count - 1;
|
|
54
44
|
str += formatPerfInfoList(perfInfoList, padding, nextPerfInfoList ? '├│' : '└ ');
|
|
55
45
|
}
|
|
56
46
|
if (nextCodingLog)
|
|
57
|
-
str += padding
|
|
47
|
+
str += `${padding}\n`;
|
|
58
48
|
return str;
|
|
59
49
|
}
|
|
60
50
|
|
|
61
51
|
function formatInt(int)
|
|
62
52
|
{
|
|
63
|
-
|
|
53
|
+
const str = int === undefined ? '-' : String(int);
|
|
64
54
|
return str;
|
|
65
55
|
}
|
|
66
56
|
|
|
@@ -68,141 +58,82 @@ function formatPerfInfoList(perfInfoList, padding, paddingChars)
|
|
|
68
58
|
{
|
|
69
59
|
// In the current implementation, perfInfoList.name can be either undefined, a unit path or
|
|
70
60
|
// "legend".
|
|
71
|
-
|
|
61
|
+
let str = `${padding}${paddingChars[0]}${perfInfoList.name || '(default)'}\n`;
|
|
72
62
|
padding += paddingChars[1];
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
for (var index = 0; index < count; ++index)
|
|
63
|
+
const count = perfInfoList.length;
|
|
64
|
+
const paddingLength = padding.length;
|
|
65
|
+
for (let index = 0; index < count; ++index)
|
|
77
66
|
{
|
|
78
|
-
|
|
79
|
-
|
|
67
|
+
const perfInfo = perfInfoList[index];
|
|
68
|
+
const next = index < count - 1;
|
|
80
69
|
str +=
|
|
81
|
-
padding
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
70
|
+
`${padding
|
|
71
|
+
}${next ? '├' : '└'
|
|
72
|
+
}${perfInfo.strategyName.padEnd(27 - paddingLength)
|
|
73
|
+
}${perfInfo.status.padEnd(10)
|
|
74
|
+
}${formatInt(perfInfo.outputLength).padStart(11)
|
|
75
|
+
}${formatInt(perfInfo.time).padStart(11)
|
|
76
|
+
}\n`;
|
|
77
|
+
const { perfLog } = perfInfo;
|
|
88
78
|
if (perfLog)
|
|
89
79
|
str += formatCodingLog(perfLog, padding, next);
|
|
90
80
|
}
|
|
91
81
|
return str;
|
|
92
82
|
}
|
|
93
83
|
|
|
94
|
-
function parseCommandLine(
|
|
84
|
+
function parseCommandLine([,, ...args])
|
|
95
85
|
{
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (arg2 === undefined)
|
|
100
|
-
throw Error('option ' + quote(arg) + ' requires an argument');
|
|
101
|
-
options.features = arg2.trim().split(/(?:\s+|\s*,\s*)/);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function parseFlag(char)
|
|
105
|
-
{
|
|
106
|
-
switch (char)
|
|
107
|
-
{
|
|
108
|
-
case 'c':
|
|
109
|
-
case 'w':
|
|
110
|
-
wrapMode = 'call';
|
|
111
|
-
break;
|
|
112
|
-
case 'd':
|
|
113
|
-
options.perfInfo = { };
|
|
114
|
-
break;
|
|
115
|
-
case 'e':
|
|
116
|
-
wrapMode = 'eval';
|
|
117
|
-
break;
|
|
118
|
-
case 't':
|
|
119
|
-
options.trimCode = true;
|
|
120
|
-
break;
|
|
121
|
-
case 'x':
|
|
122
|
-
express = true;
|
|
123
|
-
break;
|
|
124
|
-
default:
|
|
125
|
-
throw Error('unrecognized flag ' + quote(char));
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
function parseRunAs()
|
|
130
|
-
{
|
|
131
|
-
var arg2 = argv[++index];
|
|
132
|
-
if (arg2 === undefined)
|
|
133
|
-
throw Error('option ' + quote(arg) + ' requires an argument');
|
|
134
|
-
options.runAs = arg2;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
var inputFileName;
|
|
138
|
-
var outputFileName;
|
|
139
|
-
var options = { };
|
|
140
|
-
var arg;
|
|
141
|
-
var express;
|
|
142
|
-
var wrapMode;
|
|
143
|
-
|
|
144
|
-
for (var index = 2; index < argv.length; ++index)
|
|
145
|
-
{
|
|
146
|
-
arg = argv[index];
|
|
147
|
-
var flag;
|
|
148
|
-
if (/^--/.test(arg))
|
|
86
|
+
const parsed =
|
|
87
|
+
parseArgs
|
|
88
|
+
(
|
|
149
89
|
{
|
|
150
|
-
|
|
151
|
-
|
|
90
|
+
args,
|
|
91
|
+
options:
|
|
152
92
|
{
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
{
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
outputFileName = arg;
|
|
189
|
-
else
|
|
190
|
-
inputFileName = arg;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
if (!options.runAs)
|
|
93
|
+
'call': { type: 'boolean', short: 'c' },
|
|
94
|
+
'diagnostic': { type: 'boolean', short: 'd' },
|
|
95
|
+
'eval-flag': { type: 'boolean', short: 'e' },
|
|
96
|
+
'express': { type: 'boolean', short: 'x' },
|
|
97
|
+
'features': { type: 'string', short: 'f' },
|
|
98
|
+
'help': { type: 'boolean' },
|
|
99
|
+
'run-as': { type: 'string', short: 'r' },
|
|
100
|
+
'trim-code': { type: 'boolean', short: 't' },
|
|
101
|
+
'version': { type: 'boolean', short: 'v' },
|
|
102
|
+
'wrap': { type: 'boolean', short: 'w' },
|
|
103
|
+
},
|
|
104
|
+
allowPositionals: true,
|
|
105
|
+
strict: true,
|
|
106
|
+
},
|
|
107
|
+
);
|
|
108
|
+
const { values, positionals } = parsed;
|
|
109
|
+
if (values.help)
|
|
110
|
+
return 'help';
|
|
111
|
+
if (values.version)
|
|
112
|
+
return 'version';
|
|
113
|
+
if (positionals.length > 2)
|
|
114
|
+
throw Error(`Unexpected argument "${positionals[2]}"`);
|
|
115
|
+
const [inputFileName, outputFileName] = positionals;
|
|
116
|
+
const options = { };
|
|
117
|
+
if (values.diagnostic)
|
|
118
|
+
options.perfInfo = { };
|
|
119
|
+
const { features } = values;
|
|
120
|
+
if (features != null)
|
|
121
|
+
options.features = features.trim().split(/(?:\s+|\s*,\s*)/);
|
|
122
|
+
if (values['trim-code'])
|
|
123
|
+
options.trimCode = true;
|
|
124
|
+
const runAs = values['run-as'];
|
|
125
|
+
if (runAs != null)
|
|
126
|
+
options.runAs = runAs;
|
|
127
|
+
else
|
|
194
128
|
{
|
|
195
|
-
|
|
129
|
+
const { express } = values;
|
|
130
|
+
const wrapMode =
|
|
131
|
+
values.call ?? values.wrap ? 'call' : values['eval-flag'] ? 'eval' : undefined;
|
|
132
|
+
const runAs = (express ? ['express'] : []).concat(wrapMode ?? []).join('-');
|
|
196
133
|
if (runAs)
|
|
197
134
|
options.runAs = runAs;
|
|
198
135
|
}
|
|
199
|
-
|
|
200
|
-
return result;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
function quote(arg)
|
|
204
|
-
{
|
|
205
|
-
return '"' + arg + '"';
|
|
136
|
+
return { inputFileName, outputFileName, options };
|
|
206
137
|
}
|
|
207
138
|
|
|
208
139
|
function widthOf(size)
|
|
@@ -210,9 +141,4 @@ function widthOf(size)
|
|
|
210
141
|
return String(size).length;
|
|
211
142
|
}
|
|
212
143
|
|
|
213
|
-
module.exports =
|
|
214
|
-
{
|
|
215
|
-
createDiagnosticReport: createDiagnosticReport,
|
|
216
|
-
createReport: createReport,
|
|
217
|
-
parseCommandLine: parseCommandLine,
|
|
218
|
-
};
|
|
144
|
+
module.exports = { createDiagnosticReport, createReport, parseCommandLine };
|
package/tools/time-utils.js
CHANGED
|
@@ -1,44 +1,28 @@
|
|
|
1
|
-
/* eslint-env node */
|
|
2
|
-
/* global Promise */
|
|
3
|
-
|
|
4
1
|
'use strict';
|
|
5
2
|
|
|
6
3
|
exports.formatDuration =
|
|
7
4
|
function (duration)
|
|
8
5
|
{
|
|
9
|
-
|
|
6
|
+
const str = duration < 5e-3 ? '< 0.01 s' : `${duration.toFixed(2)} s`;
|
|
10
7
|
return str;
|
|
11
8
|
};
|
|
12
9
|
|
|
13
10
|
exports.timeThis =
|
|
14
11
|
function (fn)
|
|
15
12
|
{
|
|
16
|
-
|
|
13
|
+
const begin = process.hrtime();
|
|
17
14
|
fn();
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
const time = process.hrtime(begin);
|
|
16
|
+
const duration = time[0] + time[1] / 1e9;
|
|
20
17
|
return duration;
|
|
21
18
|
};
|
|
22
19
|
|
|
23
20
|
exports.timeThisAsync =
|
|
24
|
-
function (fn)
|
|
21
|
+
async function (fn)
|
|
25
22
|
{
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
.then
|
|
32
|
-
(
|
|
33
|
-
function ()
|
|
34
|
-
{
|
|
35
|
-
var time = process.hrtime(begin);
|
|
36
|
-
var duration = time[0] + time[1] / 1e9;
|
|
37
|
-
resolve(duration);
|
|
38
|
-
}
|
|
39
|
-
)
|
|
40
|
-
.catch(reject);
|
|
41
|
-
};
|
|
42
|
-
var promise = new Promise(executor);
|
|
43
|
-
return promise;
|
|
23
|
+
const begin = process.hrtime();
|
|
24
|
+
await fn();
|
|
25
|
+
const time = process.hrtime(begin);
|
|
26
|
+
const duration = time[0] + time[1] / 1e9;
|
|
27
|
+
return duration;
|
|
44
28
|
};
|