scorm-again 1.7.0 → 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 +73 -35
  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
@@ -1,1312 +0,0 @@
1
- // @flow
2
- import {
3
- BaseCMI,
4
- checkValidFormat,
5
- checkValidRange,
6
- CMIArray,
7
- CMIScore,
8
- } from './common';
9
- import APIConstants from '../constants/api_constants';
10
- import ErrorCodes from '../constants/error_codes';
11
- import Regex from '../constants/regex';
12
- import {Scorm12ValidationError} from '../exceptions';
13
- import * as Utilities from '../utilities';
14
- import * as Util from '../utilities';
15
-
16
- const scorm12_constants = APIConstants.scorm12;
17
- const scorm12_regex = Regex.scorm12;
18
- const scorm12_error_codes = ErrorCodes.scorm12;
19
-
20
- /**
21
- * Helper method for throwing Read Only error
22
- */
23
- export function throwReadOnlyError() {
24
- throw new Scorm12ValidationError(scorm12_error_codes.READ_ONLY_ELEMENT);
25
- }
26
-
27
- /**
28
- * Helper method for throwing Write Only error
29
- */
30
- export function throwWriteOnlyError() {
31
- throw new Scorm12ValidationError(scorm12_error_codes.WRITE_ONLY_ELEMENT);
32
- }
33
-
34
- /**
35
- * Helper method for throwing Invalid Set error
36
- */
37
- function throwInvalidValueError() {
38
- throw new Scorm12ValidationError(scorm12_error_codes.INVALID_SET_VALUE);
39
- }
40
-
41
- /**
42
- * Helper method, no reason to have to pass the same error codes every time
43
- * @param {*} value
44
- * @param {string} regexPattern
45
- * @param {boolean} allowEmptyString
46
- * @return {boolean}
47
- */
48
- export function check12ValidFormat(
49
- value: String,
50
- regexPattern: String,
51
- allowEmptyString?: boolean) {
52
- return checkValidFormat(
53
- value,
54
- regexPattern,
55
- scorm12_error_codes.TYPE_MISMATCH,
56
- Scorm12ValidationError,
57
- allowEmptyString
58
- );
59
- }
60
-
61
- /**
62
- * Helper method, no reason to have to pass the same error codes every time
63
- * @param {*} value
64
- * @param {string} rangePattern
65
- * @param {boolean} allowEmptyString
66
- * @return {boolean}
67
- */
68
- export function check12ValidRange(
69
- value: any,
70
- rangePattern: String,
71
- allowEmptyString?: boolean) {
72
- return checkValidRange(
73
- value,
74
- rangePattern,
75
- scorm12_error_codes.VALUE_OUT_OF_RANGE,
76
- Scorm12ValidationError,
77
- allowEmptyString
78
- );
79
- }
80
-
81
- /**
82
- * Class representing the cmi object for SCORM 1.2
83
- */
84
- export class CMI extends BaseCMI {
85
- #_children = '';
86
- #_version = '3.4';
87
- #launch_data = '';
88
- #comments = '';
89
- #comments_from_lms = '';
90
-
91
- student_data = null;
92
-
93
- /**
94
- * Constructor for the SCORM 1.2 cmi object
95
- * @param {string} cmi_children
96
- * @param {(CMIStudentData|AICCCMIStudentData)} student_data
97
- * @param {boolean} initialized
98
- */
99
- constructor(cmi_children, student_data, initialized: boolean) {
100
- super();
101
-
102
- if (initialized) this.initialize();
103
-
104
- this.#_children = cmi_children ?
105
- cmi_children :
106
- scorm12_constants.cmi_children;
107
- this.core = new CMICore();
108
- this.objectives = new CMIObjectives();
109
- this.student_data = student_data ? student_data : new CMIStudentData();
110
- this.student_preference = new CMIStudentPreference();
111
- this.interactions = new CMIInteractions();
112
- }
113
-
114
- /**
115
- * Called when the API has been initialized after the CMI has been created
116
- */
117
- initialize() {
118
- super.initialize();
119
- this.core?.initialize();
120
- this.objectives?.initialize();
121
- this.student_data?.initialize();
122
- this.student_preference?.initialize();
123
- this.interactions?.initialize();
124
- }
125
-
126
- /**
127
- * toJSON for cmi
128
- *
129
- * @return {
130
- * {
131
- * suspend_data: string,
132
- * launch_data: string,
133
- * comments: string,
134
- * comments_from_lms: string,
135
- * core: CMICore,
136
- * objectives: CMIObjectives,
137
- * student_data: CMIStudentData,
138
- * student_preference: CMIStudentPreference,
139
- * interactions: CMIInteractions
140
- * }
141
- * }
142
- */
143
- toJSON() {
144
- this.jsonString = true;
145
- const result = {
146
- 'suspend_data': this.suspend_data,
147
- 'launch_data': this.launch_data,
148
- 'comments': this.comments,
149
- 'comments_from_lms': this.comments_from_lms,
150
- 'core': this.core,
151
- 'objectives': this.objectives,
152
- 'student_data': this.student_data,
153
- 'student_preference': this.student_preference,
154
- 'interactions': this.interactions,
155
- };
156
- delete this.jsonString;
157
- return result;
158
- }
159
-
160
- /**
161
- * Getter for #_version
162
- * @return {string}
163
- */
164
- get _version() {
165
- return this.#_version;
166
- }
167
-
168
- /**
169
- * Setter for #_version. Just throws an error.
170
- * @param {string} _version
171
- */
172
- set _version(_version) {
173
- throwInvalidValueError();
174
- }
175
-
176
- /**
177
- * Getter for #_children
178
- * @return {string}
179
- */
180
- get _children() {
181
- return this.#_children;
182
- }
183
-
184
- /**
185
- * Setter for #_version. Just throws an error.
186
- * @param {string} _children
187
- */
188
- set _children(_children) {
189
- throwInvalidValueError();
190
- }
191
-
192
- /**
193
- * Getter for #suspend_data
194
- * @return {string}
195
- */
196
- get suspend_data() {
197
- return this.core?.suspend_data;
198
- }
199
-
200
- /**
201
- * Setter for #suspend_data
202
- * @param {string} suspend_data
203
- */
204
- set suspend_data(suspend_data) {
205
- if (this.core) {
206
- this.core.suspend_data = suspend_data;
207
- }
208
- }
209
-
210
- /**
211
- * Getter for #launch_data
212
- * @return {string}
213
- */
214
- get launch_data() {
215
- return this.#launch_data;
216
- }
217
-
218
- /**
219
- * Setter for #launch_data. Can only be called before initialization.
220
- * @param {string} launch_data
221
- */
222
- set launch_data(launch_data) {
223
- !this.initialized ? this.#launch_data = launch_data : throwReadOnlyError();
224
- }
225
-
226
- /**
227
- * Getter for #comments
228
- * @return {string}
229
- */
230
- get comments() {
231
- return this.#comments;
232
- }
233
-
234
- /**
235
- * Setter for #comments
236
- * @param {string} comments
237
- */
238
- set comments(comments) {
239
- if (check12ValidFormat(comments, scorm12_regex.CMIString4096, true)) {
240
- this.#comments = comments;
241
- }
242
- }
243
-
244
- /**
245
- * Getter for #comments_from_lms
246
- * @return {string}
247
- */
248
- get comments_from_lms() {
249
- return this.#comments_from_lms;
250
- }
251
-
252
- /**
253
- * Setter for #comments_from_lms. Can only be called before initialization.
254
- * @param {string} comments_from_lms
255
- */
256
- set comments_from_lms(comments_from_lms) {
257
- !this.initialized ?
258
- this.#comments_from_lms = comments_from_lms :
259
- throwReadOnlyError();
260
- }
261
-
262
- /**
263
- * Adds the current session time to the existing total time.
264
- *
265
- * @return {string}
266
- */
267
- getCurrentTotalTime() {
268
- return this.core.getCurrentTotalTime(this.start_time);
269
- }
270
- }
271
-
272
- /**
273
- * Class representing the cmi.core object
274
- * @extends BaseCMI
275
- */
276
- class CMICore extends BaseCMI {
277
- /**
278
- * Constructor for cmi.core
279
- */
280
- constructor() {
281
- super();
282
-
283
- this.score = new CMIScore(
284
- {
285
- score_children: scorm12_constants.score_children,
286
- score_range: scorm12_regex.score_range,
287
- invalidErrorCode: scorm12_error_codes.INVALID_SET_VALUE,
288
- invalidTypeCode: scorm12_error_codes.TYPE_MISMATCH,
289
- invalidRangeCode: scorm12_error_codes.VALUE_OUT_OF_RANGE,
290
- errorClass: Scorm12ValidationError,
291
- });
292
- }
293
-
294
- /**
295
- * Called when the API has been initialized after the CMI has been created
296
- */
297
- initialize() {
298
- super.initialize();
299
- this.score?.initialize();
300
- }
301
-
302
- #_children = scorm12_constants.core_children;
303
- #student_id = '';
304
- #student_name = '';
305
- #lesson_location = '';
306
- #credit = '';
307
- #lesson_status = 'not attempted';
308
- #entry = '';
309
- #total_time = '';
310
- #lesson_mode = 'normal';
311
- #exit = '';
312
- #session_time = '00:00:00';
313
- #suspend_data = '';
314
-
315
- /**
316
- * Getter for #_children
317
- * @return {string}
318
- * @private
319
- */
320
- get _children() {
321
- return this.#_children;
322
- }
323
-
324
- /**
325
- * Setter for #_children. Just throws an error.
326
- * @param {string} _children
327
- * @private
328
- */
329
- set _children(_children) {
330
- throwInvalidValueError();
331
- }
332
-
333
- /**
334
- * Getter for #student_id
335
- * @return {string}
336
- */
337
- get student_id() {
338
- return this.#student_id;
339
- }
340
-
341
- /**
342
- * Setter for #student_id. Can only be called before initialization.
343
- * @param {string} student_id
344
- */
345
- set student_id(student_id) {
346
- !this.initialized ? this.#student_id = student_id : throwReadOnlyError();
347
- }
348
-
349
- /**
350
- * Getter for #student_name
351
- * @return {string}
352
- */
353
- get student_name() {
354
- return this.#student_name;
355
- }
356
-
357
- /**
358
- * Setter for #student_name. Can only be called before initialization.
359
- * @param {string} student_name
360
- */
361
- set student_name(student_name) {
362
- !this.initialized ?
363
- this.#student_name = student_name :
364
- throwReadOnlyError();
365
- }
366
-
367
- /**
368
- * Getter for #lesson_location
369
- * @return {string}
370
- */
371
- get lesson_location() {
372
- return this.#lesson_location;
373
- }
374
-
375
- /**
376
- * Setter for #lesson_location
377
- * @param {string} lesson_location
378
- */
379
- set lesson_location(lesson_location) {
380
- if (check12ValidFormat(lesson_location, scorm12_regex.CMIString256, true)) {
381
- this.#lesson_location = lesson_location;
382
- }
383
- }
384
-
385
- /**
386
- * Getter for #credit
387
- * @return {string}
388
- */
389
- get credit() {
390
- return this.#credit;
391
- }
392
-
393
- /**
394
- * Setter for #credit. Can only be called before initialization.
395
- * @param {string} credit
396
- */
397
- set credit(credit) {
398
- !this.initialized ? this.#credit = credit : throwReadOnlyError();
399
- }
400
-
401
- /**
402
- * Getter for #lesson_status
403
- * @return {string}
404
- */
405
- get lesson_status() {
406
- return this.#lesson_status;
407
- }
408
-
409
- /**
410
- * Setter for #lesson_status
411
- * @param {string} lesson_status
412
- */
413
- set lesson_status(lesson_status) {
414
- if (this.initialized) {
415
- if (check12ValidFormat(lesson_status, scorm12_regex.CMIStatus)) {
416
- this.#lesson_status = lesson_status;
417
- }
418
- } else {
419
- if (check12ValidFormat(lesson_status, scorm12_regex.CMIStatus2)) {
420
- this.#lesson_status = lesson_status;
421
- }
422
- }
423
- }
424
-
425
- /**
426
- * Getter for #entry
427
- * @return {string}
428
- */
429
- get entry() {
430
- return this.#entry;
431
- }
432
-
433
- /**
434
- * Setter for #entry. Can only be called before initialization.
435
- * @param {string} entry
436
- */
437
- set entry(entry) {
438
- !this.initialized ? this.#entry = entry : throwReadOnlyError();
439
- }
440
-
441
- /**
442
- * Getter for #total_time
443
- * @return {string}
444
- */
445
- get total_time() {
446
- return this.#total_time;
447
- }
448
-
449
- /**
450
- * Setter for #total_time. Can only be called before initialization.
451
- * @param {string} total_time
452
- */
453
- set total_time(total_time) {
454
- !this.initialized ? this.#total_time = total_time : throwReadOnlyError();
455
- }
456
-
457
- /**
458
- * Getter for #lesson_mode
459
- * @return {string}
460
- */
461
- get lesson_mode() {
462
- return this.#lesson_mode;
463
- }
464
-
465
- /**
466
- * Setter for #lesson_mode. Can only be called before initialization.
467
- * @param {string} lesson_mode
468
- */
469
- set lesson_mode(lesson_mode) {
470
- !this.initialized ? this.#lesson_mode = lesson_mode : throwReadOnlyError();
471
- }
472
-
473
- /**
474
- * Getter for #exit. Should only be called during JSON export.
475
- * @return {*}
476
- */
477
- get exit() {
478
- return (!this.jsonString) ? throwWriteOnlyError() : this.#exit;
479
- }
480
-
481
- /**
482
- * Setter for #exit
483
- * @param {string} exit
484
- */
485
- set exit(exit) {
486
- if (check12ValidFormat(exit, scorm12_regex.CMIExit, true)) {
487
- this.#exit = exit;
488
- }
489
- }
490
-
491
- /**
492
- * Getter for #session_time. Should only be called during JSON export.
493
- * @return {*}
494
- */
495
- get session_time() {
496
- return (!this.jsonString) ? throwWriteOnlyError() : this.#session_time;
497
- }
498
-
499
- /**
500
- * Setter for #session_time
501
- * @param {string} session_time
502
- */
503
- set session_time(session_time) {
504
- if (check12ValidFormat(session_time, scorm12_regex.CMITimespan)) {
505
- this.#session_time = session_time;
506
- }
507
- }
508
-
509
- /**
510
- * Getter for #suspend_data
511
- * @return {string}
512
- */
513
- get suspend_data() {
514
- return this.#suspend_data;
515
- }
516
-
517
- /**
518
- * Setter for #suspend_data
519
- * @param {string} suspend_data
520
- */
521
- set suspend_data(suspend_data) {
522
- if (check12ValidFormat(suspend_data, scorm12_regex.CMIString4096, true)) {
523
- this.#suspend_data = suspend_data;
524
- }
525
- }
526
-
527
- /**
528
- * Adds the current session time to the existing total time.
529
- * @param {Number} start_time
530
- * @return {string}
531
- */
532
- getCurrentTotalTime(start_time: Number) {
533
- let sessionTime = this.#session_time;
534
- const startTime = start_time;
535
-
536
- if (typeof startTime !== 'undefined' && startTime !== null) {
537
- const seconds = new Date().getTime() - startTime;
538
- sessionTime = Util.getSecondsAsHHMMSS(seconds / 1000);
539
- }
540
-
541
- return Utilities.addHHMMSSTimeStrings(
542
- this.#total_time,
543
- sessionTime,
544
- new RegExp(scorm12_regex.CMITimespan),
545
- );
546
- }
547
-
548
- /**
549
- * toJSON for cmi.core
550
- *
551
- * @return {
552
- * {
553
- * student_name: string,
554
- * entry: string,
555
- * exit: string,
556
- * score: CMIScore,
557
- * student_id: string,
558
- * lesson_mode: string,
559
- * lesson_location: string,
560
- * lesson_status: string,
561
- * credit: string,
562
- * session_time: *
563
- * }
564
- * }
565
- */
566
- toJSON() {
567
- this.jsonString = true;
568
- const result = {
569
- 'student_id': this.student_id,
570
- 'student_name': this.student_name,
571
- 'lesson_location': this.lesson_location,
572
- 'credit': this.credit,
573
- 'lesson_status': this.lesson_status,
574
- 'entry': this.entry,
575
- 'lesson_mode': this.lesson_mode,
576
- 'exit': this.exit,
577
- 'session_time': this.session_time,
578
- 'score': this.score,
579
- };
580
- delete this.jsonString;
581
- return result;
582
- }
583
- }
584
-
585
- /**
586
- * Class representing SCORM 1.2's cmi.objectives object
587
- * @extends CMIArray
588
- */
589
- class CMIObjectives extends CMIArray {
590
- /**
591
- * Constructor for cmi.objectives
592
- */
593
- constructor() {
594
- super({
595
- children: scorm12_constants.objectives_children,
596
- errorCode: scorm12_error_codes.INVALID_SET_VALUE,
597
- errorClass: Scorm12ValidationError,
598
- });
599
- }
600
- }
601
-
602
- /**
603
- * Class representing SCORM 1.2's cmi.student_data object
604
- * @extends BaseCMI
605
- */
606
- export class CMIStudentData extends BaseCMI {
607
- #_children;
608
- #mastery_score = '';
609
- #max_time_allowed = '';
610
- #time_limit_action = '';
611
-
612
- /**
613
- * Constructor for cmi.student_data
614
- * @param {string} student_data_children
615
- */
616
- constructor(student_data_children) {
617
- super();
618
-
619
- this.#_children = student_data_children ?
620
- student_data_children :
621
- scorm12_constants.student_data_children;
622
- }
623
-
624
- /**
625
- * Getter for #_children
626
- * @return {*}
627
- * @private
628
- */
629
- get _children() {
630
- return this.#_children;
631
- }
632
-
633
- /**
634
- * Setter for #_children. Just throws an error.
635
- * @param {string} _children
636
- * @private
637
- */
638
- set _children(_children) {
639
- throwInvalidValueError();
640
- }
641
-
642
- /**
643
- * Getter for #master_score
644
- * @return {string}
645
- */
646
- get mastery_score() {
647
- return this.#mastery_score;
648
- }
649
-
650
- /**
651
- * Setter for #master_score. Can only be called before initialization.
652
- * @param {string} mastery_score
653
- */
654
- set mastery_score(mastery_score) {
655
- !this.initialized ?
656
- this.#mastery_score = mastery_score :
657
- throwReadOnlyError();
658
- }
659
-
660
- /**
661
- * Getter for #max_time_allowed
662
- * @return {string}
663
- */
664
- get max_time_allowed() {
665
- return this.#max_time_allowed;
666
- }
667
-
668
- /**
669
- * Setter for #max_time_allowed. Can only be called before initialization.
670
- * @param {string} max_time_allowed
671
- */
672
- set max_time_allowed(max_time_allowed) {
673
- !this.initialized ?
674
- this.#max_time_allowed = max_time_allowed :
675
- throwReadOnlyError();
676
- }
677
-
678
- /**
679
- * Getter for #time_limit_action
680
- * @return {string}
681
- */
682
- get time_limit_action() {
683
- return this.#time_limit_action;
684
- }
685
-
686
- /**
687
- * Setter for #time_limit_action. Can only be called before initialization.
688
- * @param {string} time_limit_action
689
- */
690
- set time_limit_action(time_limit_action) {
691
- !this.initialized ?
692
- this.#time_limit_action = time_limit_action :
693
- throwReadOnlyError();
694
- }
695
-
696
- /**
697
- * toJSON for cmi.student_data
698
- *
699
- * @return {
700
- * {
701
- * max_time_allowed: string,
702
- * time_limit_action: string,
703
- * mastery_score: string
704
- * }
705
- * }
706
- */
707
- toJSON() {
708
- this.jsonString = true;
709
- const result = {
710
- 'mastery_score': this.mastery_score,
711
- 'max_time_allowed': this.max_time_allowed,
712
- 'time_limit_action': this.time_limit_action,
713
- };
714
- delete this.jsonString;
715
- return result;
716
- }
717
- }
718
-
719
- /**
720
- * Class representing SCORM 1.2's cmi.student_preference object
721
- * @extends BaseCMI
722
- */
723
- export class CMIStudentPreference extends BaseCMI {
724
- #_children;
725
-
726
- /**
727
- * Constructor for cmi.student_preference
728
- * @param {string} student_preference_children
729
- */
730
- constructor(student_preference_children) {
731
- super();
732
-
733
- this.#_children = student_preference_children ?
734
- student_preference_children :
735
- scorm12_constants.student_preference_children;
736
- }
737
-
738
- #audio = '';
739
- #language = '';
740
- #speed = '';
741
- #text = '';
742
-
743
- /**
744
- * Getter for #_children
745
- * @return {string}
746
- * @private
747
- */
748
- get _children() {
749
- return this.#_children;
750
- }
751
-
752
- /**
753
- * Setter for #_children. Just throws an error.
754
- * @param {string} _children
755
- * @private
756
- */
757
- set _children(_children) {
758
- throwInvalidValueError();
759
- }
760
-
761
- /**
762
- * Getter for #audio
763
- * @return {string}
764
- */
765
- get audio() {
766
- return this.#audio;
767
- }
768
-
769
- /**
770
- * Setter for #audio
771
- * @param {string} audio
772
- */
773
- set audio(audio) {
774
- if (check12ValidFormat(audio, scorm12_regex.CMISInteger) &&
775
- check12ValidRange(audio, scorm12_regex.audio_range)) {
776
- this.#audio = audio;
777
- }
778
- }
779
-
780
- /**
781
- * Getter for #language
782
- * @return {string}
783
- */
784
- get language() {
785
- return this.#language;
786
- }
787
-
788
- /**
789
- * Setter for #language
790
- * @param {string} language
791
- */
792
- set language(language) {
793
- if (check12ValidFormat(language, scorm12_regex.CMIString256)) {
794
- this.#language = language;
795
- }
796
- }
797
-
798
- /**
799
- * Getter for #speed
800
- * @return {string}
801
- */
802
- get speed() {
803
- return this.#speed;
804
- }
805
-
806
- /**
807
- * Setter for #speed
808
- * @param {string} speed
809
- */
810
- set speed(speed) {
811
- if (check12ValidFormat(speed, scorm12_regex.CMISInteger) &&
812
- check12ValidRange(speed, scorm12_regex.speed_range)) {
813
- this.#speed = speed;
814
- }
815
- }
816
-
817
- /**
818
- * Getter for #text
819
- * @return {string}
820
- */
821
- get text() {
822
- return this.#text;
823
- }
824
-
825
- /**
826
- * Setter for #text
827
- * @param {string} text
828
- */
829
- set text(text) {
830
- if (check12ValidFormat(text, scorm12_regex.CMISInteger) &&
831
- check12ValidRange(text, scorm12_regex.text_range)) {
832
- this.#text = text;
833
- }
834
- }
835
-
836
- /**
837
- * toJSON for cmi.student_preference
838
- *
839
- * @return {
840
- * {
841
- * audio: string,
842
- * language: string,
843
- * speed: string,
844
- * text: string
845
- * }
846
- * }
847
- */
848
- toJSON() {
849
- this.jsonString = true;
850
- const result = {
851
- 'audio': this.audio,
852
- 'language': this.language,
853
- 'speed': this.speed,
854
- 'text': this.text,
855
- };
856
- delete this.jsonString;
857
- return result;
858
- }
859
- }
860
-
861
- /**
862
- * Class representing SCORM 1.2's cmi.interactions object
863
- * @extends BaseCMI
864
- */
865
- class CMIInteractions extends CMIArray {
866
- /**
867
- * Constructor for cmi.interactions
868
- */
869
- constructor() {
870
- super({
871
- children: scorm12_constants.interactions_children,
872
- errorCode: scorm12_error_codes.INVALID_SET_VALUE,
873
- errorClass: Scorm12ValidationError,
874
- });
875
- }
876
- }
877
-
878
- /**
879
- * Class representing SCORM 1.2's cmi.interactions.n object
880
- * @extends BaseCMI
881
- */
882
- export class CMIInteractionsObject extends BaseCMI {
883
- /**
884
- * Constructor for cmi.interactions.n object
885
- */
886
- constructor() {
887
- super();
888
-
889
- this.objectives = new CMIArray({
890
- errorCode: scorm12_error_codes.INVALID_SET_VALUE,
891
- errorClass: Scorm12ValidationError,
892
- children: scorm12_constants.objectives_children,
893
- });
894
- this.correct_responses = new CMIArray({
895
- errorCode: scorm12_error_codes.INVALID_SET_VALUE,
896
- errorClass: Scorm12ValidationError,
897
- children: scorm12_constants.correct_responses_children,
898
- });
899
- }
900
-
901
- /**
902
- * Called when the API has been initialized after the CMI has been created
903
- */
904
- initialize() {
905
- super.initialize();
906
- this.objectives?.initialize();
907
- this.correct_responses?.initialize();
908
- }
909
-
910
- #id = '';
911
- #time = '';
912
- #type = '';
913
- #weighting = '';
914
- #student_response = '';
915
- #result = '';
916
- #latency = '';
917
-
918
- /**
919
- * Getter for #id. Should only be called during JSON export.
920
- * @return {*}
921
- */
922
- get id() {
923
- return (!this.jsonString) ? throwWriteOnlyError() : this.#id;
924
- }
925
-
926
- /**
927
- * Setter for #id
928
- * @param {string} id
929
- */
930
- set id(id) {
931
- if (check12ValidFormat(id, scorm12_regex.CMIIdentifier)) {
932
- this.#id = id;
933
- }
934
- }
935
-
936
- /**
937
- * Getter for #time. Should only be called during JSON export.
938
- * @return {*}
939
- */
940
- get time() {
941
- return (!this.jsonString) ? throwWriteOnlyError() : this.#time;
942
- }
943
-
944
- /**
945
- * Setter for #time
946
- * @param {string} time
947
- */
948
- set time(time) {
949
- if (check12ValidFormat(time, scorm12_regex.CMITime)) {
950
- this.#time = time;
951
- }
952
- }
953
-
954
- /**
955
- * Getter for #type. Should only be called during JSON export.
956
- * @return {*}
957
- */
958
- get type() {
959
- return (!this.jsonString) ? throwWriteOnlyError() : this.#type;
960
- }
961
-
962
- /**
963
- * Setter for #type
964
- * @param {string} type
965
- */
966
- set type(type) {
967
- if (check12ValidFormat(type, scorm12_regex.CMIType)) {
968
- this.#type = type;
969
- }
970
- }
971
-
972
- /**
973
- * Getter for #weighting. Should only be called during JSON export.
974
- * @return {*}
975
- */
976
- get weighting() {
977
- return (!this.jsonString) ?
978
- throwWriteOnlyError() :
979
- this.#weighting;
980
- }
981
-
982
- /**
983
- * Setter for #weighting
984
- * @param {string} weighting
985
- */
986
- set weighting(weighting) {
987
- if (check12ValidFormat(weighting, scorm12_regex.CMIDecimal) &&
988
- check12ValidRange(weighting, scorm12_regex.weighting_range)) {
989
- this.#weighting = weighting;
990
- }
991
- }
992
-
993
- /**
994
- * Getter for #student_response. Should only be called during JSON export.
995
- * @return {*}
996
- */
997
- get student_response() {
998
- return (!this.jsonString) ? throwWriteOnlyError() : this.#student_response;
999
- }
1000
-
1001
- /**
1002
- * Setter for #student_response
1003
- * @param {string} student_response
1004
- */
1005
- set student_response(student_response) {
1006
- if (check12ValidFormat(student_response, scorm12_regex.CMIFeedback, true)) {
1007
- this.#student_response = student_response;
1008
- }
1009
- }
1010
-
1011
- /**
1012
- * Getter for #result. Should only be called during JSON export.
1013
- * @return {*}
1014
- */
1015
- get result() {
1016
- return (!this.jsonString) ? throwWriteOnlyError() : this.#result;
1017
- }
1018
-
1019
- /**
1020
- * Setter for #result
1021
- * @param {string} result
1022
- */
1023
- set result(result) {
1024
- if (check12ValidFormat(result, scorm12_regex.CMIResult)) {
1025
- this.#result = result;
1026
- }
1027
- }
1028
-
1029
- /**
1030
- * Getter for #latency. Should only be called during JSON export.
1031
- * @return {*}
1032
- */
1033
- get latency() {
1034
- return (!this.jsonString) ? throwWriteOnlyError() : this.#latency;
1035
- }
1036
-
1037
- /**
1038
- * Setter for #latency
1039
- * @param {string} latency
1040
- */
1041
- set latency(latency) {
1042
- if (check12ValidFormat(latency, scorm12_regex.CMITimespan)) {
1043
- this.#latency = latency;
1044
- }
1045
- }
1046
-
1047
- /**
1048
- * toJSON for cmi.interactions.n
1049
- *
1050
- * @return {
1051
- * {
1052
- * id: string,
1053
- * time: string,
1054
- * type: string,
1055
- * weighting: string,
1056
- * student_response: string,
1057
- * result: string,
1058
- * latency: string,
1059
- * objectives: CMIArray,
1060
- * correct_responses: CMIArray
1061
- * }
1062
- * }
1063
- */
1064
- toJSON() {
1065
- this.jsonString = true;
1066
- const result = {
1067
- 'id': this.id,
1068
- 'time': this.time,
1069
- 'type': this.type,
1070
- 'weighting': this.weighting,
1071
- 'student_response': this.student_response,
1072
- 'result': this.result,
1073
- 'latency': this.latency,
1074
- 'objectives': this.objectives,
1075
- 'correct_responses': this.correct_responses,
1076
- };
1077
- delete this.jsonString;
1078
- return result;
1079
- }
1080
- }
1081
-
1082
- /**
1083
- * Class representing SCORM 1.2's cmi.objectives.n object
1084
- * @extends BaseCMI
1085
- */
1086
- export class CMIObjectivesObject extends BaseCMI {
1087
- /**
1088
- * Constructor for cmi.objectives.n
1089
- */
1090
- constructor() {
1091
- super();
1092
-
1093
- this.score = new CMIScore(
1094
- {
1095
- score_children: scorm12_constants.score_children,
1096
- score_range: scorm12_regex.score_range,
1097
- invalidErrorCode: scorm12_error_codes.INVALID_SET_VALUE,
1098
- invalidTypeCode: scorm12_error_codes.TYPE_MISMATCH,
1099
- invalidRangeCode: scorm12_error_codes.VALUE_OUT_OF_RANGE,
1100
- errorClass: Scorm12ValidationError,
1101
- });
1102
- }
1103
-
1104
- #id = '';
1105
- #status = '';
1106
-
1107
- /**
1108
- * Getter for #id
1109
- * @return {""}
1110
- */
1111
- get id() {
1112
- return this.#id;
1113
- }
1114
-
1115
- /**
1116
- * Setter for #id
1117
- * @param {string} id
1118
- */
1119
- set id(id) {
1120
- if (check12ValidFormat(id, scorm12_regex.CMIIdentifier)) {
1121
- this.#id = id;
1122
- }
1123
- }
1124
-
1125
- /**
1126
- * Getter for #status
1127
- * @return {""}
1128
- */
1129
- get status() {
1130
- return this.#status;
1131
- }
1132
-
1133
- /**
1134
- * Setter for #status
1135
- * @param {string} status
1136
- */
1137
- set status(status) {
1138
- if (check12ValidFormat(status, scorm12_regex.CMIStatus2)) {
1139
- this.#status = status;
1140
- }
1141
- }
1142
-
1143
- /**
1144
- * toJSON for cmi.objectives.n
1145
- * @return {
1146
- * {
1147
- * id: string,
1148
- * status: string,
1149
- * score: CMIScore
1150
- * }
1151
- * }
1152
- */
1153
- toJSON() {
1154
- this.jsonString = true;
1155
- const result = {
1156
- 'id': this.id,
1157
- 'status': this.status,
1158
- 'score': this.score,
1159
- };
1160
- delete this.jsonString;
1161
- return result;
1162
- }
1163
- }
1164
-
1165
- /**
1166
- * Class representing SCORM 1.2's cmi.interactions.n.objectives.n object
1167
- * @extends BaseCMI
1168
- */
1169
- export class CMIInteractionsObjectivesObject extends BaseCMI {
1170
- /**
1171
- * Constructor for cmi.interactions.n.objectives.n
1172
- */
1173
- constructor() {
1174
- super();
1175
- }
1176
-
1177
- #id = '';
1178
-
1179
- /**
1180
- * Getter for #id
1181
- * @return {""}
1182
- */
1183
- get id() {
1184
- return this.#id;
1185
- }
1186
-
1187
- /**
1188
- * Setter for #id
1189
- * @param {string} id
1190
- */
1191
- set id(id) {
1192
- if (check12ValidFormat(id, scorm12_regex.CMIIdentifier)) {
1193
- this.#id = id;
1194
- }
1195
- }
1196
-
1197
- /**
1198
- * toJSON for cmi.interactions.n.objectives.n
1199
- * @return {
1200
- * {
1201
- * id: string
1202
- * }
1203
- * }
1204
- */
1205
- toJSON() {
1206
- this.jsonString = true;
1207
- const result = {
1208
- 'id': this.id,
1209
- };
1210
- delete this.jsonString;
1211
- return result;
1212
- }
1213
- }
1214
-
1215
- /**
1216
- * Class representing SCORM 1.2's cmi.interactions.correct_responses.n object
1217
- * @extends BaseCMI
1218
- */
1219
- export class CMIInteractionsCorrectResponsesObject extends BaseCMI {
1220
- /**
1221
- * Constructor for cmi.interactions.correct_responses.n
1222
- */
1223
- constructor() {
1224
- super();
1225
- }
1226
-
1227
- #pattern = '';
1228
-
1229
- /**
1230
- * Getter for #pattern
1231
- * @return {string}
1232
- */
1233
- get pattern() {
1234
- return (!this.jsonString) ? throwWriteOnlyError() : this.#pattern;
1235
- }
1236
-
1237
- /**
1238
- * Setter for #pattern
1239
- * @param {string} pattern
1240
- */
1241
- set pattern(pattern) {
1242
- if (check12ValidFormat(pattern, scorm12_regex.CMIFeedback, true)) {
1243
- this.#pattern = pattern;
1244
- }
1245
- }
1246
-
1247
- /**
1248
- * toJSON for cmi.interactions.correct_responses.n
1249
- * @return {
1250
- * {
1251
- * pattern: string
1252
- * }
1253
- * }
1254
- */
1255
- toJSON() {
1256
- this.jsonString = true;
1257
- const result = {
1258
- 'pattern': this.pattern,
1259
- };
1260
- delete this.jsonString;
1261
- return result;
1262
- }
1263
- }
1264
-
1265
- /**
1266
- * Class for AICC Navigation object
1267
- */
1268
- export class NAV extends BaseCMI {
1269
- /**
1270
- * Constructor for NAV object
1271
- */
1272
- constructor() {
1273
- super();
1274
- }
1275
-
1276
- #event = '';
1277
-
1278
- /**
1279
- * Getter for #event
1280
- * @return {string}
1281
- */
1282
- get event() {
1283
- return this.#event;
1284
- }
1285
-
1286
- /**
1287
- * Setter for #event
1288
- * @param {string} event
1289
- */
1290
- set event(event) {
1291
- if (check12ValidFormat(event, scorm12_regex.NAVEvent)) {
1292
- this.#event = event;
1293
- }
1294
- }
1295
-
1296
- /**
1297
- * toJSON for nav object
1298
- * @return {
1299
- * {
1300
- * event: string
1301
- * }
1302
- * }
1303
- */
1304
- toJSON() {
1305
- this.jsonString = true;
1306
- const result = {
1307
- 'event': this.event,
1308
- };
1309
- delete this.jsonString;
1310
- return result;
1311
- }
1312
- }