summaryrefslogtreecommitdiff
path: root/std/node/_utils.ts
diff options
context:
space:
mode:
authorSchwarzkopf Balázs <schwarzkopfb@icloud.com>2020-08-27 11:00:38 +0200
committerGitHub <noreply@github.com>2020-08-27 11:00:38 +0200
commite1564f385c770ac37c550f7d9e164d6a846c191e (patch)
tree1fbf2e00012793b64f07c8085d6e4d006a139a3b /std/node/_utils.ts
parent7583fd0979ee35144c7df078d00aa2e78b510be9 (diff)
fix(std/node): "events" and "util" modules (#7170)
Diffstat (limited to 'std/node/_utils.ts')
-rw-r--r--std/node/_utils.ts18
1 files changed, 18 insertions, 0 deletions
diff --git a/std/node/_utils.ts b/std/node/_utils.ts
index 0e8b26fb5..5bd4d1075 100644
--- a/std/node/_utils.ts
+++ b/std/node/_utils.ts
@@ -111,3 +111,21 @@ function slowCases(enc: string): string | undefined {
if (enc === "") return "utf8";
}
}
+
+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}`,
+ );
+ }
+}