scorm-again 2.6.3 → 2.6.4

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 (68) hide show
  1. package/dist/aicc.js +37 -22
  2. package/dist/aicc.js.map +1 -1
  3. package/dist/aicc.min.js +1 -1
  4. package/dist/aicc.min.js.map +1 -1
  5. package/dist/esm/aicc.js +37 -22
  6. package/dist/esm/aicc.js.map +1 -1
  7. package/dist/esm/aicc.min.js +1 -1
  8. package/dist/esm/aicc.min.js.map +1 -1
  9. package/dist/esm/scorm-again.js +66 -42
  10. package/dist/esm/scorm-again.js.map +1 -1
  11. package/dist/esm/scorm-again.min.js +1 -1
  12. package/dist/esm/scorm-again.min.js.map +1 -1
  13. package/dist/esm/scorm12.js +34 -20
  14. package/dist/esm/scorm12.js.map +1 -1
  15. package/dist/esm/scorm12.min.js +1 -1
  16. package/dist/esm/scorm12.min.js.map +1 -1
  17. package/dist/esm/scorm2004.js +56 -36
  18. package/dist/esm/scorm2004.js.map +1 -1
  19. package/dist/esm/scorm2004.min.js +1 -1
  20. package/dist/esm/scorm2004.min.js.map +1 -1
  21. package/dist/scorm-again.js +66 -42
  22. package/dist/scorm-again.js.map +1 -1
  23. package/dist/scorm-again.min.js +1 -1
  24. package/dist/scorm-again.min.js.map +1 -1
  25. package/dist/scorm12.js +34 -20
  26. package/dist/scorm12.js.map +1 -1
  27. package/dist/scorm12.min.js +1 -1
  28. package/dist/scorm12.min.js.map +1 -1
  29. package/dist/scorm2004.js +56 -36
  30. package/dist/scorm2004.js.map +1 -1
  31. package/dist/scorm2004.min.js +1 -1
  32. package/dist/scorm2004.min.js.map +1 -1
  33. package/package.json +1 -1
  34. package/src/BaseAPI.ts +54 -33
  35. package/src/Scorm12API.ts +3 -2
  36. package/src/Scorm2004API.ts +31 -24
  37. package/src/cmi/aicc/attempts.ts +3 -3
  38. package/src/cmi/aicc/core.ts +30 -12
  39. package/src/cmi/aicc/evaluation.ts +1 -1
  40. package/src/cmi/aicc/student_data.ts +1 -1
  41. package/src/cmi/aicc/student_demographics.ts +13 -13
  42. package/src/cmi/aicc/student_preferences.ts +1 -1
  43. package/src/cmi/aicc/tries.ts +3 -3
  44. package/src/cmi/aicc/validation.ts +1 -1
  45. package/src/cmi/common/array.ts +1 -1
  46. package/src/cmi/common/score.ts +3 -3
  47. package/src/cmi/common/validation.ts +2 -2
  48. package/src/cmi/scorm12/cmi.ts +12 -4
  49. package/src/cmi/scorm12/interactions.ts +27 -11
  50. package/src/cmi/scorm12/objectives.ts +4 -4
  51. package/src/cmi/scorm12/student_data.ts +12 -4
  52. package/src/cmi/scorm12/student_preference.ts +3 -1
  53. package/src/cmi/scorm12/validation.ts +5 -3
  54. package/src/cmi/scorm2004/adl.ts +21 -7
  55. package/src/cmi/scorm2004/cmi.ts +45 -15
  56. package/src/cmi/scorm2004/comments.ts +11 -5
  57. package/src/cmi/scorm2004/interactions.ts +25 -23
  58. package/src/cmi/scorm2004/learner_preference.ts +3 -1
  59. package/src/cmi/scorm2004/objectives.ts +5 -5
  60. package/src/cmi/scorm2004/score.ts +3 -3
  61. package/src/cmi/scorm2004/validation.ts +2 -2
  62. package/src/exceptions/aicc_exceptions.ts +4 -4
  63. package/src/exceptions/scorm12_exceptions.ts +4 -4
  64. package/src/exceptions/scorm2004_exceptions.ts +4 -4
  65. package/src/utilities.ts +3 -3
  66. package/test/Scorm12API.spec.ts +45 -0
  67. package/test/Scorm2004API.spec.ts +43 -0
  68. package/tsconfig.json +1 -0
