scorm-again 2.0.0 → 2.1.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 (77) hide show
  1. package/.github/workflows/stale.yml +14 -0
  2. package/.run/{Mocha Unit Tests.run.xml → Mocha Unit Tests (watch).run.xml } +1 -1
  3. package/.run/Template Mocha.run.xml +17 -0
  4. package/README.md +171 -72
  5. package/dist/aicc.js +1441 -1140
  6. package/dist/aicc.js.map +1 -1
  7. package/dist/aicc.min.js +1 -1
  8. package/dist/aicc.min.js.map +1 -1
  9. package/dist/scorm-again.js +2703 -2212
  10. package/dist/scorm-again.js.map +1 -1
  11. package/dist/scorm-again.min.js +1 -1
  12. package/dist/scorm-again.min.js.map +1 -1
  13. package/dist/scorm12.js +1069 -852
  14. package/dist/scorm12.js.map +1 -1
  15. package/dist/scorm12.min.js +1 -1
  16. package/dist/scorm12.min.js.map +1 -1
  17. package/dist/scorm2004.js +1861 -1571
  18. package/dist/scorm2004.js.map +1 -1
  19. package/dist/scorm2004.min.js +1 -1
  20. package/dist/scorm2004.min.js.map +1 -1
  21. package/package.json +10 -6
  22. package/src/AICC.ts +15 -17
  23. package/src/BaseAPI.ts +268 -417
  24. package/src/Scorm12API.ts +65 -38
  25. package/src/Scorm2004API.ts +151 -117
  26. package/src/cmi/aicc/attempts.ts +94 -0
  27. package/src/cmi/aicc/cmi.ts +100 -0
  28. package/src/cmi/aicc/core.ts +360 -0
  29. package/src/cmi/aicc/evaluation.ts +157 -0
  30. package/src/cmi/aicc/paths.ts +180 -0
  31. package/src/cmi/aicc/student_data.ts +86 -0
  32. package/src/cmi/aicc/student_demographics.ts +367 -0
  33. package/src/cmi/aicc/student_preferences.ts +176 -0
  34. package/src/cmi/aicc/tries.ts +116 -0
  35. package/src/cmi/aicc/validation.ts +25 -0
  36. package/src/cmi/common/array.ts +77 -0
  37. package/src/cmi/common/base_cmi.ts +46 -0
  38. package/src/cmi/common/score.ts +203 -0
  39. package/src/cmi/common/validation.ts +60 -0
  40. package/src/cmi/scorm12/cmi.ts +224 -0
  41. package/src/cmi/scorm12/interactions.ts +368 -0
  42. package/src/cmi/scorm12/nav.ts +54 -0
  43. package/src/cmi/scorm12/objectives.ts +112 -0
  44. package/src/cmi/scorm12/student_data.ts +130 -0
  45. package/src/cmi/scorm12/student_preference.ts +158 -0
  46. package/src/cmi/scorm12/validation.ts +48 -0
  47. package/src/cmi/scorm2004/adl.ts +272 -0
  48. package/src/cmi/scorm2004/cmi.ts +599 -0
  49. package/src/cmi/scorm2004/comments.ts +163 -0
  50. package/src/cmi/scorm2004/interactions.ts +466 -0
  51. package/src/cmi/scorm2004/learner_preference.ts +152 -0
  52. package/src/cmi/scorm2004/objectives.ts +212 -0
  53. package/src/cmi/scorm2004/score.ts +78 -0
  54. package/src/cmi/scorm2004/validation.ts +42 -0
  55. package/src/constants/default_settings.ts +81 -0
  56. package/src/constants/enums.ts +5 -0
  57. package/src/constants/regex.ts +2 -2
  58. package/src/constants/response_constants.ts +2 -0
  59. package/src/exceptions.ts +22 -1
  60. package/src/helpers/scheduled_commit.ts +42 -0
  61. package/src/interfaces/IBaseAPI.ts +35 -0
  62. package/src/types/api_types.ts +32 -0
  63. package/src/utilities/debounce.ts +31 -0
  64. package/src/utilities.ts +56 -0
  65. package/test/AICC.spec.ts +11 -1
  66. package/test/Scorm12API.spec.ts +262 -9
  67. package/test/Scorm2004API.spec.ts +488 -2
  68. package/test/cmi/aicc_cmi.spec.ts +188 -11
  69. package/test/cmi/scorm12_cmi.spec.ts +5 -5
  70. package/test/cmi/scorm2004_cmi.spec.ts +8 -8
  71. package/test/cmi_helpers.ts +1 -1
  72. package/test/types/api_types.spec.ts +126 -0
  73. package/test/utilities/debounce.spec.ts +56 -0
  74. package/src/cmi/aicc_cmi.ts +0 -1248
  75. package/src/cmi/common.ts +0 -411
  76. package/src/cmi/scorm12_cmi.ts +0 -1426
  77. package/src/cmi/scorm2004_cmi.ts +0 -1874
