summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVoltrex <mohammadkeyvanzade94@gmail.com>2021-08-04 00:25:38 +0430
committerMichaƫl Zasso <targos@protonmail.com>2021-09-04 15:14:51 +0200
commite1019351e89d03a78c371ec4c3e4bf8650afeec6 (patch)
tree92a107453698351210ed5fcc854548ec10186b42
parent49a7962d58f86f1deb5a78b840666edf9a7ed9a3 (diff)
downloadnode-new-e1019351e89d03a78c371ec4c3e4bf8650afeec6.tar.gz
lib: cleanup validation
Used the `validateInteger()` validator to cleanup validation and keep consistency. PR-URL: https://github.com/nodejs/node/pull/39652 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com>
-rw-r--r--lib/internal/tty.js13
1 files changed, 3 insertions, 10 deletions
diff --git a/lib/internal/tty.js b/lib/internal/tty.js
index 5a247c7928..f8bfe8cf21 100644
--- a/lib/internal/tty.js
+++ b/lib/internal/tty.js
@@ -29,10 +29,7 @@ const {
StringPrototypeToLowerCase,
} = primordials;
-const {
- ERR_INVALID_ARG_TYPE,
- ERR_OUT_OF_RANGE
-} = require('internal/errors').codes;
+const { validateInteger } = require('internal/validators');
let OSRelease;
@@ -221,13 +218,9 @@ function hasColors(count, env) {
env = count;
count = 16;
} else {
- if (typeof count !== 'number') {
- throw new ERR_INVALID_ARG_TYPE('count', 'number', count);
- }
- if (count < 2) {
- throw new ERR_OUT_OF_RANGE('count', '>= 2', count);
- }
+ validateInteger(count, 'count', 2);
}
+
return count <= 2 ** getColorDepth(env);
}