mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-25 15:07:57 +00:00
22 lines
470 B
JavaScript
22 lines
470 B
JavaScript
'use strict';
|
|
|
|
module.exports = function (math) {
|
|
/**
|
|
* Instantiate mathjs data types from their JSON representation
|
|
* @param {string} key
|
|
* @param {*} value
|
|
* @returns {*} Returns the revived object
|
|
*/
|
|
function reviver(key, value) {
|
|
var name = value && value.mathjs;
|
|
|
|
var constructor = math.type[name];
|
|
if (constructor && constructor.fromJSON) {
|
|
return constructor.fromJSON(value);
|
|
}
|
|
|
|
return value;
|
|
}
|
|
|
|
return reviver;
|
|
}; |