-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
97 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { factory } from '../utils/factory' | ||
|
||
const name = 'replacer' | ||
const dependencies = [] | ||
|
||
export const createReplacer = /* #__PURE__ */ factory(name, dependencies, ({ }) => { | ||
/** | ||
* Stringify data types into their JSON representation. | ||
* Most data types can be serialized using their `.toJSON` method, | ||
* but not all, for example the number `Infinity`. For these cases you have | ||
* to use the replacer. Example usage: | ||
* | ||
* JSON.stringify([2, Infinity], math.replacer) | ||
* | ||
* @param {string} key | ||
* @param {*} value | ||
* @returns {*} Returns the replaced object | ||
*/ | ||
return function replacer (key, value) { | ||
// the numeric values Infinitiy, -Infinity, and NaN cannot be serialized to JSON | ||
if (typeof value === 'number' && (!isFinite(value) || isNaN(value))) { | ||
return { | ||
mathjs: 'number', | ||
value: String(value) | ||
} | ||
} | ||
|
||
return value | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters