-
-
Notifications
You must be signed in to change notification settings - Fork 184
Expand file tree
/
Copy pathNumber.ts
More file actions
20 lines (18 loc) · 666 Bytes
/
Number.ts
File metadata and controls
20 lines (18 loc) · 666 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
export function __TS__Number(this: void, value: unknown): number {
const valueType = type(value);
if (valueType === "number") {
return value as number;
} else if (valueType === "string") {
const numberValue = tonumber(value);
if (numberValue) return numberValue;
if (value === "Infinity") return Infinity;
if (value === "-Infinity") return -Infinity;
const [stringWithoutSpaces] = string.gsub(value as string, "%s", "");
if (stringWithoutSpaces === "") return 0;
return NaN;
} else if (valueType === "boolean") {
return value ? 1 : 0;
} else {
return NaN;
}
}