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 | * Attach type information
|
19 | */
|
20 |
|
21 |
|
22 | ResultSet.prototype.type = 'ResultSet';
|
23 | ResultSet.prototype.isResultSet = true;
|
24 | /**
|
25 | * Returns the array with results hold by this ResultSet
|
26 | * @memberof ResultSet
|
27 | * @returns {Array} entries
|
28 | */
|
29 |
|
30 | ResultSet.prototype.valueOf = function () {
|
31 | return this.entries;
|
32 | };
|
33 | /**
|
34 | * Returns the stringified results of the ResultSet
|
35 | * @memberof ResultSet
|
36 | * @returns {string} string
|
37 | */
|
38 |
|
39 |
|
40 | ResultSet.prototype.toString = function () {
|
41 | return '[' + this.entries.join(', ') + ']';
|
42 | };
|
43 | /**
|
44 | * Get a JSON representation of the ResultSet
|
45 | * @memberof ResultSet
|
46 | * @returns {Object} Returns a JSON object structured as:
|
47 | * `{"mathjs": "ResultSet", "entries": [...]}`
|
48 | */
|
49 |
|
50 |
|
51 | ResultSet.prototype.toJSON = function () {
|
52 | return {
|
53 | mathjs: 'ResultSet',
|
54 | entries: this.entries
|
55 | };
|
56 | };
|
57 | /**
|
58 | * Instantiate a ResultSet from a JSON object
|
59 | * @memberof ResultSet
|
60 | * @param {Object} json A JSON object structured as:
|
61 | * `{"mathjs": "ResultSet", "entries": [...]}`
|
62 | * @return {ResultSet}
|
63 | */
|
64 |
|
65 |
|
66 | ResultSet.fromJSON = function (json) {
|
67 | return new ResultSet(json.entries);
|
68 | };
|
69 |
|
70 | return ResultSet;
|
71 | }
|
72 |
|
73 | exports.name = 'ResultSet';
|
74 | exports.path = 'type';
|
75 | exports.factory = factory; |
\ | No newline at end of file |