scorm-again 1.7.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/.babelrc +18 -7
  2. package/.github/dependabot.yml +5 -0
  3. package/.github/workflows/main.yml +79 -0
  4. package/.jsdoc.json +4 -5
  5. package/.mocharc.json +8 -0
  6. package/.run/Mocha Unit Tests.run.xml +5 -2
  7. package/CONTRIBUTING.md +1 -1
  8. package/README.md +14 -1
  9. package/dist/aicc.js +3661 -7170
  10. package/dist/aicc.js.map +1 -1
  11. package/dist/aicc.min.js +2 -40
  12. package/dist/aicc.min.js.map +1 -0
  13. package/dist/scorm-again.js +5671 -10695
  14. package/dist/scorm-again.js.map +1 -1
  15. package/dist/scorm-again.min.js +2 -52
  16. package/dist/scorm-again.min.js.map +1 -0
  17. package/dist/scorm12.js +2871 -5433
  18. package/dist/scorm12.js.map +1 -1
  19. package/dist/scorm12.min.js +2 -34
  20. package/dist/scorm12.min.js.map +1 -0
  21. package/dist/scorm2004.js +3868 -6797
  22. package/dist/scorm2004.js.map +1 -1
  23. package/dist/scorm2004.min.js +2 -40
  24. package/dist/scorm2004.min.js.map +1 -0
  25. package/eslint.config.js +21 -0
  26. package/package.json +72 -34
  27. package/results.json +34254 -0
  28. package/src/{AICC.js → AICC.ts} +27 -21
  29. package/src/BaseAPI.ts +1449 -0
  30. package/src/Scorm12API.ts +360 -0
  31. package/src/{Scorm2004API.js → Scorm2004API.ts} +245 -163
  32. package/src/cmi/aicc_cmi.ts +1248 -0
  33. package/src/cmi/common.ts +411 -0
  34. package/src/cmi/scorm12_cmi.ts +1426 -0
  35. package/src/cmi/scorm2004_cmi.ts +1874 -0
  36. package/src/constants/api_constants.ts +318 -0
  37. package/src/constants/error_codes.ts +88 -0
  38. package/src/constants/language_constants.ts +394 -0
  39. package/src/constants/regex.ts +97 -0
  40. package/src/constants/{response_constants.js → response_constants.ts} +67 -62
  41. package/src/exceptions.ts +133 -0
  42. package/src/exports/aicc.js +1 -1
  43. package/src/exports/scorm-again.js +3 -3
  44. package/src/exports/scorm12.js +1 -1
  45. package/src/exports/scorm2004.js +1 -1
  46. package/src/{utilities.js → utilities.ts} +114 -74
  47. package/tea.yaml +6 -0
  48. package/test/{AICC.spec.js → AICC.spec.ts} +70 -72
  49. package/test/Scorm12API.spec.ts +580 -0
  50. package/test/Scorm2004API.spec.ts +812 -0
  51. package/test/api_helpers.ts +176 -0
  52. package/test/cmi/{aicc_cmi.spec.js → aicc_cmi.spec.ts} +193 -209
  53. package/test/cmi/{scorm12_cmi.spec.js → scorm12_cmi.spec.ts} +251 -269
  54. package/test/cmi/scorm2004_cmi.spec.ts +1031 -0
  55. package/test/cmi_helpers.ts +207 -0
  56. package/test/exceptions.spec.ts +79 -0
  57. package/test/field_values.ts +202 -0
  58. package/test/utilities.spec.ts +322 -0
  59. package/tsconfig.json +18 -0
  60. package/webpack.config.js +65 -0
  61. package/.circleci/config.yml +0 -99
  62. package/.codeclimate.yml +0 -7
  63. package/.eslintrc.js +0 -36
  64. package/src/.flowconfig +0 -11
  65. package/src/BaseAPI.js +0 -1275
  66. package/src/Scorm12API.js +0 -308
  67. package/src/cmi/aicc_cmi.js +0 -1141
  68. package/src/cmi/common.js +0 -328
  69. package/src/cmi/scorm12_cmi.js +0 -1312
  70. package/src/cmi/scorm2004_cmi.js +0 -1692
  71. package/src/constants/api_constants.js +0 -218
  72. package/src/constants/error_codes.js +0 -87
  73. package/src/constants/language_constants.js +0 -76
  74. package/src/constants/regex.js +0 -84
  75. package/src/exceptions.js +0 -104
  76. package/test/Scorm12API.spec.js +0 -528
  77. package/test/Scorm2004API.spec.js +0 -775
  78. package/test/abstract_classes.spec.js +0 -17
  79. package/test/api_helpers.js +0 -128
  80. package/test/cmi/scorm2004_cmi.spec.js +0 -1066
  81. package/test/cmi_helpers.js +0 -161
  82. package/test/exceptions.spec.js +0 -71
  83. package/test/field_values.js +0 -353
  84. package/test/utilities.spec.js +0 -339
  85. package/webpack.js +0 -78
