1 | 'use strict'
|
2 |
|
3 | function factory (type, config, load, typed, math) {
|
4 | |
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | return function reviver (key, value) {
|
11 | const constructor = type[value && value.mathjs] ||
|
12 | (math.expression && math.expression.node[value && value.mathjs])
|
13 | // TODO: instead of checking math.expression.node, expose all Node classes on math.type too
|
14 |
|
15 | if (constructor && typeof constructor.fromJSON === 'function') {
|
16 | return constructor.fromJSON(value)
|
17 | }
|
18 |
|
19 | return value
|
20 | }
|
21 | }
|
22 |
|
23 | exports.name = 'reviver'
|
24 | exports.path = 'json'
|
25 | exports.factory = factory
|
26 | exports.math = true // request the math namespace as fifth argument
|