UNPKG

901 BJavaScriptView Raw
1'use strict';
2
3var Fraction = require('fraction.js');
4
5/**
6 * Attach type information
7 */
8Fraction.prototype.type = 'Fraction';
9Fraction.prototype.isFraction = true;
10
11/**
12 * Get a JSON representation of a Fraction containing type information
13 * @returns {Object} Returns a JSON object structured as:
14 * `{"mathjs": "Fraction", "n": 3, "d": 8}`
15 */
16Fraction.prototype.toJSON = function () {
17 return {
18 mathjs: 'Fraction',
19 n: this.s * this.n,
20 d: this.d
21 };
22};
23
24/**
25 * Instantiate a Fraction from a JSON object
26 * @param {Object} json a JSON object structured as:
27 * `{"mathjs": "Fraction", "n": 3, "d": 8}`
28 * @return {BigNumber}
29 */
30Fraction.fromJSON = function (json) {
31 return new Fraction(json);
32};
33
34function factory(type, config, load, typed) {
35 return Fraction;
36}
37
38exports.name = 'Fraction';
39exports.path = 'type';
40exports.factory = factory;
\No newline at end of file