Skip to content

Commit ca3cb96

Browse files
VoltrexKeyvadanielleadams
authored andcommitted
lib: cleanup validation
Used the `validateInteger()` validator to cleanup validation and keep consistency. PR-URL: #39652 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com>
1 parent cc08d30 commit ca3cb96

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

lib/internal/tty.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ const {
2929
StringPrototypeToLowerCase,
3030
} = primordials;
3131

32-
const {
33-
ERR_INVALID_ARG_TYPE,
34-
ERR_OUT_OF_RANGE
35-
} = require('internal/errors').codes;
32+
const { validateInteger } = require('internal/validators');
3633

3734
let OSRelease;
3835

@@ -221,13 +218,9 @@ function hasColors(count, env) {
221218
env = count;
222219
count = 16;
223220
} else {
224-
if (typeof count !== 'number') {
225-
throw new ERR_INVALID_ARG_TYPE('count', 'number', count);
226-
}
227-
if (count < 2) {
228-
throw new ERR_OUT_OF_RANGE('count', '>= 2', count);
229-
}
221+
validateInteger(count, 'count', 2);
230222
}
223+
231224
return count <= 2 ** getColorDepth(env);
232225
}
233226

0 commit comments

Comments
 (0)