-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathconversions.js
More file actions
38 lines (38 loc) · 1.31 KB
/
Copy pathconversions.js
File metadata and controls
38 lines (38 loc) · 1.31 KB
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
34
35
36
37
38
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const errors_1 = require("./errors");
function toInt(input) {
let value = NaN;
//todo add extra checks for (additional chars)
if (typeof input === 'string' || typeof input === 'number') {
value = Number.parseInt(input);
}
if (Number.isNaN(value)) {
throw new errors_1.ConversionError(input, toInt.name, 'could not be converted to an integer');
}
return value;
}
exports.toInt = toInt;
function toNumber(input) {
let value = NaN;
//todo add extra checks for (additional chars)
if (typeof input === 'string' || typeof input === 'number')
value = Number(input);
if (Number.isNaN(value)) {
throw new errors_1.ConversionError(input, toNumber.name, 'could not be converted to a number');
}
return value;
}
exports.toNumber = toNumber;
function toBoolean(input) {
let value = undefined;
if (typeof input === 'string' || typeof input === 'number' || typeof input === 'boolean') {
value = Boolean(input); // todo not valid
}
if (typeof value === 'undefined') {
throw new errors_1.ConversionError(input, toBoolean.name, 'could not be converted to a boolean');
}
return value;
}
exports.toBoolean = toBoolean;
//# sourceMappingURL=conversions.js.map