@@ -415,6 +415,10 @@ var BaseAPI = (function () {
415
415
  : this._error_codes.GENERAL;
416
416
  for (var idx = 0; idx < structure.length; idx++) {
417
417
  var attribute = structure[idx];
418
+ if (!attribute) {
419
+ this.throwSCORMError(invalidErrorCode, invalidErrorMessage);
420
+ return api_constants.global_constants.SCORM_FALSE;
421
+ }
418
422
  if (idx === structure.length - 1) {
419
423
  if (scorm2004 && attribute.substring(0, 8) === "{target=") {
420
424
  if (this.isInitialized()) {
@@ -445,7 +449,7 @@ var BaseAPI = (function () {
445
449
  break;
446
450
  }
447
451
  if (refObject instanceof array.CMIArray) {
448
- var index = parseInt(structure[idx + 1], 10);
452
+ var index = parseInt(structure[idx + 1] || "0", 10);
449
453
  if (!isNaN(index)) {
450
454
  var item = refObject.childArray[index];
451
455
  if (item) {
@@ -489,6 +493,10 @@ var BaseAPI = (function () {
489
493
  : this._error_codes.GENERAL;
490
494
  for (var idx = 0; idx < structure.length; idx++) {
491
495
  attribute = structure[idx];
496
+ if (!attribute) {
497
+ this.throwSCORMError(invalidErrorCode, invalidErrorMessage);
498
+ return;
499
+ }
492
500
  if (!scorm2004) {
493
501
  if (idx === structure.length - 1) {
494
502
  if (!this._checkObjectHasProperty(refObject, attribute)) {
@@ -514,7 +522,7 @@ var BaseAPI = (function () {
514
522
  break;
515
523
  }
516
524
  if (refObject instanceof array.CMIArray) {
517
- var index = parseInt(structure[idx + 1], 10);
525
+ var index = parseInt(structure[idx + 1] || "", 10);
518
526
  if (!isNaN(index)) {
519
527
  var item = refObject.childArray[index];
520
528
  if (item) {
@@ -552,17 +560,18 @@ var BaseAPI = (function () {
552
560
  return this.currentState === api_constants.global_constants.STATE_TERMINATED;
553
561
  };
554
562
  BaseAPI.prototype.on = function (listenerName, callback) {
563
+ var _a, _c;
555
564
  if (!callback)
556
565
  return;
557
566
  var listenerFunctions = listenerName.split(" ");
558
567
  for (var i = 0; i < listenerFunctions.length; i++) {
559
- var listenerSplit = listenerFunctions[i].split(".");
560
- if (listenerSplit.length === 0)
568
+ var listenerSplit = (_a = listenerFunctions[i]) === null || _a === void 0 ? void 0 : _a.split(".");
569
+ if (!listenerSplit || listenerSplit.length === 0)
561
570
  return;
562
571
  var functionName = listenerSplit[0];
563
572
  var CMIElement = null;
564
573
  if (listenerSplit.length > 1) {
565
- CMIElement = listenerName.replace(functionName + ".", "");
574
+ CMIElement = (_c = listenerFunctions[i]) === null || _c === void 0 ? void 0 : _c.replace(functionName + ".", "");
566
575
  }
567
576
  this.listenerArray.push({
568
577
  functionName: functionName,
@@ -573,17 +582,18 @@ var BaseAPI = (function () {
573
582
  }
574
583
  };
575
584
  BaseAPI.prototype.off = function (listenerName, callback) {
585
+ var _a, _c;
576
586
  if (!callback)
577
587
  return;
578
588
  var listenerFunctions = listenerName.split(" ");
579
589
  var _loop_1 = function (i) {
580
- var listenerSplit = listenerFunctions[i].split(".");
581
- if (listenerSplit.length === 0)
590
+ var listenerSplit = (_a = listenerFunctions[i]) === null || _a === void 0 ? void 0 : _a.split(".");
591
+ if (!listenerSplit || listenerSplit.length === 0)
582
592
  return { value: void 0 };
583
593
  var functionName = listenerSplit[0];
584
594
  var CMIElement = null;
585
595
  if (listenerSplit.length > 1) {
586
- CMIElement = listenerName.replace(functionName + ".", "");
596
+ CMIElement = (_c = listenerFunctions[i]) === null || _c === void 0 ? void 0 : _c.replace(functionName + ".", "");
587
597
  }
588
598
  var removeIndex = this_1.listenerArray.findIndex(function (obj) {
589
599
  return obj.functionName === functionName &&
@@ -603,15 +613,16 @@ var BaseAPI = (function () {
603
613
  }
604
614
  };
605
615
  BaseAPI.prototype.clear = function (listenerName) {
616
+ var _a, _c;
606
617
  var listenerFunctions = listenerName.split(" ");
607
618
  var _loop_2 = function (i) {
608
- var listenerSplit = listenerFunctions[i].split(".");
609
- if (listenerSplit.length === 0)
619
+ var listenerSplit = (_a = listenerFunctions[i]) === null || _a === void 0 ? void 0 : _a.split(".");
620
+ if (!listenerSplit || (listenerSplit === null || listenerSplit === void 0 ? void 0 : listenerSplit.length) === 0)
610
621
  return { value: void 0 };
611
622
  var functionName = listenerSplit[0];
612
623
  var CMIElement = null;
613
624
  if (listenerSplit.length > 1) {
614
- CMIElement = listenerName.replace(functionName + ".", "");
625
+ CMIElement = (_c = listenerFunctions[i]) === null || _c === void 0 ? void 0 : _c.replace(functionName + ".", "");
615
626
  }
616
627
  this_2.listenerArray = this_2.listenerArray.filter(function (obj) {
617
628
  return obj.functionName !== functionName && obj.CMIElement !== CMIElement;
@@ -1180,8 +1191,8 @@ function checkValidFormat(value, regexPattern, errorCode, errorClass, allowEmpty
1180
1191
  function checkValidRange(value, rangePattern, errorCode, errorClass) {
1181
1192
  var ranges = rangePattern.split("#");
1182
1193
  value = value * 1.0;
1183
- if (value >= ranges[0]) {
1184
- if (ranges[1] === "*" || value <= ranges[1]) {
1194
+ if (ranges[0] && value >= ranges[0]) {
1195
+ if (ranges[1] && (ranges[1] === "*" || value <= ranges[1])) {
1185
1196
  return true;
1186
1197
  }
1187
1198
  else {
@@ -2776,11 +2787,12 @@ var Scorm12ValidationError = (function (_super) {
2776
2787
  (0,tslib__WEBPACK_IMPORTED_MODULE_1__.__extends)(Scorm12ValidationError, _super);
2777
2788
  function Scorm12ValidationError(errorCode) {
2778
2789
  var _this = this;
2790
+ var _a, _b, _c, _d, _e;
2779
2791
  if ({}.hasOwnProperty.call(scorm12_errors, String(errorCode))) {
2780
- _this = _super.call(this, errorCode, scorm12_errors[String(errorCode)].basicMessage, scorm12_errors[String(errorCode)].detailMessage) || this;
2792
+ _this = _super.call(this, errorCode, ((_a = scorm12_errors[String(errorCode)]) === null || _a === void 0 ? void 0 : _a.basicMessage) || "Unknown error", (_b = scorm12_errors[String(errorCode)]) === null || _b === void 0 ? void 0 : _b.detailMessage) || this;
2781
2793
  }
2782
2794
  else {
2783
- _this = _super.call(this, 101, scorm12_errors["101"].basicMessage, scorm12_errors["101"].detailMessage) || this;
2795
+ _this = _super.call(this, 101, (_d = (_c = scorm12_errors["101"]) === null || _c === void 0 ? void 0 : _c.basicMessage) !== null && _d !== void 0 ? _d : "General error", (_e = scorm12_errors["101"]) === null || _e === void 0 ? void 0 : _e.detailMessage) || this;
2784
2796
  }
2785
2797
  return _this;
2786
2798
  }
@@ -2850,7 +2862,7 @@ function getSecondsAsISODuration(seconds) {
2850
2862
  var duration = "P";
2851
2863
  var remainder = seconds;
2852
2864
  for (var designationsKey in designations) {
2853
- var current_seconds = designations[designationsKey];
2865
+ var current_seconds = designations[designationsKey] || 1;
2854
2866
  var value = Math.floor(remainder / current_seconds);
2855
2867
  remainder = remainder % current_seconds;
2856
2868
  if (countDecimals(remainder) > 2) {
@@ -2957,7 +2969,7 @@ function unflatten(data) {
2957
2969
  var m = regex.exec(p);
2958
2970
  while (m) {
2959
2971
  cur = cur[prop] || (cur[prop] = m[2] ? [] : {});
2960
- prop = m[2] || m[1];
2972
+ prop = m[2] || m[1] || "";
2961
2973
  m = regex.exec(p);
2962
2974
  }
2963
2975
  cur[prop] = data[p];
@@ -2969,7 +2981,7 @@ function countDecimals(num) {
2969
2981
  if (Math.floor(num) === num || String(num).indexOf(".") < 0)
2970
2982
  return 0;
2971
2983
  var parts = num.toString().split(".")[1];
2972
- return parts.length || 0;
2984
+ return (parts === null || parts === void 0 ? void 0 : parts.length) || 0;
2973
2985
  }
2974
2986
  function formatMessage(functionName, message, CMIElement) {
2975
2987
  var baseLength = 20;
@@ -3646,14 +3658,16 @@ var Scorm12Impl = (function (_super) {
3646
3658
  Scorm12Impl.prototype.validateCorrectResponse = function (_CMIElement, _value) {
3647
3659
  };
3648
3660
  Scorm12Impl.prototype.getLmsErrorMessageDetails = function (errorNumber, detail) {
3661
+ var _a, _b;
3649
3662
  var basicMessage = "No Error";
3650
3663
  var detailMessage = "No Error";
3651
3664
  errorNumber = String(errorNumber);
3652
3665
  if (_constants_api_constants__WEBPACK_IMPORTED_MODULE_4__.scorm12_constants.error_descriptions[errorNumber]) {
3653
3666
  basicMessage =
3654
- _constants_api_constants__WEBPACK_IMPORTED_MODULE_4__.scorm12_constants.error_descriptions[errorNumber].basicMessage;
3667
+ ((_a = _constants_api_constants__WEBPACK_IMPORTED_MODULE_4__.scorm12_constants.error_descriptions[errorNumber]) === null || _a === void 0 ? void 0 : _a.basicMessage) ||
3668
+ "General Error";
3655
3669
  detailMessage =
3656
- _constants_api_constants__WEBPACK_IMPORTED_MODULE_4__.scorm12_constants.error_descriptions[errorNumber].detailMessage;
3670
+ ((_b = _constants_api_constants__WEBPACK_IMPORTED_MODULE_4__.scorm12_constants.error_descriptions[errorNumber]) === null || _b === void 0 ? void 0 : _b.detailMessage) || "";
3657
3671
  }
3658
3672
  return detail ? detailMessage : basicMessage;
3659
3673
  };