scorm-again 1.7.1 → 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.
- package/.babelrc +18 -7
- package/.github/dependabot.yml +5 -0
- package/.github/workflows/main.yml +79 -0
- package/.github/workflows/stale.yml +14 -0
- package/.jsdoc.json +4 -5
- package/.mocharc.json +8 -0
- package/.run/{Mocha Unit Tests.run.xml → Mocha Unit Tests (watch).run.xml } +6 -3
- package/.run/Template Mocha.run.xml +17 -0
- package/CONTRIBUTING.md +1 -1
- package/README.md +183 -71
- package/dist/aicc.js +3822 -7030
- package/dist/aicc.js.map +1 -1
- package/dist/aicc.min.js +2 -40
- package/dist/aicc.min.js.map +1 -0
- package/dist/scorm-again.js +5965 -10498
- package/dist/scorm-again.js.map +1 -1
- package/dist/scorm-again.min.js +2 -52
- package/dist/scorm-again.min.js.map +1 -0
- package/dist/scorm12.js +3028 -5373
- package/dist/scorm12.js.map +1 -1
- package/dist/scorm12.min.js +2 -34
- package/dist/scorm12.min.js.map +1 -0
- package/dist/scorm2004.js +4054 -6693
- package/dist/scorm2004.js.map +1 -1
- package/dist/scorm2004.min.js +2 -40
- package/dist/scorm2004.min.js.map +1 -0
- package/eslint.config.js +21 -0
- package/package.json +76 -34
- package/results.json +34254 -0
- package/src/AICC.ts +72 -0
- package/src/BaseAPI.ts +1300 -0
- package/src/Scorm12API.ts +387 -0
- package/src/Scorm2004API.ts +688 -0
- package/src/cmi/aicc/attempts.ts +94 -0
- package/src/cmi/aicc/cmi.ts +100 -0
- package/src/cmi/aicc/core.ts +360 -0
- package/src/cmi/aicc/evaluation.ts +157 -0
- package/src/cmi/aicc/paths.ts +180 -0
- package/src/cmi/aicc/student_data.ts +86 -0
- package/src/cmi/aicc/student_demographics.ts +367 -0
- package/src/cmi/aicc/student_preferences.ts +176 -0
- package/src/cmi/aicc/tries.ts +116 -0
- package/src/cmi/aicc/validation.ts +25 -0
- package/src/cmi/common/array.ts +77 -0
- package/src/cmi/common/base_cmi.ts +46 -0
- package/src/cmi/common/score.ts +203 -0
- package/src/cmi/common/validation.ts +60 -0
- package/src/cmi/scorm12/cmi.ts +224 -0
- package/src/cmi/scorm12/interactions.ts +368 -0
- package/src/cmi/scorm12/nav.ts +54 -0
- package/src/cmi/scorm12/objectives.ts +112 -0
- package/src/cmi/scorm12/student_data.ts +130 -0
- package/src/cmi/scorm12/student_preference.ts +158 -0
- package/src/cmi/scorm12/validation.ts +48 -0
- package/src/cmi/scorm2004/adl.ts +272 -0
- package/src/cmi/scorm2004/cmi.ts +599 -0
- package/src/cmi/scorm2004/comments.ts +163 -0
- package/src/cmi/scorm2004/interactions.ts +466 -0
- package/src/cmi/scorm2004/learner_preference.ts +152 -0
- package/src/cmi/scorm2004/objectives.ts +212 -0
- package/src/cmi/scorm2004/score.ts +78 -0
- package/src/cmi/scorm2004/validation.ts +42 -0
- package/src/constants/api_constants.ts +318 -0
- package/src/constants/default_settings.ts +81 -0
- package/src/constants/enums.ts +5 -0
- package/src/constants/error_codes.ts +88 -0
- package/src/constants/language_constants.ts +394 -0
- package/src/constants/regex.ts +97 -0
- package/src/constants/{response_constants.js → response_constants.ts} +69 -62
- package/src/exceptions.ts +154 -0
- package/src/exports/aicc.js +1 -1
- package/src/exports/scorm-again.js +3 -3
- package/src/exports/scorm12.js +1 -1
- package/src/exports/scorm2004.js +1 -1
- package/src/helpers/scheduled_commit.ts +42 -0
- package/src/interfaces/IBaseAPI.ts +35 -0
- package/src/types/api_types.ts +32 -0
- package/src/utilities/debounce.ts +31 -0
- package/src/utilities.ts +338 -0
- package/tea.yaml +6 -0
- package/test/{AICC.spec.js → AICC.spec.ts} +79 -71
- package/test/Scorm12API.spec.ts +833 -0
- package/test/Scorm2004API.spec.ts +1298 -0
- package/test/api_helpers.ts +176 -0
- package/test/cmi/aicc_cmi.spec.ts +845 -0
- package/test/cmi/{scorm12_cmi.spec.js → scorm12_cmi.spec.ts} +253 -271
- package/test/cmi/scorm2004_cmi.spec.ts +1031 -0
- package/test/cmi_helpers.ts +207 -0
- package/test/exceptions.spec.ts +79 -0
- package/test/field_values.ts +202 -0
- package/test/types/api_types.spec.ts +126 -0
- package/test/utilities/debounce.spec.ts +56 -0
- package/test/utilities.spec.ts +322 -0
- package/tsconfig.json +18 -0
- package/webpack.config.js +65 -0
- package/.circleci/config.yml +0 -99
- package/.codeclimate.yml +0 -7
- package/.eslintrc.js +0 -36
- package/src/.flowconfig +0 -11
- package/src/AICC.js +0 -68
- package/src/BaseAPI.js +0 -1275
- package/src/Scorm12API.js +0 -308
- package/src/Scorm2004API.js +0 -572
- package/src/cmi/aicc_cmi.js +0 -1141
- package/src/cmi/common.js +0 -328
- package/src/cmi/scorm12_cmi.js +0 -1312
- package/src/cmi/scorm2004_cmi.js +0 -1692
- package/src/constants/api_constants.js +0 -218
- package/src/constants/error_codes.js +0 -87
- package/src/constants/language_constants.js +0 -76
- package/src/constants/regex.js +0 -84
- package/src/exceptions.js +0 -104
- package/src/utilities.js +0 -242
- package/test/Scorm12API.spec.js +0 -528
- package/test/Scorm2004API.spec.js +0 -775
- package/test/abstract_classes.spec.js +0 -17
- package/test/api_helpers.js +0 -128
- package/test/cmi/aicc_cmi.spec.js +0 -684
- package/test/cmi/scorm2004_cmi.spec.js +0 -1066
- package/test/cmi_helpers.js +0 -161
- package/test/exceptions.spec.js +0 -71
- package/test/field_values.js +0 -353
- package/test/utilities.spec.js +0 -339
- package/webpack.js +0 -78
package/src/utilities.js
DELETED
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
export const SECONDS_PER_SECOND = 1.0;
|
|
3
|
-
export const SECONDS_PER_MINUTE = 60;
|
|
4
|
-
export const SECONDS_PER_HOUR = 60 * SECONDS_PER_MINUTE;
|
|
5
|
-
export const SECONDS_PER_DAY = 24 * SECONDS_PER_HOUR;
|
|
6
|
-
|
|
7
|
-
const designations = [
|
|
8
|
-
['D', SECONDS_PER_DAY],
|
|
9
|
-
['H', SECONDS_PER_HOUR],
|
|
10
|
-
['M', SECONDS_PER_MINUTE],
|
|
11
|
-
['S', SECONDS_PER_SECOND],
|
|
12
|
-
];
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Converts a Number to a String of HH:MM:SS
|
|
16
|
-
*
|
|
17
|
-
* @param {Number} totalSeconds
|
|
18
|
-
* @return {string}
|
|
19
|
-
*/
|
|
20
|
-
export function getSecondsAsHHMMSS(totalSeconds: Number) {
|
|
21
|
-
// SCORM spec does not deal with negative durations, give zero back
|
|
22
|
-
if (!totalSeconds || totalSeconds <= 0) {
|
|
23
|
-
return '00:00:00';
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const hours = Math.floor(totalSeconds / SECONDS_PER_HOUR);
|
|
27
|
-
|
|
28
|
-
const dateObj = new Date(totalSeconds * 1000);
|
|
29
|
-
const minutes = dateObj.getUTCMinutes();
|
|
30
|
-
// make sure we add any possible decimal value
|
|
31
|
-
const seconds = dateObj.getSeconds();
|
|
32
|
-
const ms = totalSeconds % 1.0;
|
|
33
|
-
let msStr = '';
|
|
34
|
-
if (countDecimals(ms) > 0) {
|
|
35
|
-
if (countDecimals(ms) > 2) {
|
|
36
|
-
msStr = ms.toFixed(2);
|
|
37
|
-
} else {
|
|
38
|
-
msStr = String(ms);
|
|
39
|
-
}
|
|
40
|
-
msStr = '.' + msStr.split('.')[1];
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return (hours + ':' + minutes + ':' + seconds).replace(/\b\d\b/g,
|
|
44
|
-
'0$&') + msStr;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Calculate the number of seconds from ISO 8601 Duration
|
|
49
|
-
*
|
|
50
|
-
* @param {Number} seconds
|
|
51
|
-
* @return {String}
|
|
52
|
-
*/
|
|
53
|
-
export function getSecondsAsISODuration(seconds: Number) {
|
|
54
|
-
// SCORM spec does not deal with negative durations, give zero back
|
|
55
|
-
if (!seconds || seconds <= 0) {
|
|
56
|
-
return 'PT0S';
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
let duration = 'P';
|
|
60
|
-
let remainder = seconds;
|
|
61
|
-
|
|
62
|
-
designations.forEach(([sign, current_seconds]) => {
|
|
63
|
-
let value = Math.floor(remainder / current_seconds);
|
|
64
|
-
|
|
65
|
-
remainder = remainder % current_seconds;
|
|
66
|
-
if (countDecimals(remainder) > 2) {
|
|
67
|
-
remainder = Number(Number(remainder).toFixed(2));
|
|
68
|
-
}
|
|
69
|
-
// If we have anything left in the remainder, and we're currently adding
|
|
70
|
-
// seconds to the duration, go ahead and add the decimal to the seconds
|
|
71
|
-
if (sign === 'S' && remainder > 0) {
|
|
72
|
-
value += remainder;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (value) {
|
|
76
|
-
if ((duration.indexOf('D') > 0 ||
|
|
77
|
-
sign === 'H' || sign === 'M' || sign === 'S') &&
|
|
78
|
-
duration.indexOf('T') === -1) {
|
|
79
|
-
duration += 'T';
|
|
80
|
-
}
|
|
81
|
-
duration += `${value}${sign}`;
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
return duration;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Calculate the number of seconds from HH:MM:SS.DDDDDD
|
|
90
|
-
*
|
|
91
|
-
* @param {string} timeString
|
|
92
|
-
* @param {RegExp} timeRegex
|
|
93
|
-
* @return {number}
|
|
94
|
-
*/
|
|
95
|
-
export function getTimeAsSeconds(timeString: String, timeRegex: RegExp) {
|
|
96
|
-
if (!timeString || typeof timeString !== 'string' ||
|
|
97
|
-
!timeString.match(timeRegex)) {
|
|
98
|
-
return 0;
|
|
99
|
-
}
|
|
100
|
-
const parts = timeString.split(':');
|
|
101
|
-
const hours = Number(parts[0]);
|
|
102
|
-
const minutes = Number(parts[1]);
|
|
103
|
-
const seconds = Number(parts[2]);
|
|
104
|
-
return (hours * 3600) + (minutes * 60) + seconds;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Calculate the number of seconds from ISO 8601 Duration
|
|
109
|
-
*
|
|
110
|
-
* @param {string} duration
|
|
111
|
-
* @param {RegExp} durationRegex
|
|
112
|
-
* @return {number}
|
|
113
|
-
*/
|
|
114
|
-
export function getDurationAsSeconds(duration: String, durationRegex: RegExp) {
|
|
115
|
-
if (!duration || !duration.match(durationRegex)) {
|
|
116
|
-
return 0;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const [, years, months, , days, hours, minutes, seconds] = new RegExp(
|
|
120
|
-
durationRegex).exec(duration) || [];
|
|
121
|
-
|
|
122
|
-
let result = 0.0;
|
|
123
|
-
|
|
124
|
-
result += (Number(seconds) * 1.0 || 0.0);
|
|
125
|
-
result += (Number(minutes) * 60.0 || 0.0);
|
|
126
|
-
result += (Number(hours) * 3600.0 || 0.0);
|
|
127
|
-
result += (Number(days) * (60 * 60 * 24.0) || 0.0);
|
|
128
|
-
result += (Number(years) * (60 * 60 * 24 * 365.0) || 0.0);
|
|
129
|
-
|
|
130
|
-
return result;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Adds together two ISO8601 Duration strings
|
|
135
|
-
*
|
|
136
|
-
* @param {string} first
|
|
137
|
-
* @param {string} second
|
|
138
|
-
* @param {RegExp} durationRegex
|
|
139
|
-
* @return {string}
|
|
140
|
-
*/
|
|
141
|
-
export function addTwoDurations(
|
|
142
|
-
first: String,
|
|
143
|
-
second: String,
|
|
144
|
-
durationRegex: RegExp) {
|
|
145
|
-
return getSecondsAsISODuration(
|
|
146
|
-
getDurationAsSeconds(first, durationRegex) +
|
|
147
|
-
getDurationAsSeconds(second, durationRegex),
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Add together two HH:MM:SS.DD strings
|
|
153
|
-
*
|
|
154
|
-
* @param {string} first
|
|
155
|
-
* @param {string} second
|
|
156
|
-
* @param {RegExp} timeRegex
|
|
157
|
-
* @return {string}
|
|
158
|
-
*/
|
|
159
|
-
export function addHHMMSSTimeStrings(
|
|
160
|
-
first: String,
|
|
161
|
-
second: String,
|
|
162
|
-
timeRegex: RegExp) {
|
|
163
|
-
return getSecondsAsHHMMSS(
|
|
164
|
-
getTimeAsSeconds(first, timeRegex) +
|
|
165
|
-
getTimeAsSeconds(
|
|
166
|
-
second, timeRegex),
|
|
167
|
-
);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Flatten a JSON object down to string paths for each values
|
|
172
|
-
* @param {object} data
|
|
173
|
-
* @return {object}
|
|
174
|
-
*/
|
|
175
|
-
export function flatten(data) {
|
|
176
|
-
const result = {};
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Recurse through the object
|
|
180
|
-
* @param {*} cur
|
|
181
|
-
* @param {*} prop
|
|
182
|
-
*/
|
|
183
|
-
function recurse(cur, prop) {
|
|
184
|
-
if (Object(cur) !== cur) {
|
|
185
|
-
result[prop] = cur;
|
|
186
|
-
} else if (Array.isArray(cur)) {
|
|
187
|
-
for (let i = 0, l = cur.length; i < l; i++) {
|
|
188
|
-
recurse(cur[i], prop + '[' + i + ']');
|
|
189
|
-
if (l === 0) result[prop] = [];
|
|
190
|
-
}
|
|
191
|
-
} else {
|
|
192
|
-
let isEmpty = true;
|
|
193
|
-
for (const p in cur) {
|
|
194
|
-
if ({}.hasOwnProperty.call(cur, p)) {
|
|
195
|
-
isEmpty = false;
|
|
196
|
-
recurse(cur[p], prop ? prop + '.' + p : p);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
if (isEmpty && prop) result[prop] = {};
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
recurse(data, '');
|
|
204
|
-
return result;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Un-flatten a flat JSON object
|
|
209
|
-
* @param {object} data
|
|
210
|
-
* @return {object}
|
|
211
|
-
*/
|
|
212
|
-
export function unflatten(data) {
|
|
213
|
-
'use strict';
|
|
214
|
-
if (Object(data) !== data || Array.isArray(data)) return data;
|
|
215
|
-
const regex = /\.?([^.[\]]+)|\[(\d+)]/g;
|
|
216
|
-
const result = {};
|
|
217
|
-
for (const p in data) {
|
|
218
|
-
if ({}.hasOwnProperty.call(data, p)) {
|
|
219
|
-
let cur = result;
|
|
220
|
-
let prop = '';
|
|
221
|
-
let m = regex.exec(p);
|
|
222
|
-
while (m) {
|
|
223
|
-
cur = cur[prop] || (cur[prop] = (m[2] ? [] : {}));
|
|
224
|
-
prop = m[2] || m[1];
|
|
225
|
-
m = regex.exec(p);
|
|
226
|
-
}
|
|
227
|
-
cur[prop] = data[p];
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
return result[''] || result;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* Counts the number of decimal places
|
|
235
|
-
* @param {number} num
|
|
236
|
-
* @return {number}
|
|
237
|
-
*/
|
|
238
|
-
export function countDecimals(num: number) {
|
|
239
|
-
if (Math.floor(num) === num || String(num).indexOf('.') < 0) return 0;
|
|
240
|
-
const parts = num.toString().split('.')[1];
|
|
241
|
-
return parts.length || 0;
|
|
242
|
-
}
|