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

72 lines (62 loc) 1.69 kB
'use strict' function factory (type, config, load, typed) { /** * A ResultSet contains a list or results * @class ResultSet * @param {Array} entries * @constructor ResultSet */ function ResultSet (entries) { if (!(this instanceof ResultSet)) { throw new SyntaxError('Constructor must be called with the new operator') } this.entries = entries || [] } /** * Attach type information */ ResultSet.prototype.type = 'ResultSet' ResultSet.prototype.isResultSet = true /** * Returns the array with results hold by this ResultSet * @memberof ResultSet * @returns {Array} entries */ ResultSet.prototype.valueOf = function () { return this.entries } /** * Returns the stringified results of the ResultSet * @memberof ResultSet * @returns {string} string */ ResultSet.prototype.toString = function () { return '[' + this.entries.join(', ') + ']' } /** * Get a JSON representation of the ResultSet * @memberof ResultSet * @returns {Object} Returns a JSON object structured as: * `{"mathjs": "ResultSet", "entries": [...]}` */ ResultSet.prototype.toJSON = function () { return { mathjs: 'ResultSet', entries: this.entries } } /** * Instantiate a ResultSet from a JSON object * @memberof ResultSet * @param {Object} json A JSON object structured as: * `{"mathjs": "ResultSet", "entries": [...]}` * @return {ResultSet} */ ResultSet.fromJSON = function (json) { return new ResultSet(json.entries) } return ResultSet } exports.name = 'ResultSet' exports.path = 'type' exports.factory = factory