1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | Object.defineProperty(exports, "__esModule", { value: true });
|
7 | exports.NumberType = void 0;
|
8 | const tslib_1 = require("tslib");
|
9 | const util_1 = tslib_1.__importDefault(require("util"));
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | class NumberType {
|
15 | constructor() {
|
16 | this.name = 'number';
|
17 | }
|
18 | isInstance(value) {
|
19 | return value == null || (!isNaN(value) && typeof value === 'number');
|
20 | }
|
21 | isCoercible(value) {
|
22 | return value == null || !isNaN(Number(value));
|
23 | }
|
24 | defaultValue() {
|
25 | return 0;
|
26 | }
|
27 | coerce(value) {
|
28 | if (value == null)
|
29 | return value;
|
30 | const n = Number(value);
|
31 | if (isNaN(n)) {
|
32 | const msg = util_1.default.format('Invalid %s: %j', this.name, value);
|
33 | throw new TypeError(msg);
|
34 | }
|
35 | return n;
|
36 | }
|
37 | serialize(value) {
|
38 | return value;
|
39 | }
|
40 | }
|
41 | exports.NumberType = NumberType;
|
42 |
|
\ | No newline at end of file |