GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — lib: refactor to use validateNumber · nodejs/node@a29da64

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • buffer.js
    • internal
      • crypto
        • util.js
      • histogram.js
    • net.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/buffer.js‎

Copy file name to clipboardExpand all lines: lib/buffer.js
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ const {
102102
const {
103103
validateArray,
104104
validateBuffer,
105+
validateNumber,
105106
validateInteger,
106107
validateString
107108
} = require('internal/validators');
@@ -346,9 +347,7 @@ ObjectSetPrototypeOf(Buffer, Uint8Array);
346347
// occurs. This is done simply to keep the internal details of the
347348
// implementation from bleeding out to users.
348349
const assertSize = hideStackFrames((size) => {
349-
if (typeof size !== 'number') {
350-
throw new ERR_INVALID_ARG_TYPE('size', 'number', size);
351-
}
350+
validateNumber(size, 'size');
352351
if (!(size >= 0 && size <= kMaxLength)) {
353352
throw new ERR_INVALID_ARG_VALUE.RangeError('size', size);
354353
}
Collapse file

‎lib/internal/crypto/util.js‎

Copy file name to clipboardExpand all lines: lib/internal/crypto/util.js
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const {
4242

4343
const {
4444
validateArray,
45+
validateNumber,
4546
validateString
4647
} = require('internal/validators');
4748

@@ -104,8 +105,8 @@ const getCurves = cachedResult(() => filterDuplicateStrings(_getCurves()));
104105

105106
function setEngine(id, flags) {
106107
validateString(id, 'id');
107-
if (flags && typeof flags !== 'number')
108-
throw new ERR_INVALID_ARG_TYPE('flags', 'number', flags);
108+
if (flags)
109+
validateNumber(flags, 'flags');
109110
flags = flags >>> 0;
110111

111112
// Use provided engine for everything by default
@@ -244,8 +245,7 @@ function hasAnyNotIn(set, ...check) {
244245

245246
function validateBitLength(length, name, required = false) {
246247
if (length !== undefined || required) {
247-
if (typeof length !== 'number')
248-
throw new ERR_INVALID_ARG_TYPE(name, 'number', length);
248+
validateNumber(length, name);
249249
if (length < 0)
250250
throw new ERR_OUT_OF_RANGE(name, '> 0');
251251
if (length % 8) {
Collapse file

‎lib/internal/histogram.js‎

Copy file name to clipboardExpand all lines: lib/internal/histogram.js
+3-6Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ const {
77
const { format } = require('util');
88
const { NumberIsNaN, SafeMap, Symbol } = primordials;
99

10-
const {
11-
ERR_INVALID_ARG_TYPE,
12-
ERR_INVALID_ARG_VALUE,
13-
} = require('internal/errors').codes;
10+
const { ERR_INVALID_ARG_VALUE } = require('internal/errors').codes;
11+
const { validateNumber } = require('internal/validators');
1412

1513
const kDestroy = Symbol('kDestroy');
1614
const kHandle = Symbol('kHandle');
@@ -58,8 +56,7 @@ class Histogram {
5856
}
5957

6058
percentile(percentile) {
61-
if (typeof percentile !== 'number')
62-
throw new ERR_INVALID_ARG_TYPE('percentile', 'number', percentile);
59+
validateNumber(percentile, 'percentile');
6360

6461
if (NumberIsNaN(percentile) || percentile <= 0 || percentile > 100)
6562
throw new ERR_INVALID_ARG_VALUE.RangeError('percentile', percentile);
Collapse file

‎lib/net.js‎

Copy file name to clipboardExpand all lines: lib/net.js
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ const { isUint8Array } = require('internal/util/types');
111111
const {
112112
validateAbortSignal,
113113
validateInt32,
114+
validateNumber,
114115
validatePort,
115116
validateString
116117
} = require('internal/validators');
@@ -981,8 +982,8 @@ function lookupAndConnect(self, options) {
981982
throw new ERR_INVALID_IP_ADDRESS(localAddress);
982983
}
983984

984-
if (localPort && typeof localPort !== 'number') {
985-
throw new ERR_INVALID_ARG_TYPE('options.localPort', 'number', localPort);
985+
if (localPort) {
986+
validateNumber(localPort, 'options.localPort');
986987
}
987988

988989
if (typeof port !== 'undefined') {

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.