@didask/scol-r 2.2.6 → 2.2.9

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.
@@ -4,6 +4,10 @@ export declare class MessageEmitter {
4
4
  private lmsOrigin;
5
5
  constructor(lmsOrigin: string);
6
6
  private sendMessage;
7
+ setStudent({ id, name }: {
8
+ id: string;
9
+ name: string;
10
+ }): void;
7
11
  setLessonStatus(status: string): void;
8
12
  setScore(score: number): void;
9
13
  setObjectives(objectives: string[]): void;
@@ -31,6 +31,9 @@ function MessageReceiver(win, sourceOrigin, adapter) {
31
31
  this.setScore = function (score) {
32
32
  adapter.setScore(score);
33
33
  };
34
+ this.setStudent = function (studentId, studentName) {
35
+ adapter.setStudent(studentId, studentName);
36
+ };
34
37
  this.setLessonStatus = function (lessonStatus) {
35
38
  adapter.setLessonStatus(lessonStatus);
36
39
  };
@@ -62,6 +65,10 @@ var MessageEmitter = /** @class */ (function () {
62
65
  arguments: values,
63
66
  }, this.lmsOrigin);
64
67
  };
68
+ MessageEmitter.prototype.setStudent = function (_a) {
69
+ var id = _a.id, name = _a.name;
70
+ this.sendMessage("setStudent", [id, name]);
71
+ };
65
72
  MessageEmitter.prototype.setLessonStatus = function (status) {
66
73
  this.sendMessage("setLessonStatus", [status]);
67
74
  };
@@ -26,6 +26,8 @@ export declare class SCORMAdapter {
26
26
  };
27
27
  getDataFromLMS(): any;
28
28
  getLearnerId(): any;
29
+ getLearnerName(): any;
30
+ setStudent(studentId: string, studentName: string): void;
29
31
  setScore(score: number): void;
30
32
  getScore(): any;
31
33
  getLessonStatus(): any;
@@ -40,3 +42,5 @@ export declare class SCORMAdapter {
40
42
  setSuspendData(data: string): void;
41
43
  get suspendData(): any;
42
44
  }
45
+ export declare const convertToTimeInterval: (milliseconds: number) => string;
46
+ export declare const convertMsToCMITimespan: (milliseconds: number) => string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SCORMAdapter = void 0;
3
+ exports.convertMsToCMITimespan = exports.convertToTimeInterval = exports.SCORMAdapter = void 0;
4
4
  var SCORMAdapter = /** @class */ (function () {
5
5
  function SCORMAdapter(errorCallback) {
6
6
  var _this = this;
@@ -207,6 +207,22 @@ var SCORMAdapter = /** @class */ (function () {
207
207
  : "cmi.core.student_id";
208
208
  return this.LMSGetValue(CMIVariableName);
209
209
  };
210
+ SCORMAdapter.prototype.getLearnerName = function () {
211
+ var CMIVariableName = this._isSCORM2004
212
+ ? "cmi.learner_name"
213
+ : "cmi.core.student_name";
214
+ return this.LMSGetValue(CMIVariableName);
215
+ };
216
+ SCORMAdapter.prototype.setStudent = function (studentId, studentName) {
217
+ if (this._isSCORM2004) {
218
+ this.LMSSetValue("cmi.learner_id", studentId);
219
+ this.LMSSetValue("cmi.learner_name", studentName);
220
+ }
221
+ else {
222
+ this.LMSSetValue("cmi.core.student_id", studentId);
223
+ this.LMSSetValue("cmi.core.student_name", studentName);
224
+ }
225
+ };
210
226
  SCORMAdapter.prototype.setScore = function (score) {
211
227
  if (this._isSCORM2004) {
212
228
  this.LMSSetValue("cmi.score.raw", score);
@@ -254,11 +270,11 @@ var SCORMAdapter = /** @class */ (function () {
254
270
  };
255
271
  SCORMAdapter.prototype.setSessionTime = function (msSessionTime) {
256
272
  if (this._isSCORM2004) {
257
- var duration = convertToTimeInterval(msSessionTime);
273
+ var duration = exports.convertToTimeInterval(msSessionTime);
258
274
  this.LMSSetValue("cmi.session_time", duration);
259
275
  }
260
276
  else {
261
- var duration = convertMsToCMITimespan(msSessionTime);
277
+ var duration = exports.convertMsToCMITimespan(msSessionTime);
262
278
  this.LMSSetValue("cmi.core.session_time", duration);
263
279
  }
264
280
  };
@@ -336,8 +352,8 @@ var SCORMAdapter = /** @class */ (function () {
336
352
  return SCORMAdapter;
337
353
  }());
338
354
  exports.SCORMAdapter = SCORMAdapter;
339
- // timeinterval (second,10,2),
340
355
  var convertToTimeInterval = function (milliseconds) {
356
+ // timeinterval (second,10,2),
341
357
  var data = getDurationData(milliseconds);
342
358
  var days = data.days;
343
359
  var hours = data.hours % 24;
@@ -351,10 +367,17 @@ var convertToTimeInterval = function (milliseconds) {
351
367
  var hms = [hoursString, minutesString, secondsString].join('');
352
368
  return 'P' + daysString + 'T' + hms;
353
369
  };
370
+ exports.convertToTimeInterval = convertToTimeInterval;
354
371
  var convertMsToCMITimespan = function (milliseconds) {
355
- var _a = getDurationData(milliseconds), seconds = _a.seconds, minutes = _a.minutes, hours = _a.hours;
356
- return hours + ":" + minutes % 60 + ":" + seconds % 60;
372
+ // CMITimespan "0000:00:00.00"
373
+ var _a = getDurationData(milliseconds), seconds = _a.seconds, minutes = _a.minutes, hours = _a.hours, cents = _a.cents;
374
+ var h = pad(hours, 4);
375
+ var m = pad(minutes % 60, 2);
376
+ var s = pad(seconds % 60, 2);
377
+ var c = pad(cents % 100, 2);
378
+ return h + ":" + m + ":" + s + "." + c;
357
379
  };
380
+ exports.convertMsToCMITimespan = convertMsToCMITimespan;
358
381
  var getDurationData = function (milliseconds) {
359
382
  var cents = Math.floor(milliseconds / 10);
360
383
  var seconds = Math.floor(milliseconds / 1000);
@@ -363,3 +386,10 @@ var getDurationData = function (milliseconds) {
363
386
  var days = Math.floor(hours / 24);
364
387
  return { days: days, hours: hours, minutes: minutes, seconds: seconds, cents: cents };
365
388
  };
389
+ var pad = function (value, targetLength) {
390
+ var text = value.toString();
391
+ var padLength = targetLength - text.length;
392
+ if (padLength <= 0)
393
+ return text;
394
+ return "0".repeat(padLength) + text;
395
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var bun_test_1 = require("bun:test");
4
+ var SCORMAdapter_1 = require("./SCORMAdapter");
5
+ bun_test_1.test('convertMsToCMITimespan ("0000:00:00.00")', function () {
6
+ var milliseconds = (36 * 60 * 60 * 1000) + (6 * 60 * 1000) + (2 * 1000) + (23 * 10);
7
+ var CMITimespan = SCORMAdapter_1.convertMsToCMITimespan(milliseconds);
8
+ bun_test_1.expect(CMITimespan).toBe('0036:06:02.23');
9
+ });
10
+ bun_test_1.test('convertToTimeInterval', function () {
11
+ var milliseconds = (36 * 60 * 60 * 1000) + (6 * 60 * 1000) + (2 * 1000) + (23 * 10);
12
+ var timeInterval = SCORMAdapter_1.convertToTimeInterval(milliseconds);
13
+ bun_test_1.expect(timeInterval).toBe('P1DT12H6M2');
14
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@didask/scol-r",
3
- "version": "2.2.6",
3
+ "version": "2.2.9",
4
4
  "description": "Shareable Cross-Origin Learning Resources",
5
5
  "main": "index.html",
6
6
  "types": "lib/index.d.ts",