UNPKG

mathjs

Version:

Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser with support for symbolic computation, comes with a large set of built-in functions and constants, and offers an integrated solution to work with dif

41 lines (39 loc) 1.15 kB
import Fraction from 'fraction.js'; import { factory } from '../../utils/factory.js'; var name = 'Fraction'; var dependencies = []; export var createFractionClass = /* #__PURE__ */factory(name, dependencies, () => { /** * Attach type information */ Object.defineProperty(Fraction, 'name', { value: 'Fraction' }); Fraction.prototype.constructor = Fraction; Fraction.prototype.type = 'Fraction'; Fraction.prototype.isFraction = true; /** * Get a JSON representation of a Fraction containing type information * @returns {Object} Returns a JSON object structured as: * `{"mathjs": "Fraction", "n": "3", "d": "8"}` */ Fraction.prototype.toJSON = function () { return { mathjs: 'Fraction', n: String(this.s * this.n), d: String(this.d) }; }; /** * Instantiate a Fraction from a JSON object * @param {Object} json a JSON object structured as: * `{"mathjs": "Fraction", "n": "3", "d": "8"}` * @return {BigNumber} */ Fraction.fromJSON = function (json) { return new Fraction(json); }; return Fraction; }, { isClass: true });