-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.ts
More file actions
33 lines (28 loc) · 808 Bytes
/
util.ts
File metadata and controls
33 lines (28 loc) · 808 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
* Internal utilities
*/
import isFinite = require("is-finite");
import isInteger = require("is-integer");
/**
* Tests if the specified value is a non-negative finite number.
* @internal
*/
export function isNonNegativeFinite(value: number): boolean {
return isFinite(value) && value >= 0;
}
/**
* Tests if the specified value is an integer in the specified range.
* @internal
*/
export function isIntegerInRange(value: number, start: number, end?: number): boolean {
if (end == null) {
end = start;
start = 0;
}
if (typeof start !== "number" || typeof end !== "number") {
throw new TypeError("Expected start and end to be numbers");
}
return isInteger(value)
&& value >= Math.min(start, end)
&& value <= Math.max(start, end);
}