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,339 +0,0 @@
1
- import {expect} from 'chai';
2
- import {describe, it} from 'mocha';
3
- import * as Utilities from '../src/utilities';
4
- import Regex from '../src/constants/regex';
5
-
6
- const scorm12_regex = Regex.scorm12;
7
- const scorm2004_regex = Regex.scorm2004;
8
-
9
- describe('Utility Tests', () => {
10
- describe('getSecondsAsHHMMSS()', () => {
11
- it('10 returns 00:00:10', () => {
12
- expect(
13
- Utilities.getSecondsAsHHMMSS(10),
14
- ).to.equal('00:00:10');
15
- });
16
-
17
- it('60 returns 00:01:00', () => {
18
- expect(
19
- Utilities.getSecondsAsHHMMSS(60),
20
- ).to.equal('00:01:00');
21
- });
22
-
23
- it('3600 returns 01:00:00', () => {
24
- expect(
25
- Utilities.getSecondsAsHHMMSS(3600),
26
- ).to.equal('01:00:00');
27
- });
28
-
29
- it('70 returns 00:01:10', () => {
30
- expect(
31
- Utilities.getSecondsAsHHMMSS(70),
32
- ).to.equal('00:01:10');
33
- });
34
-
35
- it('3670 returns 01:01:10', () => {
36
- expect(
37
- Utilities.getSecondsAsHHMMSS(3670),
38
- ).to.equal('01:01:10');
39
- });
40
-
41
- it('90000 returns 25:00:00, check for hours greater than 24', () => {
42
- expect(
43
- Utilities.getSecondsAsHHMMSS(90000),
44
- ).to.equal('25:00:00');
45
- });
46
-
47
- it('-3600 returns 00:00:00, negative time not allowed in SCORM session times',
48
- () => {
49
- expect(
50
- Utilities.getSecondsAsHHMMSS(-3600),
51
- ).to.equal('00:00:00');
52
- });
53
-
54
- it('Empty seconds returns 00:00:00', () => {
55
- expect(
56
- Utilities.getSecondsAsHHMMSS(null),
57
- ).to.equal('00:00:00');
58
- });
59
- });
60
-
61
- describe('getSecondsAsISODuration()', () => {
62
- it('10 returns PT10S', () => {
63
- expect(
64
- Utilities.getSecondsAsISODuration(10),
65
- ).to.equal('PT10S');
66
- });
67
-
68
- it('60 returns PT1M', () => {
69
- expect(
70
- Utilities.getSecondsAsISODuration(60),
71
- ).to.equal('PT1M');
72
- });
73
-
74
- it('3600 returns PT1H', () => {
75
- expect(
76
- Utilities.getSecondsAsISODuration(3600),
77
- ).to.equal('PT1H');
78
- });
79
-
80
- it('70 returns PT1M10S', () => {
81
- expect(
82
- Utilities.getSecondsAsISODuration(70),
83
- ).to.equal('PT1M10S');
84
- });
85
-
86
- it('916.88 returns PT15M16.88S', () => {
87
- expect(
88
- Utilities.getSecondsAsISODuration(916.88),
89
- ).to.equal('PT15M16.88S');
90
- });
91
-
92
- it('3670 returns PT1H1M10S', () => {
93
- expect(
94
- Utilities.getSecondsAsISODuration(3670),
95
- ).to.equal('PT1H1M10S');
96
- });
97
-
98
- it('90000 returns P1DT1H', () => {
99
- expect(
100
- Utilities.getSecondsAsISODuration(90000),
101
- ).to.equal('P1DT1H');
102
- });
103
-
104
- it('90061 returns P1DT1H1M1S', () => {
105
- expect(
106
- Utilities.getSecondsAsISODuration(90061),
107
- ).to.equal('P1DT1H1M1S');
108
- });
109
-
110
- it('-3600 returns PT0S, negative time not allowed in SCORM session times',
111
- () => {
112
- expect(
113
- Utilities.getSecondsAsISODuration(-3600),
114
- ).to.equal('PT0S');
115
- });
116
-
117
- it('Empty seconds returns PT0S', () => {
118
- expect(
119
- Utilities.getSecondsAsISODuration(null),
120
- ).to.equal('PT0S');
121
- });
122
- });
123
-
124
- describe('getTimeAsSeconds()', () => {
125
- it('00:00:10 returns 10', () => {
126
- expect(
127
- Utilities.getTimeAsSeconds('00:00:10', scorm12_regex.CMITimespan),
128
- ).to.equal(10);
129
- });
130
-
131
- it('00:01:10 returns 70', () => {
132
- expect(
133
- Utilities.getTimeAsSeconds('00:01:10', scorm12_regex.CMITimespan),
134
- ).to.equal(70);
135
- });
136
-
137
- it('01:01:10 returns 3670', () => {
138
- expect(
139
- Utilities.getTimeAsSeconds('01:01:10', scorm12_regex.CMITimespan),
140
- ).to.equal(3670);
141
- });
142
-
143
- it('100:00:00 returns 3670', () => {
144
- expect(
145
- Utilities.getTimeAsSeconds('100:00:00', scorm12_regex.CMITimespan),
146
- ).to.equal(360000);
147
- });
148
-
149
- it('-01:00:00 returns 0', () => {
150
- expect(
151
- Utilities.getTimeAsSeconds('-01:00:00', scorm12_regex.CMITimespan),
152
- ).to.equal(0);
153
- });
154
-
155
- it('Number value returns 0', () => {
156
- expect(
157
- Utilities.getTimeAsSeconds(999, scorm12_regex.CMITimespan),
158
- ).to.equal(0);
159
- });
160
-
161
- it('boolean value returns 0', () => {
162
- expect(
163
- Utilities.getTimeAsSeconds(true, scorm12_regex.CMITimespan),
164
- ).to.equal(0);
165
- });
166
-
167
- it('Empty value returns 0', () => {
168
- expect(
169
- Utilities.getTimeAsSeconds(null, scorm12_regex.CMITimespan),
170
- ).to.equal(0);
171
- });
172
- });
173
-
174
- describe('getDurationAsSeconds()', () => {
175
- it('P0S returns 0', () => {
176
- expect(
177
- Utilities.getDurationAsSeconds('P0S', scorm2004_regex.CMITimespan),
178
- ).to.equal(0);
179
- });
180
-
181
- it('P70S returns 70', () => {
182
- expect(
183
- Utilities.getDurationAsSeconds('P70S', scorm2004_regex.CMITimespan),
184
- ).to.equal(70);
185
- });
186
-
187
- it('PT1M10S returns 70', () => {
188
- expect(
189
- Utilities.getDurationAsSeconds('PT1M10S',
190
- scorm2004_regex.CMITimespan),
191
- ).to.equal(70);
192
- });
193
-
194
- it('PT15M16.88S returns 916.88', () => {
195
- expect(
196
- Utilities.getDurationAsSeconds('PT15M16.88S',
197
- scorm2004_regex.CMITimespan),
198
- ).to.equal(916.88);
199
- });
200
-
201
- it('P1D returns 86400', () => {
202
- expect(
203
- Utilities.getDurationAsSeconds('P1D', scorm2004_regex.CMITimespan),
204
- ).to.equal(86400);
205
- });
206
-
207
- it('P1Y returns number of seconds for one year from now', () => {
208
- const now = new Date();
209
- const oneYearFromNow = new Date(now);
210
- oneYearFromNow.setFullYear(oneYearFromNow.getFullYear() + 1);
211
-
212
- expect(
213
- Utilities.getDurationAsSeconds('P1Y', scorm2004_regex.CMITimespan),
214
- ).to.equal((oneYearFromNow - now) / 1000.0);
215
- });
216
-
217
- it('Invalid duration returns 0', () => {
218
- expect(
219
- Utilities.getDurationAsSeconds('T1M10S', scorm2004_regex.CMITimespan),
220
- ).to.equal(0);
221
- });
222
-
223
- it('Empty duration returns 0', () => {
224
- expect(
225
- Utilities.getDurationAsSeconds(null, scorm2004_regex.CMITimespan),
226
- ).to.equal(0);
227
- });
228
- });
229
-
230
- describe('addTwoDurations()', () => {
231
- it('P1H5M30.5S plus PT15M10S equals P1H20M40.5S', () => {
232
- expect(
233
- Utilities.addTwoDurations('PT1H5M30.5S', 'PT15M30S',
234
- scorm2004_regex.CMITimespan),
235
- ).to.equal('PT1H21M0.5S');
236
- });
237
- it('P1Y364D plus P2DT1H45M52S equals P731DT1H45M52S', () => {
238
- expect(
239
- Utilities.addTwoDurations('P1Y364D', 'P2DT1H45M52S',
240
- scorm2004_regex.CMITimespan),
241
- ).to.equal('P731DT1H45M52S');
242
- });
243
- it('Invalid plus valid equals valid', () => {
244
- expect(
245
- Utilities.addTwoDurations('NOT A VALID DURATION', 'PT1H30M45S',
246
- scorm2004_regex.CMITimespan),
247
- ).to.equal('PT1H30M45S');
248
- });
249
- it('Valid plus invalid equals valid', () => {
250
- expect(
251
- Utilities.addTwoDurations('PT1H30M45S', 'NOT A VALID DURATION',
252
- scorm2004_regex.CMITimespan),
253
- ).to.equal('PT1H30M45S');
254
- });
255
- });
256
-
257
- describe('addHHMMSSTimeStrings()', () => {
258
- it('01:05:30.5 plus 00:15:10 equals 01:20:40.5', () => {
259
- expect(
260
- Utilities.addHHMMSSTimeStrings('01:05:30.5', '00:15:30',
261
- scorm12_regex.CMITimespan),
262
- ).to.equal('01:21:00.5');
263
- });
264
- it('17496:00:00 plus 49:35:52 equals 17545:35:52', () => {
265
- expect(
266
- Utilities.addHHMMSSTimeStrings('17496:00:00', '49:35:52',
267
- scorm12_regex.CMITimespan),
268
- ).to.equal('17545:35:52');
269
- });
270
- it('Invalid plus valid equals valid', () => {
271
- expect(
272
- Utilities.addHHMMSSTimeStrings('-00:15:10', '01:05:30.5',
273
- scorm12_regex.CMITimespan),
274
- ).to.equal('01:05:30.5');
275
- });
276
- it('Valid plus invalid equals valid', () => {
277
- expect(
278
- Utilities.addHHMMSSTimeStrings('01:05:30.5', 'NOT A VALID DURATION',
279
- scorm12_regex.CMITimespan),
280
- ).to.equal('01:05:30.5');
281
- });
282
- });
283
-
284
- describe('flatten()', () => {
285
- it('Should return flattened object', () => {
286
- expect(
287
- Utilities.flatten({
288
- 'cmi': {
289
- 'core': {
290
- 'learner_id': 'jputney',
291
- 'learner_name': 'Jonathan',
292
- },
293
- 'objectives': {
294
- '0': {
295
- 'id': 'AAA',
296
- },
297
- '1': {
298
- 'id': 'BBB',
299
- },
300
- },
301
- },
302
- }),
303
- ).to.eql({
304
- 'cmi.core.learner_id': 'jputney',
305
- 'cmi.core.learner_name': 'Jonathan',
306
- 'cmi.objectives.0.id': 'AAA',
307
- 'cmi.objectives.1.id': 'BBB',
308
- });
309
- });
310
- });
311
-
312
- describe('unflatten()', () => {
313
- it('Should return flattened object', () => {
314
- expect(
315
- Utilities.unflatten({
316
- 'cmi.core.learner_id': 'jputney',
317
- 'cmi.core.learner_name': 'Jonathan',
318
- 'cmi.objectives.0.id': 'AAA',
319
- 'cmi.objectives.1.id': 'BBB',
320
- }),
321
- ).to.eql({
322
- 'cmi': {
323
- 'core': {
324
- 'learner_id': 'jputney',
325
- 'learner_name': 'Jonathan',
326
- },
327
- 'objectives': {
328
- '0': {
329
- 'id': 'AAA',
330
- },
331
- '1': {
332
- 'id': 'BBB',
333
- },
334
- },
335
- },
336
- });
337
- });
338
- });
339
- });
package/webpack.js DELETED
@@ -1,78 +0,0 @@
1
- const path = require('path');
2
- const webpack = require('webpack');
3
- const ESLintPlugin = require('eslint-webpack-plugin');
4
- const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
5
-
6
- const JSLoader = {
7
- test: /\.js$/i,
8
- use: {
9
- loader: 'babel-loader',
10
- options: {
11
- presets: [
12
- [
13
- '@babel/preset-env',
14
- {
15
- 'corejs': '3',
16
- 'useBuiltIns': 'entry',
17
- 'targets': {
18
- 'browsers': [
19
- 'edge >= 16',
20
- 'safari >= 9',
21
- 'firefox >= 57',
22
- 'ie >= 11',
23
- 'ios >= 9',
24
- 'chrome >= 49',
25
- ],
26
- },
27
- },
28
- ],
29
- ['@babel/preset-flow'],
30
- ],
31
- plugins: [
32
- '@babel/plugin-proposal-class-properties',
33
- '@babel/plugin-proposal-private-methods',
34
- '@babel/plugin-proposal-optional-chaining',
35
- ],
36
- },
37
- },
38
- };
39
-
40
- module.exports = {
41
- mode: 'development',
42
- devtool: 'source-map',
43
- entry: {
44
- 'aicc': './src/exports/aicc.js',
45
- 'scorm12': './src/exports/scorm12.js',
46
- 'scorm2004': './src/exports/scorm2004.js',
47
- 'scorm-again': './src/exports/scorm-again.js',
48
- 'aicc.min': './src/exports/aicc.js',
49
- 'scorm12.min': './src/exports/scorm12.js',
50
- 'scorm2004.min': './src/exports/scorm2004.js',
51
- 'scorm-again.min': './src/exports/scorm-again.js',
52
- },
53
- target: ['web', 'es5'],
54
- module: {
55
- rules: [
56
- JSLoader,
57
- ],
58
- },
59
- output: {
60
- path: path.resolve(__dirname, 'dist'),
61
- environment: {
62
- arrowFunction: false,
63
- },
64
- },
65
- optimization: {
66
- minimize: true,
67
- minimizer: [new UglifyJsPlugin({
68
- include: /\.min\.js$/,
69
- })],
70
- },
71
- plugins: [
72
- new ESLintPlugin({
73
- overrideConfigFile: path.resolve(__dirname, '.eslintrc.js'),
74
- context: path.resolve(__dirname, '../src'),
75
- files: '**/*.js',
76
- }),
77
- ],
78
- };