1 | 'use strict';
|
2 |
|
3 | function factory(type, config, load, typed) {
|
4 | var getTypeOf = load(require('../function/utils/typeof'));
|
5 | var validInputTypes = {
|
6 | 'string': true,
|
7 | 'number': true,
|
8 | 'BigNumber': true,
|
9 | 'Fraction': true
|
10 |
|
11 | };
|
12 | var validOutputTypes = {
|
13 | 'number': load(require('./number')),
|
14 | 'BigNumber': load(require('./bignumber/function/bignumber')),
|
15 | 'Fraction': load(require('./fraction/function/fraction'))
|
16 | |
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | };
|
26 |
|
27 | var numeric = function numeric(value, outputType) {
|
28 | var inputType = getTypeOf(value);
|
29 |
|
30 | if (!(inputType in validInputTypes)) {
|
31 | throw new TypeError('Cannot convert ' + value + ' of type "' + inputType + '"; valid input types are ' + Object.keys(validInputTypes).join(', '));
|
32 | }
|
33 |
|
34 | if (!(outputType in validOutputTypes)) {
|
35 | throw new TypeError('Cannot convert ' + value + ' to type "' + outputType + '"; valid output types are ' + Object.keys(validOutputTypes).join(', '));
|
36 | }
|
37 |
|
38 | if (outputType === inputType) {
|
39 | return value;
|
40 | } else {
|
41 | return validOutputTypes[outputType](value);
|
42 | }
|
43 | };
|
44 |
|
45 | numeric.toTex = function (node, options) {
|
46 |
|
47 | return node.args[0].toTex();
|
48 | };
|
49 |
|
50 | return numeric;
|
51 | }
|
52 |
|
53 |
|
54 |
|
55 | exports.path = 'type';
|
56 | exports.name = '_numeric';
|
57 | exports.factory = factory; |
\ | No newline at end of file |