Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
lib: cleanup validation
Used the `validateInteger()` validator to cleanup validation and keep
consistency.
  • Loading branch information
VoltrexKeyva committed Aug 3, 2021
commit d453331889c9986e2eeeeac5a0f2c17f47153b7a
13 changes: 3 additions & 10 deletions lib/internal/tty.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}

Expand Down