11'use strict' ;
22
33const {
4+ ArrayPrototypeConcat,
5+ ArrayPrototypeSort,
46 Boolean,
5- Map,
67 MathFloor,
78 MathMax,
89 ObjectKeys,
910 RegExp,
11+ StringPrototypeTrimLeft,
12+ StringPrototypeRepeat,
13+ StringPrototypeReplace,
14+ SafeMap,
1015} = primordials ;
1116
1217const { types } = internalBinding ( 'options' ) ;
@@ -23,7 +28,7 @@ for (const key of ObjectKeys(types))
2328// Environment variables are parsed ad-hoc throughout the code base,
2429// so we gather the documentation here.
2530const { hasIntl, hasSmallICU, hasNodeOptions } = internalBinding ( 'config' ) ;
26- const envVars = new Map ( [
31+ const envVars = new SafeMap ( ArrayPrototypeConcat ( [
2732 [ 'NODE_DEBUG' , { helpText : "','-separated list of core modules that " +
2833 'should print debug information' } ] ,
2934 [ 'NODE_DEBUG_NATIVE' , { helpText : "','-separated list of C++ core debug " +
@@ -51,28 +56,30 @@ const envVars = new Map([
5156 'to' } ] ,
5257 [ 'UV_THREADPOOL_SIZE' , { helpText : 'sets the number of threads used in ' +
5358 'libuv\'s threadpool' } ]
54- ] . concat ( hasIntl ? [
59+ ] , hasIntl ? [
5560 [ 'NODE_ICU_DATA' , { helpText : 'data path for ICU (Intl object) data' +
5661 hasSmallICU ? '' : ' (will extend linked-in data)' } ]
57- ] : [ ] ) . concat ( hasNodeOptions ? [
62+ ] : [ ] ) , ( hasNodeOptions ? [
5863 [ 'NODE_OPTIONS' , { helpText : 'set CLI options in the environment via a ' +
5964 'space-separated list' } ]
60- ] : [ ] ) . concat ( hasCrypto ? [
65+ ] : [ ] ) , hasCrypto ? [
6166 [ 'OPENSSL_CONF' , { helpText : 'load OpenSSL configuration from file' } ] ,
6267 [ 'SSL_CERT_DIR' , { helpText : 'sets OpenSSL\'s directory of trusted ' +
6368 'certificates when used in conjunction with --use-openssl-ca' } ] ,
6469 [ 'SSL_CERT_FILE' , { helpText : 'sets OpenSSL\'s trusted certificate file ' +
6570 'when used in conjunction with --use-openssl-ca' } ] ,
66- ] : [ ] ) ) ;
71+ ] : [ ] ) ;
6772
6873
6974function indent ( text , depth ) {
70- return text . replace ( / ^ / gm, ' ' . repeat ( depth ) ) ;
75+ return StringPrototypeReplace ( text , / ^ / gm, StringPrototypeRepeat ( ' ' , depth ) ) ;
7176}
7277
7378function 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' : '' ) ) ;
7683}
7784
7885function getArgDescription ( type ) {
@@ -94,13 +101,15 @@ function getArgDescription(type) {
94101 }
95102}
96103
97- function format ( { options, aliases = new Map ( ) , firstColumn, secondColumn } ) {
104+ function format (
105+ { options, aliases = new SafeMap ( ) , firstColumn, secondColumn }
106+ ) {
98107 let text = '' ;
99108 let maxFirstColumnUsed = 0 ;
100109
101110 for ( const [
102111 name , { helpText, type, value }
103- ] of [ ...options . entries ( ) ] . sort ( ) ) {
112+ ] of ArrayPrototypeSort ( [ ...options . entries ( ) ] ) ) {
104113 if ( ! helpText ) continue ;
105114
106115 let displayName = name ;
@@ -136,12 +145,12 @@ function format({ options, aliases = new Map(), firstColumn, secondColumn }) {
136145 text += displayName ;
137146 maxFirstColumnUsed = MathMax ( maxFirstColumnUsed , displayName . length ) ;
138147 if ( displayName . length >= firstColumn )
139- text += '\n' + ' ' . repeat ( firstColumn ) ;
148+ text += '\n' + StringPrototypeRepeat ( ' ' , firstColumn ) ;
140149 else
141- text += ' ' . repeat ( firstColumn - displayName . length ) ;
150+ text += StringPrototypeRepeat ( ' ' , firstColumn - displayName . length ) ;
142151
143- text += indent ( fold ( displayHelpText , secondColumn ) ,
144- firstColumn ) . trimLeft ( ) + '\n' ;
152+ text += indent ( StringPrototypeTrimLeft ( fold ( displayHelpText , secondColumn ) ,
153+ firstColumn ) ) + '\n' ;
145154 }
146155
147156 if ( maxFirstColumnUsed < firstColumn - 4 ) {
0 commit comments