1 | 'use strict'
|
2 |
|
3 | function factory (type, config, load, typed) {
|
4 | const getTypeOf = load(require('../function/utils/typeof'))
|
5 |
|
6 | const validInputTypes = {
|
7 | 'string': true,
|
8 | 'number': true,
|
9 | 'BigNumber': true,
|
10 | 'Fraction': true
|
11 | }
|
12 |
|
13 |
|
14 | const validOutputTypes = {
|
15 | 'number': load(require('./number')),
|
16 | 'BigNumber': load(require('./bignumber/function/bignumber')),
|
17 | 'Fraction': load(require('./fraction/function/fraction'))
|
18 | }
|
19 |
|
20 | |
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | const numeric = function (value, outputType) {
|
29 | const inputType = getTypeOf(value)
|
30 |
|
31 | if (!(inputType in validInputTypes)) {
|
32 | throw new TypeError('Cannot convert ' + value + ' of type "' + inputType + '"; valid input types are ' + Object.keys(validInputTypes).join(', '))
|
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
|