1
1
'use strict' ;
2
2
3
3
const {
4
+ ArrayPrototypeConcat,
5
+ ArrayPrototypeSort,
4
6
Boolean,
5
- Map,
6
7
MathFloor,
7
8
MathMax,
8
9
ObjectKeys,
9
10
RegExp,
11
+ StringPrototypeTrimLeft,
12
+ StringPrototypeRepeat,
13
+ StringPrototypeReplace,
14
+ SafeMap,
10
15
} = primordials ;
11
16
12
17
const { types } = internalBinding ( 'options' ) ;
@@ -23,7 +28,7 @@ for (const key of ObjectKeys(types))
23
28
// Environment variables are parsed ad-hoc throughout the code base,
24
29
// so we gather the documentation here.
25
30
const { hasIntl, hasSmallICU, hasNodeOptions } = internalBinding ( 'config' ) ;
26
- const envVars = new Map ( [
31
+ const envVars = new SafeMap ( ArrayPrototypeConcat ( [
27
32
[ 'NODE_DEBUG' , { helpText : "','-separated list of core modules that " +
28
33
'should print debug information' } ] ,
29
34
[ 'NODE_DEBUG_NATIVE' , { helpText : "','-separated list of C++ core debug " +
@@ -51,28 +56,30 @@ const envVars = new Map([
51
56
'to' } ] ,
52
57
[ 'UV_THREADPOOL_SIZE' , { helpText : 'sets the number of threads used in ' +
53
58
'libuv\'s threadpool' } ]
54
- ] . concat ( hasIntl ? [
59
+ ] , hasIntl ? [
55
60
[ 'NODE_ICU_DATA' , { helpText : 'data path for ICU (Intl object) data' +
56
61
hasSmallICU ? '' : ' (will extend linked-in data)' } ]
57
- ] : [ ] ) . concat ( hasNodeOptions ? [
62
+ ] : [ ] ) , ( hasNodeOptions ? [
58
63
[ 'NODE_OPTIONS' , { helpText : 'set CLI options in the environment via a ' +
59
64
'space-separated list' } ]
60
- ] : [ ] ) . concat ( hasCrypto ? [
65
+ ] : [ ] ) , hasCrypto ? [
61
66
[ 'OPENSSL_CONF' , { helpText : 'load OpenSSL configuration from file' } ] ,
62
67
[ 'SSL_CERT_DIR' , { helpText : 'sets OpenSSL\'s directory of trusted ' +
63
68
'certificates when used in conjunction with --use-openssl-ca' } ] ,
64
69
[ 'SSL_CERT_FILE' , { helpText : 'sets OpenSSL\'s trusted certificate file ' +
65
70
'when used in conjunction with --use-openssl-ca' } ] ,
66
- ] : [ ] ) ) ;
71
+ ] : [ ] ) ;
67
72
68
73
69
74
function indent ( text , depth ) {
70
- return text . replace ( / ^ / gm, ' ' . repeat ( depth ) ) ;
75
+ return StringPrototypeReplace ( text , / ^ / gm, StringPrototypeRepeat ( ' ' , depth ) ) ;
71
76
}
72
77
73
78
function fold ( text , width ) {
74
- return text . replace ( new RegExp ( `([^\n]{0,${ width } })( |$)` , 'g' ) ,
75
- ( _ , newLine , end ) => newLine + ( end === ' ' ? '\n' : '' ) ) ;
79
+ return StringPrototypeReplace ( text ,
80
+ new RegExp ( `([^\n]{0,${ width } })( |$)` , 'g' ) ,
81
+ ( _ , newLine , end ) =>
82
+ newLine + ( end === ' ' ? '\n' : '' ) ) ;
76
83
}
77
84
78
85
function getArgDescription ( type ) {
@@ -94,13 +101,15 @@ function getArgDescription(type) {
94
101
}
95
102
}
96
103
97
- function format ( { options, aliases = new Map ( ) , firstColumn, secondColumn } ) {
104
+ function format (
105
+ { options, aliases = new SafeMap ( ) , firstColumn, secondColumn }
106
+ ) {
98
107
let text = '' ;
99
108
let maxFirstColumnUsed = 0 ;
100
109
101
110
for ( const [
102
111
name , { helpText, type, value }
103
- ] of [ ...options . entries ( ) ] . sort ( ) ) {
112
+ ] of ArrayPrototypeSort ( [ ...options . entries ( ) ] ) ) {
104
113
if ( ! helpText ) continue ;
105
114
106
115
let displayName = name ;
@@ -136,12 +145,12 @@ function format({ options, aliases = new Map(), firstColumn, secondColumn }) {
136
145
text += displayName ;
137
146
maxFirstColumnUsed = MathMax ( maxFirstColumnUsed , displayName . length ) ;
138
147
if ( displayName . length >= firstColumn )
139
- text += '\n' + ' ' . repeat ( firstColumn ) ;
148
+ text += '\n' + StringPrototypeRepeat ( ' ' , firstColumn ) ;
140
149
else
141
- text += ' ' . repeat ( firstColumn - displayName . length ) ;
150
+ text += StringPrototypeRepeat ( ' ' , firstColumn - displayName . length ) ;
142
151
143
- text += indent ( fold ( displayHelpText , secondColumn ) ,
144
- firstColumn ) . trimLeft ( ) + '\n' ;
152
+ text += indent ( StringPrototypeTrimLeft ( fold ( displayHelpText , secondColumn ) ,
153
+ firstColumn ) ) + '\n' ;
145
154
}
146
155
147
156
if ( maxFirstColumnUsed < firstColumn - 4 ) {
0 commit comments