1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.createNumber = void 0;
|
7 |
|
8 | var _factory = require("../utils/factory");
|
9 |
|
10 | var _collection = require("../utils/collection");
|
11 |
|
12 | var name = 'number';
|
13 | var dependencies = ['typed'];
|
14 | var createNumber = (0, _factory.factory)(name, dependencies, function (_ref) {
|
15 | var typed = _ref.typed;
|
16 |
|
17 | |
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | var number = typed('number', {
|
43 | '': function _() {
|
44 | return 0;
|
45 | },
|
46 | number: function number(x) {
|
47 | return x;
|
48 | },
|
49 | string: function string(x) {
|
50 | if (x === 'NaN') return NaN;
|
51 | var num = Number(x);
|
52 |
|
53 | if (isNaN(num)) {
|
54 | throw new SyntaxError('String "' + x + '" is no valid number');
|
55 | }
|
56 |
|
57 | return num;
|
58 | },
|
59 | BigNumber: function BigNumber(x) {
|
60 | return x.toNumber();
|
61 | },
|
62 | Fraction: function Fraction(x) {
|
63 | return x.valueOf();
|
64 | },
|
65 | Unit: function Unit(x) {
|
66 | throw new Error('Second argument with valueless unit expected');
|
67 | },
|
68 | "null": function _null(x) {
|
69 | return 0;
|
70 | },
|
71 | 'Unit, string | Unit': function UnitStringUnit(unit, valuelessUnit) {
|
72 | return unit.toNumber(valuelessUnit);
|
73 | },
|
74 | 'Array | Matrix': function ArrayMatrix(x) {
|
75 | return (0, _collection.deepMap)(x, number);
|
76 | }
|
77 | });
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 | number.fromJSON = function (json) {
|
84 | return parseFloat(json.value);
|
85 | };
|
86 |
|
87 | return number;
|
88 | });
|
89 | exports.createNumber = createNumber; |
\ | No newline at end of file |