Skip to content

Commit 96950f7

Browse files
committed
lib: cleanup validation
Used the `validateInteger()` validator to cleanup validation and keep consistency.
1 parent dd18795 commit 96950f7

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

lib/internal/tty.js

Lines changed: 4 additions & 12 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

@@ -220,14 +217,9 @@ function hasColors(count, env) {
220217
(count === undefined || (typeof count === 'object' && count !== null))) {
221218
env = count;
222219
count = 16;
223-
} 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-
}
230-
}
220+
} else
221+
validateInteger(count, 'count', 2);
222+
231223
return count <= 2 ** getColorDepth(env);
232224
}
233225

0 commit comments

Comments
 (0)