Skip to content

Commit 6bc007f

Browse files
Lxxyxdanielleadams
authored andcommitted
tty: refactor to use more primordials
PR-URL: #36272 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 5935ccc commit 6bc007f

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

‎lib/internal/tty.js‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222

2323
'use strict';
2424

25+
const{
26+
RegExpPrototypeTest,
27+
StringPrototypeSplit,
28+
StringPrototypeToLowerCase,
29+
}=primordials;
30+
2531
const{
2632
ERR_INVALID_ARG_TYPE,
2733
ERR_OUT_OF_RANGE
@@ -134,7 +140,7 @@ function getColorDepth(env = process.env){
134140
// Lazy load for startup performance.
135141
if(OSRelease===undefined){
136142
const{ release }=require('os');
137-
OSRelease=release().split('.');
143+
OSRelease=StringPrototypeSplit(release(),'.');
138144
}
139145
// Windows 10 build 10586 is the first Windows release that supports 256
140146
// colors. Windows 10 build 14931 is the first release that supports
@@ -163,14 +169,15 @@ function getColorDepth(env = process.env){
163169
}
164170

165171
if('TEAMCITY_VERSION'inenv){
166-
return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ?
172+
returnRegExpPrototypeTest(/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/,env.TEAMCITY_VERSION) ?
167173
COLORS_16 : COLORS_2;
168174
}
169175

170176
switch(env.TERM_PROGRAM){
171177
case'iTerm.app':
172178
if(!env.TERM_PROGRAM_VERSION||
173-
/^[0-2]\./.test(env.TERM_PROGRAM_VERSION)){
179+
RegExpPrototypeTest(/^[0-2]\./,env.TERM_PROGRAM_VERSION)
180+
){
174181
returnCOLORS_256;
175182
}
176183
returnCOLORS_16m;
@@ -186,16 +193,17 @@ function getColorDepth(env = process.env){
186193
}
187194

188195
if(env.TERM){
189-
if(/^xterm-256/.test(env.TERM))
196+
if(RegExpPrototypeTest(/^xterm-256/,env.TERM)){
190197
returnCOLORS_256;
198+
}
191199

192-
consttermEnv=env.TERM.toLowerCase();
200+
consttermEnv=StringPrototypeToLowerCase(env.TERM);
193201

194202
if(TERM_ENVS[termEnv]){
195203
returnTERM_ENVS[termEnv];
196204
}
197205
for(consttermofTERM_ENVS_REG_EXP){
198-
if(term.test(termEnv)){
206+
if(RegExpPrototypeTest(term,termEnv)){
199207
returnCOLORS_16;
200208
}
201209
}

0 commit comments

Comments
(0)