1 | 'use strict';
|
2 |
|
3 | var deepMap = require('../../../utils/collection/deepMap');
|
4 |
|
5 | function factory(type, config, load, typed) {
|
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 | var fraction = typed('fraction', {
|
32 | 'number': function number(x) {
|
33 | if (!isFinite(x) || isNaN(x)) {
|
34 | throw new Error(x + ' cannot be represented as a fraction');
|
35 | }
|
36 |
|
37 | return new type.Fraction(x);
|
38 | },
|
39 |
|
40 | 'string': function string(x) {
|
41 | return new type.Fraction(x);
|
42 | },
|
43 |
|
44 | 'number, number': function numberNumber(numerator, denominator) {
|
45 | return new type.Fraction(numerator, denominator);
|
46 | },
|
47 |
|
48 | 'null': function _null(x) {
|
49 | return new type.Fraction(0);
|
50 | },
|
51 |
|
52 | 'BigNumber': function BigNumber(x) {
|
53 | return new type.Fraction(x.toString());
|
54 | },
|
55 |
|
56 | 'Fraction': function Fraction(x) {
|
57 | return x;
|
58 | },
|
59 |
|
60 | 'Object': function Object(x) {
|
61 | return new type.Fraction(x);
|
62 | },
|
63 |
|
64 | 'Array | Matrix': function ArrayMatrix(x) {
|
65 | return deepMap(x, fraction);
|
66 | }
|
67 | });
|
68 |
|
69 | return fraction;
|
70 | }
|
71 |
|
72 | exports.name = 'fraction';
|
73 | exports.factory = factory; |
\ | No newline at end of file |