summaryrefslogtreecommitdiff
path: root/std/node/util.ts
diff options
context:
space:
mode:
Diffstat (limited to 'std/node/util.ts')
-rw-r--r--std/node/util.ts17
1 files changed, 17 insertions, 0 deletions
diff --git a/std/node/util.ts b/std/node/util.ts
index d0187e616..9879da513 100644
--- a/std/node/util.ts
+++ b/std/node/util.ts
@@ -45,3 +45,20 @@ export function isFunction(value: unknown): boolean {
export function isRegExp(value: unknown): boolean {
return value instanceof RegExp;
}
+
+export function validateIntegerRange(
+ value: number,
+ name: string,
+ min = -2147483648,
+ max = 2147483647
+): void {
+ // The defaults for min and max correspond to the limits of 32-bit integers.
+ if (!Number.isInteger(value)) {
+ throw new Error(`${name} must be 'an integer' but was ${value}`);
+ }
+ if (value < min || value > max) {
+ throw new Error(
+ `${name} must be >= ${min} && <= ${max}. Value was ${value}`
+ );
+ }
+}