diff options
author | Chris Knight <cknight1234@gmail.com> | 2020-02-10 23:19:48 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-10 18:19:48 -0500 |
commit | 81905a867ea3f942619229e330840d132c57a5da (patch) | |
tree | 4bcdac6a58dfc5fd14e83f04c3f388a6d43968d3 /std/node/util.ts | |
parent | e1105a159406d8b64a833fa3266fd4ac7fc47a00 (diff) |
feat: Event emitter node polyfill (#3944)
Diffstat (limited to 'std/node/util.ts')
-rw-r--r-- | std/node/util.ts | 17 |
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}` + ); + } +} |