@@ -0,0 +1,112 @@
1
+ import {BaseCMI} from "../common/base_cmi";
2
+ import {CMIScore} from "../common/score";
3
+ import APIConstants from "../../constants/api_constants";
4
+ import Regex from "../../constants/regex";
5
+ import ErrorCodes from "../../constants/error_codes";
6
+ import {Scorm12ValidationError} from "../../exceptions";
7
+ import {check12ValidFormat} from "./validation";
8
+ import {CMIArray} from "../common/array";
9
+
10
+ /**
11
+ * Class representing SCORM 1.2's `cmi.objectives` object
12
+ * @extends CMIArray
13
+ */
14
+ export class CMIObjectives extends CMIArray {
15
+ /**
16
+ * Constructor for `cmi.objectives`
17
+ */
18
+ constructor() {
19
+ super({
20
+ children: APIConstants.scorm12.objectives_children,
21
+ errorCode: ErrorCodes.scorm12.INVALID_SET_VALUE,
22
+ errorClass: Scorm12ValidationError,
23
+ });
24
+ }
25
+ }
26
+
27
+ /**
28
+ * Class representing SCORM 1.2's cmi.objectives.n object
29
+ * @extends BaseCMI
30
+ */
31
+ export class CMIObjectivesObject extends BaseCMI {
32
+ /**
33
+ * Constructor for cmi.objectives.n
34
+ */
35
+ constructor() {
36
+ super();
37
+ this.score = new CMIScore({
38
+ score_children: APIConstants.scorm12.score_children,
39
+ score_range: Regex.scorm12.score_range,
40
+ invalidErrorCode: ErrorCodes.scorm12.INVALID_SET_VALUE,
41
+ invalidTypeCode: ErrorCodes.scorm12.TYPE_MISMATCH,
42
+ invalidRangeCode: ErrorCodes.scorm12.VALUE_OUT_OF_RANGE,
43
+ errorClass: Scorm12ValidationError,
44
+ });
45
+ }
46
+
47
+ public readonly score: CMIScore;
48
+
49
+ private _id = "";
50
+ private _status = "";
51
+
52
+ /**
53
+ * Getter for _id
54
+ * @return {string}
55
+ */
56
+ get id(): string {
57
+ return this._id;
58
+ }
59
+
60
+ /**
61
+ * Setter for _id
62
+ * @param {string} id
63
+ */
64
+ set id(id: string) {
65
+ if (check12ValidFormat(id, Regex.scorm12.CMIIdentifier)) {
66
+ this._id = id;
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Getter for _status
72
+ * @return {string}
73
+ */
74
+ get status(): string {
75
+ return this._status;
76
+ }
77
+
78
+ /**
79
+ * Setter for _status
80
+ * @param {string} status
81
+ */
82
+ set status(status: string) {
83
+ if (check12ValidFormat(status, Regex.scorm12.CMIStatus2)) {
84
+ this._status = status;
85
+ }
86
+ }
87
+
88
+ /**
89
+ * toJSON for cmi.objectives.n
90
+ * @return {
91
+ * {
92
+ * id: string,
93
+ * status: string,
94
+ * score: CMIScore
95
+ * }
96
+ * }
97
+ */
98
+ toJSON(): {
99
+ id: string;
100
+ status: string;
101
+ score: CMIScore;
102
+ } {
103
+ this.jsonString = true;
104
+ const result = {
105
+ id: this.id,
106
+ status: this.status,
107
+ score: this.score,
108
+ };
109
+ delete this.jsonString;
110
+ return result;
111
+ }
112
+ }
@@ -0,0 +1,130 @@
1
+ import { BaseCMI } from "../common/base_cmi";
2
+ import APIConstants from "../../constants/api_constants";
3
+ import { Scorm12ValidationError } from "../../exceptions";
4
+ import ErrorCodes from "../../constants/error_codes";
5
+
6
+ /**
7
+ * Class representing the SCORM 1.2 cmi.student_data object
8
+ * @extends BaseCMI
9
+ */
10
+ export class CMIStudentData extends BaseCMI {
11
+ private readonly __children;
12
+ private _mastery_score = "";
13
+ private _max_time_allowed = "";
14
+ private _time_limit_action = "";
15
+
16
+ /**
17
+ * Constructor for cmi.student_data
18
+ * @param {string} student_data_children
19
+ */
20
+ constructor(student_data_children?: string) {
21
+ super();
22
+ this.__children = student_data_children
23
+ ? student_data_children
24
+ : APIConstants.scorm12.student_data_children;
25
+ }
26
+
27
+ /**
28
+ * Getter for __children
29
+ * @return {string}
30
+ * @private
31
+ */
32
+ get _children(): string {
33
+ return this.__children;
34
+ }
35
+
36
+ /**
37
+ * Setter for __children. Just throws an error.
38
+ * @param {string} _children
39
+ * @private
40
+ */
41
+ set _children(_children: string) {
42
+ throw new Scorm12ValidationError(ErrorCodes.scorm12.INVALID_SET_VALUE);
43
+ }
44
+
45
+ /**
46
+ * Getter for _master_score
47
+ * @return {string}
48
+ */
49
+ get mastery_score(): string {
50
+ return this._mastery_score;
51
+ }
52
+
53
+ /**
54
+ * Setter for _master_score. Can only be called before initialization.
55
+ * @param {string} mastery_score
56
+ */
57
+ set mastery_score(mastery_score: string) {
58
+ if (this.initialized) {
59
+ throw new Scorm12ValidationError(ErrorCodes.scorm12.READ_ONLY_ELEMENT);
60
+ } else {
61
+ this._mastery_score = mastery_score;
62
+ }
63
+ }
64
+
65
+ /**
66
+ * Getter for _max_time_allowed
67
+ * @return {string}
68
+ */
69
+ get max_time_allowed(): string {
70
+ return this._max_time_allowed;
71
+ }
72
+
73
+ /**
74
+ * Setter for _max_time_allowed. Can only be called before initialization.
75
+ * @param {string} max_time_allowed
76
+ */
77
+ set max_time_allowed(max_time_allowed: string) {
78
+ if (this.initialized) {
79
+ throw new Scorm12ValidationError(ErrorCodes.scorm12.READ_ONLY_ELEMENT);
80
+ } else {
81
+ this._max_time_allowed = max_time_allowed;
82
+ }
83
+ }
84
+
85
+ /**
86
+ * Getter for _time_limit_action
87
+ * @return {string}
88
+ */
89
+ get time_limit_action(): string {
90
+ return this._time_limit_action;
91
+ }
92
+
93
+ /**
94
+ * Setter for _time_limit_action. Can only be called before initialization.
95
+ * @param {string} time_limit_action
96
+ */
97
+ set time_limit_action(time_limit_action: string) {
98
+ if (this.initialized) {
99
+ throw new Scorm12ValidationError(ErrorCodes.scorm12.READ_ONLY_ELEMENT);
100
+ } else {
101
+ this._time_limit_action = time_limit_action;
102
+ }
103
+ }
104
+
105
+ /**
106
+ * toJSON for cmi.student_data
107
+ *
108
+ * @return {
109
+ * {
110
+ * max_time_allowed: string,
111
+ * time_limit_action: string,
112
+ * mastery_score: string
113
+ * }
114
+ * }
115
+ */
116
+ toJSON(): {
117
+ mastery_score: string;
118
+ max_time_allowed: string;
119
+ time_limit_action: string;
120
+ } {
121
+ this.jsonString = true;
122
+ const result = {
123
+ mastery_score: this.mastery_score,
124
+ max_time_allowed: this.max_time_allowed,
125
+ time_limit_action: this.time_limit_action,
126
+ };
127
+ delete this.jsonString;
128
+ return result;
129
+ }
130
+ }
@@ -0,0 +1,158 @@
1
+ import { BaseCMI } from "../common/base_cmi";
2
+ import APIConstants from "../../constants/api_constants";
3
+ import { Scorm12ValidationError } from "../../exceptions";
4
+ import ErrorCodes from "../../constants/error_codes";
5
+ import { check12ValidFormat, check12ValidRange } from "./validation";
6
+ import Regex from "../../constants/regex";
7
+
8
+ /**
9
+ * Class representing the SCORM 1.2 cmi.student_preference object
10
+ * @extends BaseCMI
11
+ */
12
+ export class CMIStudentPreference extends BaseCMI {
13
+ private readonly __children;
14
+
15
+ /**
16
+ * Constructor for cmi.student_preference
17
+ * @param {string} student_preference_children
18
+ */
19
+ constructor(student_preference_children?: string) {
20
+ super();
21
+ this.__children = student_preference_children
22
+ ? student_preference_children
23
+ : APIConstants.scorm12.student_preference_children;
24
+ }
25
+
26
+ private _audio = "";
27
+ private _language = "";
28
+ private _speed = "";
29
+ private _text = "";
30
+
31
+ /**
32
+ * Getter for __children
33
+ * @return {string}
34
+ * @private
35
+ */
36
+ get _children(): string {
37
+ return this.__children;
38
+ }
39
+
40
+ /**
41
+ * Setter for __children. Just throws an error.
42
+ * @param {string} _children
43
+ * @private
44
+ */
45
+ set _children(_children: string) {
46
+ throw new Scorm12ValidationError(ErrorCodes.scorm12.INVALID_SET_VALUE);
47
+ }
48
+
49
+ /**
50
+ * Getter for _audio
51
+ * @return {string}
52
+ */
53
+ get audio(): string {
54
+ return this._audio;
55
+ }
56
+
57
+ /**
58
+ * Setter for _audio
59
+ * @param {string} audio
60
+ */
61
+ set audio(audio: string) {
62
+ if (
63
+ check12ValidFormat(audio, Regex.scorm12.CMISInteger) &&
64
+ check12ValidRange(audio, Regex.scorm12.audio_range)
65
+ ) {
66
+ this._audio = audio;
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Getter for _language
72
+ * @return {string}
73
+ */
74
+ get language(): string {
75
+ return this._language;
76
+ }
77
+
78
+ /**
79
+ * Setter for _language
80
+ * @param {string} language
81
+ */
82
+ set language(language: string) {
83
+ if (check12ValidFormat(language, Regex.scorm12.CMIString256)) {
84
+ this._language = language;
85
+ }
86
+ }
87
+
88
+ /**
89
+ * Getter for _speed
90
+ * @return {string}
91
+ */
92
+ get speed(): string {
93
+ return this._speed;
94
+ }
95
+
96
+ /**
97
+ * Setter for _speed
98
+ * @param {string} speed
99
+ */
100
+ set speed(speed: string) {
101
+ if (
102
+ check12ValidFormat(speed, Regex.scorm12.CMISInteger) &&
103
+ check12ValidRange(speed, Regex.scorm12.speed_range)
104
+ ) {
105
+ this._speed = speed;
106
+ }
107
+ }
108
+
109
+ /**
110
+ * Getter for _text
111
+ * @return {string}
112
+ */
113
+ get text(): string {
114
+ return this._text;
115
+ }
116
+
117
+ /**
118
+ * Setter for _text
119
+ * @param {string} text
120
+ */
121
+ set text(text: string) {
122
+ if (
123
+ check12ValidFormat(text, Regex.scorm12.CMISInteger) &&
124
+ check12ValidRange(text, Regex.scorm12.text_range)
125
+ ) {
126
+ this._text = text;
127
+ }
128
+ }
129
+
130
+ /**
131
+ * toJSON for cmi.student_preference
132
+ *
133
+ * @return {
134
+ * {
135
+ * audio: string,
136
+ * language: string,
137
+ * speed: string,
138
+ * text: string
139
+ * }
140
+ * }
141
+ */
142
+ toJSON(): {
143
+ audio: string;
144
+ language: string;
145
+ speed: string;
146
+ text: string;
147
+ } {
148
+ this.jsonString = true;
149
+ const result = {
150
+ audio: this.audio,
151
+ language: this.language,
152
+ speed: this.speed,
153
+ text: this.text,
154
+ };
155
+ delete this.jsonString;
156
+ return result;
157
+ }
158
+ }
@@ -0,0 +1,48 @@
1
+ import {checkValidFormat, checkValidRange} from "../common/validation";
2
+ import ErrorCodes from "../../constants/error_codes";
3
+ import {Scorm12ValidationError} from "../../exceptions";
4
+
5
+ /**
6
+ * Helper method, no reason to have to pass the same error codes every time
7
+ * @param {string} value
8
+ * @param {string} regexPattern
9
+ * @param {boolean} allowEmptyString
10
+ * @return {boolean}
11
+ */
12
+ export function check12ValidFormat(
13
+ value: string,
14
+ regexPattern: string,
15
+ allowEmptyString?: boolean,
16
+ ): boolean {
17
+ return checkValidFormat(
18
+ value,
19
+ regexPattern,
20
+ ErrorCodes.scorm12.TYPE_MISMATCH,
21
+ Scorm12ValidationError,
22
+ allowEmptyString,
23
+ );
24
+ }
25
+
26
+ /**
27
+ * Helper method, no reason to have to pass the same error codes every time
28
+ * @param {string} value
29
+ * @param {string} rangePattern
30
+ * @param {boolean} allowEmptyString
31
+ * @return {boolean}
32
+ */
33
+ export function check12ValidRange(
34
+ value: any,
35
+ rangePattern: string,
36
+ allowEmptyString?: boolean,
37
+ ): boolean {
38
+ if (!allowEmptyString && value === "") {
39
+ throw new Scorm12ValidationError(ErrorCodes.scorm12.VALUE_OUT_OF_RANGE);
40
+ }
41
+
42
+ return checkValidRange(
43
+ value,
44
+ rangePattern,
45
+ ErrorCodes.scorm12.VALUE_OUT_OF_RANGE,
46
+ Scorm12ValidationError,
47
+ );
48
+ }
@@ -0,0 +1,272 @@
1
+ import { BaseCMI } from "../common/base_cmi";
2
+ import { Scorm2004ValidationError } from "../../exceptions";
3
+ import ErrorCodes from "../../constants/error_codes";
4
+ import { check2004ValidFormat } from "./validation";
5
+ import Regex from "../../constants/regex";
6
+ import { NAVBoolean } from "../../constants/enums";
7
+
8
+ /**
9
+ * Class representing SCORM 2004's adl object
10
+ */
11
+ export class ADL extends BaseCMI {
12
+ /**
13
+ * Constructor for adl
14
+ */
15
+ constructor() {
16
+ super();
17
+ this.nav = new ADLNav();
18
+ }
19
+
20
+ public nav: ADLNav;
21
+
22
+ /**
23
+ * Called when the API has been initialized after the CMI has been created
24
+ */
25
+ initialize() {
26
+ super.initialize();
27
+ this.nav?.initialize();
28
+ }
29
+
30
+ /**
31
+ * toJSON for adl
32
+ * @return {
33
+ * {
34
+ * nav: ADLNav
35
+ * }
36
+ * }
37
+ */
38
+ toJSON(): {
39
+ nav: ADLNav;
40
+ } {
41
+ this.jsonString = true;
42
+ const result = {
43
+ nav: this.nav,
44
+ };
45
+ delete this.jsonString;
46
+ return result;
47
+ }
48
+ }
49
+
50
+ /**
51
+ * Class representing SCORM 2004's `adl.nav` object
52
+ */
53
+
54
+ export class ADLNav extends BaseCMI {
55
+ private _request = "_none_";
56
+
57
+ /**
58
+ * Constructor for `adl.nav`
59
+ */
60
+ constructor() {
61
+ super();
62
+ this.request_valid = new ADLNavRequestValid();
63
+ }
64
+
65
+ public request_valid: ADLNavRequestValid;
66
+
67
+ /**
68
+ * Called when the API has been initialized after the CMI has been created
69
+ */
70
+ initialize() {
71
+ super.initialize();
72
+ this.request_valid?.initialize();
73
+ }
74
+
75
+ /**
76
+ * Getter for _request
77
+ * @return {string}
78
+ */
79
+ get request(): string {
80
+ return this._request;
81
+ }
82
+
83
+ /**
84
+ * Setter for _request
85
+ * @param {string} request
86
+ */
87
+ set request(request: string) {
88
+ if (check2004ValidFormat(request, Regex.scorm2004.NAVEvent)) {
89
+ this._request = request;
90
+ }
91
+ }
92
+
93
+ /**
94
+ * toJSON for adl.nav
95
+ *
96
+ * @return {
97
+ * {
98
+ * request: string
99
+ * }
100
+ * }
101
+ */
102
+ toJSON(): {
103
+ request: string;
104
+ } {
105
+ this.jsonString = true;
106
+ const result = {
107
+ request: this.request,
108
+ };
109
+ delete this.jsonString;
110
+ return result;
111
+ }
112
+ }
113
+
114
+ /**
115
+ * Class representing SCORM 2004's adl.nav.request_valid object
116
+ */
117
+
118
+ export class ADLNavRequestValid extends BaseCMI {
119
+ private _continue = "unknown";
120
+ private _previous = "unknown";
121
+ private _choice: {
122
+ [key: string]: NAVBoolean;
123
+ } = {};
124
+ private _jump: {
125
+ [key: string]: NAVBoolean;
126
+ } = {};
127
+
128
+ /**
129
+ * Constructor for adl.nav.request_valid
130
+ */
131
+ constructor() {
132
+ super();
133
+ }
134
+
135
+ /**
136
+ * Getter for _continue
137
+ * @return {string}
138
+ */
139
+ get continue(): string {
140
+ return this._continue;
141
+ }
142
+
143
+ /**
144
+ * Setter for _continue. Just throws an error.
145
+ * @param {string} _continue
146
+ */
147
+ set continue(_continue: string) {
148
+ if (this.initialized) {
149
+ throw new Scorm2004ValidationError(
150
+ ErrorCodes.scorm2004.READ_ONLY_ELEMENT,
151
+ );
152
+ }
153
+ if (check2004ValidFormat(_continue, Regex.scorm2004.NAVBoolean)) {
154
+ this._continue = _continue;
155
+ }
156
+ }
157
+
158
+ /**
159
+ * Getter for _previous
160
+ * @return {string}
161
+ */
162
+ get previous(): string {
163
+ return this._previous;
164
+ }
165
+
166
+ /**
167
+ * Setter for _previous. Just throws an error.
168
+ * @param {string} _previous
169
+ */
170
+ set previous(_previous: string) {
171
+ if (this.initialized) {
172
+ throw new Scorm2004ValidationError(
173
+ ErrorCodes.scorm2004.READ_ONLY_ELEMENT,
174
+ );
175
+ }
176
+ if (check2004ValidFormat(_previous, Regex.scorm2004.NAVBoolean)) {
177
+ this._previous = _previous;
178
+ }
179
+ }
180
+
181
+ /**
182
+ * Getter for _choice
183
+ * @return {{ [key: string]: NAVBoolean }}
184
+ */
185
+ get choice(): { [key: string]: NAVBoolean } {
186
+ return this._choice;
187
+ }
188
+
189
+ /**
190
+ * Setter for _choice
191
+ * @param {{ [key: string]: string }} choice
192
+ */
193
+ set choice(choice: { [key: string]: string }) {
194
+ if (this.initialized) {
195
+ throw new Scorm2004ValidationError(
196
+ ErrorCodes.scorm2004.READ_ONLY_ELEMENT,
197
+ );
198
+ }
199
+ if (typeof choice !== "object") {
200
+ throw new Scorm2004ValidationError(ErrorCodes.scorm2004.TYPE_MISMATCH);
201
+ }
202
+ for (const key in choice) {
203
+ if ({}.hasOwnProperty.call(choice, key)) {
204
+ if (
205
+ check2004ValidFormat(choice[key], Regex.scorm2004.NAVBoolean) &&
206
+ check2004ValidFormat(key, Regex.scorm2004.NAVTarget)
207
+ ) {
208
+ this._choice[key] =
209
+ NAVBoolean[choice[key] as keyof typeof NAVBoolean];
210
+ }
211
+ }
212
+ }
213
+ }
214
+
215
+ /**
216
+ * Getter for _jump
217
+ * @return {{ [key: string]: NAVBoolean }}
218
+ */
219
+ get jump(): { [key: string]: NAVBoolean } {
220
+ return this._jump;
221
+ }
222
+
223
+ /**
224
+ * Setter for _jump
225
+ * @param {{ [key: string]: string }} jump
226
+ */
227
+ set jump(jump: { [key: string]: string }) {
228
+ if (this.initialized) {
229
+ throw new Scorm2004ValidationError(
230
+ ErrorCodes.scorm2004.READ_ONLY_ELEMENT,
231
+ );
232
+ }
233
+ if (typeof jump !== "object") {
234
+ throw new Scorm2004ValidationError(ErrorCodes.scorm2004.TYPE_MISMATCH);
235
+ }
236
+ for (const key in jump) {
237
+ if ({}.hasOwnProperty.call(jump, key)) {
238
+ if (
239
+ check2004ValidFormat(jump[key], Regex.scorm2004.NAVBoolean) &&
240
+ check2004ValidFormat(key, Regex.scorm2004.NAVTarget)
241
+ ) {
242
+ this._jump[key] = NAVBoolean[jump[key] as keyof typeof NAVBoolean];
243
+ }
244
+ }
245
+ }
246
+ }
247
+
248
+ /**
249
+ * toJSON for adl.nav.request_valid
250
+ *
251
+ * @return {
252
+ * {
253
+ * previous: string,
254
+ * continue: string
255
+ * }
256
+ * }
257
+ */
258
+ toJSON(): {
259
+ previous: string;
260
+ continue: string;
261
+ } {
262
+ this.jsonString = true;
263
+ const result = {
264
+ previous: this._previous,
265
+ continue: this._continue,
266
+ choice: this._choice,
267
+ jump: this._jump,
268
+ };
269
+ delete this.jsonString;
270
+ return result;
271
+ }
272
+ }