package/src/cmi/common.js DELETED
@@ -1,328 +0,0 @@
1
- // @flow
2
- import APIConstants from '../constants/api_constants';
3
- import ErrorCodes from '../constants/error_codes';
4
- import Regex from '../constants/regex';
5
-
6
- const scorm12_constants = APIConstants.scorm12;
7
- const scorm12_regex = Regex.scorm12;
8
- const scorm12_error_codes = ErrorCodes.scorm12;
9
-
10
- /**
11
- * Check if the value matches the proper format. If not, throw proper error code.
12
- *
13
- * @param {string} value
14
- * @param {string} regexPattern
15
- * @param {number} errorCode
16
- * @param {class} errorClass
17
- * @param {boolean} allowEmptyString
18
- * @return {boolean}
19
- */
20
- export function checkValidFormat(
21
- value: String,
22
- regexPattern: String,
23
- errorCode: number,
24
- errorClass: function,
25
- allowEmptyString?: boolean) {
26
- const formatRegex = new RegExp(regexPattern);
27
- const matches = value.match(formatRegex);
28
- if (allowEmptyString && value === '') {
29
- return true;
30
- }
31
- if (value === undefined || !matches || matches[0] === '') {
32
- throw new errorClass.prototype.constructor(errorCode);
33
- }
34
- return true;
35
- }
36
-
37
- /**
38
- * Check if the value matches the proper range. If not, throw proper error code.
39
- *
40
- * @param {*} value
41
- * @param {string} rangePattern
42
- * @param {number} errorCode
43
- * @param {class} errorClass
44
- * @return {boolean}
45
- */
46
- export function checkValidRange(
47
- value: any,
48
- rangePattern: String,
49
- errorCode: number,
50
- errorClass: function) {
51
- const ranges = rangePattern.split('#');
52
- value = value * 1.0;
53
- if (value >= ranges[0]) {
54
- if ((ranges[1] === '*') || (value <= ranges[1])) {
55
- return true;
56
- } else {
57
- throw new errorClass.prototype.constructor(errorCode);
58
- }
59
- } else {
60
- throw new errorClass.prototype.constructor(errorCode);
61
- }
62
- }
63
-
64
- /**
65
- * Base class for API cmi objects
66
- */
67
- export class BaseCMI {
68
- jsonString = false;
69
- #initialized = false;
70
- #start_time;
71
-
72
- /**
73
- * Constructor for BaseCMI, just marks the class as abstract
74
- */
75
- constructor() {
76
- if (new.target === BaseCMI) {
77
- throw new TypeError('Cannot construct BaseCMI instances directly');
78
- }
79
- }
80
-
81
- /**
82
- * Getter for #initialized
83
- * @return {boolean}
84
- */
85
- get initialized() {
86
- return this.#initialized;
87
- }
88
-
89
- /**
90
- * Getter for #start_time
91
- * @return {Number}
92
- */
93
- get start_time() {
94
- return this.#start_time;
95
- }
96
-
97
- /**
98
- * Called when the API has been initialized after the CMI has been created
99
- */
100
- initialize() {
101
- this.#initialized = true;
102
- }
103
-
104
- /**
105
- * Called when the player should override the 'session_time' provided by
106
- * the module
107
- */
108
- setStartTime() {
109
- this.#start_time = new Date().getTime();
110
- }
111
- }
112
-
113
- /**
114
- * Base class for cmi *.score objects
115
- */
116
- export class CMIScore extends BaseCMI {
117
- /**
118
- * Constructor for *.score
119
- * @param {string} score_children
120
- * @param {string} score_range
121
- * @param {string} max
122
- * @param {number} invalidErrorCode
123
- * @param {number} invalidTypeCode
124
- * @param {number} invalidRangeCode
125
- * @param {string} decimalRegex
126
- * @param {class} errorClass
127
- */
128
- constructor(
129
- {
130
- score_children,
131
- score_range,
132
- max,
133
- invalidErrorCode,
134
- invalidTypeCode,
135
- invalidRangeCode,
136
- decimalRegex,
137
- errorClass,
138
- }) {
139
- super();
140
-
141
- this.#_children = score_children ||
142
- scorm12_constants.score_children;
143
- this.#_score_range = !score_range ? false : scorm12_regex.score_range;
144
- this.#max = (max || max === '') ? max : '100';
145
- this.#_invalid_error_code = invalidErrorCode ||
146
- scorm12_error_codes.INVALID_SET_VALUE;
147
- this.#_invalid_type_code = invalidTypeCode ||
148
- scorm12_error_codes.TYPE_MISMATCH;
149
- this.#_invalid_range_code = invalidRangeCode ||
150
- scorm12_error_codes.VALUE_OUT_OF_RANGE;
151
- this.#_decimal_regex = decimalRegex ||
152
- scorm12_regex.CMIDecimal;
153
- this.#_error_class = errorClass;
154
- }
155
-
156
- #_children;
157
- #_score_range;
158
- #_invalid_error_code;
159
- #_invalid_type_code;
160
- #_invalid_range_code;
161
- #_decimal_regex;
162
- #_error_class;
163
- #raw = '';
164
- #min = '';
165
- #max;
166
-
167
- /**
168
- * Getter for _children
169
- * @return {string}
170
- * @private
171
- */
172
- get _children() {
173
- return this.#_children;
174
- }
175
-
176
- /**
177
- * Setter for _children. Just throws an error.
178
- * @param {string} _children
179
- * @private
180
- */
181
- set _children(_children) {
182
- throw new this.#_error_class.prototype.constructor(this.#_invalid_error_code);
183
- }
184
-
185
- /**
186
- * Getter for #raw
187
- * @return {string}
188
- */
189
- get raw() {
190
- return this.#raw;
191
- }
192
-
193
- /**
194
- * Setter for #raw
195
- * @param {string} raw
196
- */
197
- set raw(raw) {
198
- if (checkValidFormat(raw, this.#_decimal_regex, this.#_invalid_type_code, this.#_error_class) &&
199
- (!this.#_score_range ||
200
- checkValidRange(raw, this.#_score_range, this.#_invalid_range_code, this.#_error_class))) {
201
- this.#raw = raw;
202
- }
203
- }
204
-
205
- /**
206
- * Getter for #min
207
- * @return {string}
208
- */
209
- get min() {
210
- return this.#min;
211
- }
212
-
213
- /**
214
- * Setter for #min
215
- * @param {string} min
216
- */
217
- set min(min) {
218
- if (checkValidFormat(min, this.#_decimal_regex, this.#_invalid_type_code, this.#_error_class) &&
219
- (!this.#_score_range ||
220
- checkValidRange(min, this.#_score_range, this.#_invalid_range_code, this.#_error_class))) {
221
- this.#min = min;
222
- }
223
- }
224
-
225
- /**
226
- * Getter for #max
227
- * @return {string}
228
- */
229
- get max() {
230
- return this.#max;
231
- }
232
-
233
- /**
234
- * Setter for #max
235
- * @param {string} max
236
- */
237
- set max(max) {
238
- if (checkValidFormat(max, this.#_decimal_regex, this.#_invalid_type_code, this.#_error_class) &&
239
- (!this.#_score_range ||
240
- checkValidRange(max, this.#_score_range, this.#_invalid_range_code, this.#_error_class))) {
241
- this.#max = max;
242
- }
243
- }
244
-
245
- /**
246
- * toJSON for *.score
247
- * @return {{min: string, max: string, raw: string}}
248
- */
249
- toJSON() {
250
- this.jsonString = true;
251
- const result = {
252
- 'raw': this.raw,
253
- 'min': this.min,
254
- 'max': this.max,
255
- };
256
- delete this.jsonString;
257
- return result;
258
- }
259
- }
260
-
261
- /**
262
- * Base class for cmi *.n objects
263
- */
264
- export class CMIArray extends BaseCMI {
265
- /**
266
- * Constructor cmi *.n arrays
267
- * @param {string} children
268
- * @param {number} errorCode
269
- * @param {class} errorClass
270
- */
271
- constructor({children, errorCode, errorClass}) {
272
- super();
273
- this.#_children = children;
274
- this.#errorCode = errorCode;
275
- this.#errorClass = errorClass;
276
- this.childArray = [];
277
- }
278
-
279
- #errorCode;
280
- #errorClass;
281
- #_children;
282
-
283
- /**
284
- * Getter for _children
285
- * @return {*}
286
- */
287
- get _children() {
288
- return this.#_children;
289
- }
290
-
291
- /**
292
- * Setter for _children. Just throws an error.
293
- * @param {string} _children
294
- */
295
- set _children(_children) {
296
- throw new this.#errorClass.prototype.constructor(this.#errorCode);
297
- }
298
-
299
- /**
300
- * Getter for _count
301
- * @return {number}
302
- */
303
- get _count() {
304
- return this.childArray.length;
305
- }
306
-
307
- /**
308
- * Setter for _count. Just throws an error.
309
- * @param {number} _count
310
- */
311
- set _count(_count) {
312
- throw new this.#errorClass.prototype.constructor(this.#errorCode);
313
- }
314
-
315
- /**
316
- * toJSON for *.n arrays
317
- * @return {object}
318
- */
319
- toJSON() {
320
- this.jsonString = true;
321
- const result = {};
322
- for (let i = 0; i < this.childArray.length; i++) {
323
- result[i + ''] = this.childArray[i];
324
- }
325
- delete this.jsonString;
326
- return result;
327
- }
328
- }