1 |
|
2 |
|
3 | function factory (type, config, load, typed) {
|
4 | /**
|
5 | * A ResultSet contains a list or results
|
6 | * @class ResultSet
|
7 | * @param {Array} entries
|
8 | * @constructor ResultSet
|
9 | */
|
10 | function ResultSet (entries) {
|
11 | if (!(this instanceof ResultSet)) {
|
12 | throw new SyntaxError('Constructor must be called with the new operator')
|
13 | }
|
14 |
|
15 | this.entries = entries || []
|
16 | }
|
17 |
|
18 | /**
|
19 | * Attach type information
|
20 | */
|
21 | ResultSet.prototype.type = 'ResultSet'
|
22 | ResultSet.prototype.isResultSet = true
|
23 |
|
24 | /**
|
25 | * Returns the array with results hold by this ResultSet
|
26 | * @memberof ResultSet
|
27 | * @returns {Array} entries
|
28 | */
|
29 | ResultSet.prototype.valueOf = function () {
|
30 | return this.entries
|
31 | }
|
32 |
|
33 | /**
|
34 | * Returns the stringified results of the ResultSet
|
35 | * @memberof ResultSet
|
36 | * @returns {string} string
|
37 | */
|
38 | ResultSet.prototype.toString = function () {
|
39 | return '[' + this.entries.join(', ') + ']'
|
40 | }
|
41 |
|
42 | /**
|
43 | * Get a JSON representation of the ResultSet
|
44 | * @memberof ResultSet
|
45 | * @returns {Object} Returns a JSON object structured as:
|
46 | * `{"mathjs": "ResultSet", "entries": [...]}`
|
47 | */
|
48 | ResultSet.prototype.toJSON = function () {
|
49 | return {
|
50 | mathjs: 'ResultSet',
|
51 | entries: this.entries
|
52 | }
|
53 | }
|
54 |
|
55 | /**
|
56 | * Instantiate a ResultSet from a JSON object
|
57 | * @memberof ResultSet
|
58 | * @param {Object} json A JSON object structured as:
|
59 | * `{"mathjs": "ResultSet", "entries": [...]}`
|
60 | * @return {ResultSet}
|
61 | */
|
62 | ResultSet.fromJSON = function (json) {
|
63 | return new ResultSet(json.entries)
|
64 | }
|
65 |
|
66 | return ResultSet
|
67 | }
|
68 |
|
69 | exports.name = 'ResultSet'
|
70 | exports.path = 'type'
|
71 | exports.factory = factory
|