UNPKG

623 BJavaScriptView Raw
1import { factory } from '../utils/factory.js';
2var name = 'reviver';
3var dependencies = ['classes'];
4export var createReviver = /* #__PURE__ */factory(name, dependencies, _ref => {
5 var {
6 classes
7 } = _ref;
8
9 /**
10 * Instantiate mathjs data types from their JSON representation
11 * @param {string} key
12 * @param {*} value
13 * @returns {*} Returns the revived object
14 */
15 return function reviver(key, value) {
16 var constructor = classes[value && value.mathjs];
17
18 if (constructor && typeof constructor.fromJSON === 'function') {
19 return constructor.fromJSON(value);
20 }
21
22 return value;
23 };
24});
\No newline at end of file