Fixing eslint issues, and still working on test cases
This commit is contained in:
169
src/BaseAPI.js
169
src/BaseAPI.js
@@ -134,7 +134,7 @@ export default class BaseAPI {
|
||||
* @param {string} callbackName
|
||||
* @param {boolean} checkTerminated
|
||||
* @param {string} CMIElement
|
||||
* @param {any} value
|
||||
* @param {*} value
|
||||
* @return {string}
|
||||
*/
|
||||
setValue(
|
||||
@@ -204,7 +204,7 @@ export default class BaseAPI {
|
||||
* Returns the errorNumber error description
|
||||
*
|
||||
* @param {string} callbackName
|
||||
* @param {number} CMIErrorCode
|
||||
* @param {(string|number)} CMIErrorCode
|
||||
* @return {string}
|
||||
*/
|
||||
getErrorString(callbackName: String, CMIErrorCode) {
|
||||
@@ -224,8 +224,8 @@ export default class BaseAPI {
|
||||
/**
|
||||
* Returns a comprehensive description of the errorNumber error.
|
||||
*
|
||||
* @param callbackName
|
||||
* @param CMIErrorCode
|
||||
* @param {string} callbackName
|
||||
* @param {(string|number)} CMIErrorCode
|
||||
* @return {string}
|
||||
*/
|
||||
getDiagnostic(callbackName: String, CMIErrorCode) {
|
||||
@@ -243,10 +243,16 @@ export default class BaseAPI {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the LMS state and ensures it has been initialized
|
||||
* Checks the LMS state and ensures it has been initialized.
|
||||
*
|
||||
* @param {boolean} checkTerminated
|
||||
* @param {number} beforeInitError
|
||||
* @param {number} afterTermError
|
||||
* @return {boolean}
|
||||
*/
|
||||
checkState(
|
||||
checkTerminated: boolean, beforeInitError: number,
|
||||
checkTerminated: boolean,
|
||||
beforeInitError: number,
|
||||
afterTermError?: number) {
|
||||
if (_self.isNotInitialized()) {
|
||||
_self.throwSCORMError(beforeInitError);
|
||||
@@ -262,13 +268,15 @@ export default class BaseAPI {
|
||||
/**
|
||||
* Logging for all SCORM actions
|
||||
*
|
||||
* @param functionName
|
||||
* @param CMIElement
|
||||
* @param logMessage
|
||||
* @param messageLevel
|
||||
* @param {string} functionName
|
||||
* @param {string} CMIElement
|
||||
* @param {string} logMessage
|
||||
* @param {number}messageLevel
|
||||
*/
|
||||
apiLog(
|
||||
functionName: String, CMIElement: String, logMessage: String,
|
||||
functionName: String,
|
||||
CMIElement: String,
|
||||
logMessage: String,
|
||||
messageLevel: number) {
|
||||
logMessage = _self.formatMessage(functionName, CMIElement, logMessage);
|
||||
|
||||
@@ -287,21 +295,12 @@ export default class BaseAPI {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the last SCORM error code on success
|
||||
*/
|
||||
clearSCORMError(success: String) {
|
||||
if (success !== api_constants.SCORM_FALSE) {
|
||||
_self.lastErrorCode = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the SCORM messages for easy reading
|
||||
*
|
||||
* @param functionName
|
||||
* @param CMIElement
|
||||
* @param message
|
||||
* @param {string} functionName
|
||||
* @param {string} CMIElement
|
||||
* @param {string} message
|
||||
* @return {string}
|
||||
*/
|
||||
formatMessage(functionName: String, CMIElement: String, message: String) {
|
||||
@@ -340,8 +339,9 @@ export default class BaseAPI {
|
||||
/**
|
||||
* Checks to see if {str} contains {tester}
|
||||
*
|
||||
* @param str String to check against
|
||||
* @param tester String to check for
|
||||
* @param {string} str String to check against
|
||||
* @param {string} tester String to check for
|
||||
* @return {boolean}
|
||||
*/
|
||||
stringContains(str: String, tester: String) {
|
||||
return str.indexOf(tester) > -1;
|
||||
@@ -350,6 +350,10 @@ export default class BaseAPI {
|
||||
/**
|
||||
* Returns the message that corresponds to errorNumber
|
||||
* APIs that inherit BaseAPI should override this function
|
||||
*
|
||||
* @param {(string|number)} _errorNumber
|
||||
* @param {boolean} _detail
|
||||
* @return {string}
|
||||
*/
|
||||
getLmsErrorMessageDetails(_errorNumber, _detail) {
|
||||
return 'No error';
|
||||
@@ -358,6 +362,9 @@ export default class BaseAPI {
|
||||
/**
|
||||
* Gets the value for the specific element.
|
||||
* APIs that inherit BaseAPI should override this function
|
||||
*
|
||||
* @param {string} _CMIElement
|
||||
* @return {string}
|
||||
*/
|
||||
getCMIValue(_CMIElement) {
|
||||
return '';
|
||||
@@ -366,11 +373,24 @@ export default class BaseAPI {
|
||||
/**
|
||||
* Sets the value for the specific element.
|
||||
* APIs that inherit BaseAPI should override this function
|
||||
*
|
||||
* @param {string} _CMIElement
|
||||
* @param {any} _value
|
||||
*/
|
||||
setCMIValue(_CMIElement, _value) {
|
||||
return '';
|
||||
// just a stub method
|
||||
}
|
||||
|
||||
/**
|
||||
* Shared API method to set a valid for a given element.
|
||||
*
|
||||
* @param {string} methodName
|
||||
* @param {boolean} scorm2004
|
||||
* @param {string} CMIElement
|
||||
* @param {*} value
|
||||
* @return {string}
|
||||
* @private
|
||||
*/
|
||||
_commonSetCMIValue(
|
||||
methodName: String, scorm2004: boolean, CMIElement, value) {
|
||||
if (!CMIElement || CMIElement === '') {
|
||||
@@ -393,7 +413,7 @@ export default class BaseAPI {
|
||||
if (scorm2004 && (attribute.substr(0, 8) === '{target=') &&
|
||||
(typeof refObject._isTargetValid == 'function')) {
|
||||
_self.throwSCORMError(_self.#error_codes.READ_ONLY_ELEMENT);
|
||||
} else if (!refObject.hasOwnProperty(attribute)) {
|
||||
} else if (!{}.hasOwnProperty.call(refObject, attribute)) {
|
||||
_self.throwSCORMError(invalidErrorCode, invalidErrorMessage);
|
||||
} else {
|
||||
if (_self.stringContains(CMIElement, '.correct_responses')) {
|
||||
@@ -412,7 +432,7 @@ export default class BaseAPI {
|
||||
break;
|
||||
}
|
||||
|
||||
if (refObject.prototype === CMIArray) {
|
||||
if (refObject instanceof CMIArray) {
|
||||
const index = parseInt(structure[i + 1], 10);
|
||||
|
||||
// SCO is trying to set an item on an array
|
||||
@@ -448,24 +468,34 @@ export default class BaseAPI {
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract method for validating that a response is correct.
|
||||
*
|
||||
* @param {string} _CMIElement
|
||||
* @param {*} _value
|
||||
*/
|
||||
validateCorrectResponse(_CMIElement, _value) {
|
||||
return false;
|
||||
// just a stub method
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets or builds a new child element to add to the array.
|
||||
* APIs that inherit BaseAPI should override this method
|
||||
* APIs that inherit BaseAPI should override this method.
|
||||
*
|
||||
* @param {string} _CMIElement - unused
|
||||
* @param {*} _value - unused
|
||||
* @return {*}
|
||||
*/
|
||||
getChildElement(_CMIElement) {
|
||||
getChildElement(_CMIElement, _value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a value from the CMI Object
|
||||
*
|
||||
* @param methodName
|
||||
* @param scorm2004
|
||||
* @param CMIElement
|
||||
* @param {string} methodName
|
||||
* @param {boolean} scorm2004
|
||||
* @param {string} CMIElement
|
||||
* @return {*}
|
||||
*/
|
||||
_commonGetCMIValue(methodName: String, scorm2004: boolean, CMIElement) {
|
||||
@@ -482,7 +512,7 @@ export default class BaseAPI {
|
||||
|
||||
if (!scorm2004) {
|
||||
if (i === structure.length - 1) {
|
||||
if (!refObject.hasOwnProperty(attribute)) {
|
||||
if (!{}.hasOwnProperty.call(refObject, attribute)) {
|
||||
_self.throwSCORMError(101,
|
||||
'getCMIValue did not find a value for: ' + CMIElement);
|
||||
}
|
||||
@@ -493,7 +523,7 @@ export default class BaseAPI {
|
||||
const target = String(attribute).
|
||||
substr(8, String(attribute).length - 9);
|
||||
return refObject._isTargetValid(target);
|
||||
} else if (!refObject.hasOwnProperty(attribute)) {
|
||||
} else if (!{}.hasOwnProperty.call(refObject, attribute)) {
|
||||
_self.throwSCORMError(401,
|
||||
'The data model element passed to GetValue (' + CMIElement +
|
||||
') is not a valid SCORM data model element.');
|
||||
@@ -520,6 +550,8 @@ export default class BaseAPI {
|
||||
|
||||
/**
|
||||
* Returns true if the API's current state is STATE_INITIALIZED
|
||||
*
|
||||
* @return {boolean}
|
||||
*/
|
||||
isInitialized() {
|
||||
return _self.currentState === api_constants.STATE_INITIALIZED;
|
||||
@@ -527,6 +559,8 @@ export default class BaseAPI {
|
||||
|
||||
/**
|
||||
* Returns true if the API's current state is STATE_NOT_INITIALIZED
|
||||
*
|
||||
* @return {boolean}
|
||||
*/
|
||||
isNotInitialized() {
|
||||
return _self.currentState === api_constants.STATE_NOT_INITIALIZED;
|
||||
@@ -534,6 +568,8 @@ export default class BaseAPI {
|
||||
|
||||
/**
|
||||
* Returns true if the API's current state is STATE_TERMINATED
|
||||
*
|
||||
* @return {boolean}
|
||||
*/
|
||||
isTerminated() {
|
||||
return _self.currentState === api_constants.STATE_TERMINATED;
|
||||
@@ -542,8 +578,8 @@ export default class BaseAPI {
|
||||
/**
|
||||
* Provides a mechanism for attaching to a specific SCORM event
|
||||
*
|
||||
* @param listenerName
|
||||
* @param callback
|
||||
* @param {string} listenerName
|
||||
* @param {function} callback
|
||||
*/
|
||||
on(listenerName: String, callback: function) {
|
||||
if (!callback) return;
|
||||
@@ -571,9 +607,9 @@ export default class BaseAPI {
|
||||
/**
|
||||
* Processes any 'on' listeners that have been created
|
||||
*
|
||||
* @param functionName
|
||||
* @param CMIElement
|
||||
* @param value
|
||||
* @param {string} functionName
|
||||
* @param {string} CMIElement
|
||||
* @param {*} value
|
||||
*/
|
||||
processListeners(functionName: String, CMIElement: String, value: any) {
|
||||
for (let i = 0; i < _self.listenerArray.length; i++) {
|
||||
@@ -591,8 +627,8 @@ export default class BaseAPI {
|
||||
/**
|
||||
* Throws a SCORM error
|
||||
*
|
||||
* @param errorNumber
|
||||
* @param message
|
||||
* @param {number} errorNumber
|
||||
* @param {string} message
|
||||
*/
|
||||
throwSCORMError(errorNumber: number, message: String) {
|
||||
if (!message) {
|
||||
@@ -605,20 +641,34 @@ export default class BaseAPI {
|
||||
_self.lastErrorCode = String(errorNumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the last SCORM error code on success.
|
||||
*
|
||||
* @param {string} success
|
||||
*/
|
||||
clearSCORMError(success: String) {
|
||||
if (success !== api_constants.SCORM_FALSE) {
|
||||
_self.lastErrorCode = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads CMI data from a JSON object.
|
||||
*
|
||||
* @param {object} json
|
||||
* @param {string} CMIElement
|
||||
*/
|
||||
loadFromJSON(json, CMIElement) {
|
||||
if (!_self.isNotInitialized()) {
|
||||
console.error(
|
||||
'loadFromJSON can only be called before the call to LMSInitialize.');
|
||||
'loadFromJSON can only be called before the call to lmsInitialize.');
|
||||
return;
|
||||
}
|
||||
|
||||
CMIElement = CMIElement || 'cmi';
|
||||
|
||||
for (const key in json) {
|
||||
if (json.hasOwnProperty(key) && json[key]) {
|
||||
if ({}.hasOwnProperty.call(json, key) && json[key]) {
|
||||
const currentCMIElement = CMIElement + '.' + key;
|
||||
const value = json[key];
|
||||
|
||||
@@ -636,6 +686,11 @@ export default class BaseAPI {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the CMI object to JSON for sending to an LMS.
|
||||
*
|
||||
* @return {string}
|
||||
*/
|
||||
renderCMIToJSON() {
|
||||
const cmi = _self.cmi;
|
||||
// Do we want/need to return fields that have no set value?
|
||||
@@ -646,8 +701,8 @@ export default class BaseAPI {
|
||||
/**
|
||||
* Check if the value matches the proper format. If not, throw proper error code.
|
||||
*
|
||||
* @param value
|
||||
* @param regexPattern
|
||||
* @param {string} value
|
||||
* @param {string} regexPattern
|
||||
* @return {boolean}
|
||||
*/
|
||||
checkValidFormat(value: String, regexPattern: String) {
|
||||
@@ -662,8 +717,8 @@ export default class BaseAPI {
|
||||
/**
|
||||
* Check if the value matches the proper range. If not, throw proper error code.
|
||||
*
|
||||
* @param value
|
||||
* @param rangePattern
|
||||
* @param {*} value
|
||||
* @param {string} rangePattern
|
||||
* @return {boolean}
|
||||
*/
|
||||
checkValidRange(value: any, rangePattern: String) {
|
||||
@@ -686,7 +741,7 @@ export default class BaseAPI {
|
||||
/**
|
||||
* Throws a SCORM error
|
||||
*
|
||||
* @param when the number of milliseconds to wait before committing
|
||||
* @param {number} when - the number of milliseconds to wait before committing
|
||||
*/
|
||||
scheduleCommit(when: number) {
|
||||
_self.#timeout = new ScheduledCommit(this, when);
|
||||
@@ -703,16 +758,27 @@ export default class BaseAPI {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Private class that wraps a timeout call to the commit() function
|
||||
*/
|
||||
class ScheduledCommit {
|
||||
#API;
|
||||
#cancelled: false;
|
||||
#timeout;
|
||||
|
||||
/**
|
||||
* Constructor for ScheduledCommit
|
||||
* @param {BaseAPI} API
|
||||
* @param {number} when
|
||||
*/
|
||||
constructor(API: any, when: number) {
|
||||
_self.#API = API;
|
||||
_self.#timeout = setTimeout(_self.#wrapper, when);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel any currently scheduled commit
|
||||
*/
|
||||
cancel() {
|
||||
_self.#cancelled = true;
|
||||
if (_self.#timeout) {
|
||||
@@ -720,6 +786,9 @@ class ScheduledCommit {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap the API commit call to check if the call has already been cancelled
|
||||
*/
|
||||
#wrapper = () => {
|
||||
if (!_self.#cancelled) {
|
||||
_self.#API.commit();
|
||||
|
||||
@@ -13,134 +13,170 @@ import {scorm12_error_codes} from './constants/error_codes';
|
||||
import {scorm12_regex} from './regex';
|
||||
|
||||
const constants = scorm12_constants;
|
||||
let _self;
|
||||
|
||||
/**
|
||||
* API class for SCORM 1.2
|
||||
*/
|
||||
export default class Scorm12API extends BaseAPI {
|
||||
/**
|
||||
* Constructor for SCORM 1.2 API
|
||||
*/
|
||||
constructor() {
|
||||
super(scorm12_error_codes);
|
||||
_self = this;
|
||||
|
||||
this.cmi = new CMI(this);
|
||||
_self.cmi = new CMI(this);
|
||||
// Rename functions to match 1.2 Spec and expose to modules
|
||||
_self.LMSInitialize = _self.lmsInitialize;
|
||||
_self.LMSFinish = _self.lmsFinish;
|
||||
_self.LMSGetValue = _self.lmsGetValue;
|
||||
_self.LMSSetValue = _self.lmsSetValue;
|
||||
_self.LMSCommit = _self.lmsCommit;
|
||||
_self.LMSGetLastError = _self.lmsGetLastError;
|
||||
_self.LMSGetErrorString = _self.lmsGetErrorString;
|
||||
_self.LMSGetDiagnostic = _self.lmsGetDiagnostic;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {string} bool
|
||||
*/
|
||||
LMSInitialize() {
|
||||
return this.initialize('LMSInitialize', 'LMS was already initialized!',
|
||||
* lmsInitialize function from SCORM 1.2 Spec
|
||||
*
|
||||
* @return {string} bool
|
||||
*/
|
||||
lmsInitialize() {
|
||||
return _self.initialize('LMSInitialize', 'LMS was already initialized!',
|
||||
'LMS is already finished!');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {string} bool
|
||||
*/
|
||||
LMSFinish() {
|
||||
return this.terminate('LMSFinish', false);
|
||||
* LMSFinish function from SCORM 1.2 Spec
|
||||
*
|
||||
* @return {string} bool
|
||||
*/
|
||||
lmsFinish() {
|
||||
return _self.terminate('LMSFinish', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CMIElement
|
||||
* @return {string}
|
||||
*/
|
||||
LMSGetValue(CMIElement) {
|
||||
return this.getValue('LMSGetValue', false, CMIElement);
|
||||
* LMSGetValue function from SCORM 1.2 Spec
|
||||
*
|
||||
* @param {string} CMIElement
|
||||
* @return {string}
|
||||
*/
|
||||
lmsGetValue(CMIElement) {
|
||||
return _self.getValue('LMSGetValue', false, CMIElement);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CMIElement
|
||||
* @param value
|
||||
* @return {string}
|
||||
*/
|
||||
LMSSetValue(CMIElement, value) {
|
||||
return this.setValue('LMSSetValue', false, CMIElement, value);
|
||||
* LMSSetValue function from SCORM 1.2 Spec
|
||||
*
|
||||
* @param {string} CMIElement
|
||||
* @param {*} value
|
||||
* @return {string}
|
||||
*/
|
||||
lmsSetValue(CMIElement, value) {
|
||||
return _self.setValue('LMSSetValue', false, CMIElement, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Orders LMS to store all content parameters
|
||||
*
|
||||
* @return {string} bool
|
||||
*/
|
||||
LMSCommit() {
|
||||
return this.commit('LMSCommit', false);
|
||||
* LMSCommit function from SCORM 1.2 Spec
|
||||
*
|
||||
* @return {string} bool
|
||||
*/
|
||||
lmsCommit() {
|
||||
return _self.commit('LMSCommit', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns last error code
|
||||
*
|
||||
* @return {string}
|
||||
*/
|
||||
LMSGetLastError() {
|
||||
return this.getLastError('LMSGetLastError');
|
||||
* LMSGetLastError function from SCORM 1.2 Spec
|
||||
*
|
||||
* @return {string}
|
||||
*/
|
||||
lmsGetLastError() {
|
||||
return _self.getLastError('LMSGetLastError');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the errorNumber error description
|
||||
*
|
||||
* @param CMIErrorCode
|
||||
* @return {string}
|
||||
*/
|
||||
LMSGetErrorString(CMIErrorCode) {
|
||||
return this.getErrorString('LMSGetErrorString', CMIErrorCode);
|
||||
* LMSGetErrorString function from SCORM 1.2 Spec
|
||||
*
|
||||
* @param {string} CMIErrorCode
|
||||
* @return {string}
|
||||
*/
|
||||
lmsGetErrorString(CMIErrorCode) {
|
||||
return _self.getErrorString('LMSGetErrorString', CMIErrorCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a comprehensive description of the errorNumber error.
|
||||
*
|
||||
* @param CMIErrorCode
|
||||
* @return {string}
|
||||
*/
|
||||
LMSGetDiagnostic(CMIErrorCode) {
|
||||
return this.getDiagnostic('LMSGetDiagnostic', CMIErrorCode);
|
||||
* LMSGetDiagnostic function from SCORM 1.2 Spec
|
||||
*
|
||||
* @param {string} CMIErrorCode
|
||||
* @return {string}
|
||||
*/
|
||||
lmsGetDiagnostic(CMIErrorCode) {
|
||||
return _self.getDiagnostic('LMSGetDiagnostic', CMIErrorCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a value on the CMI Object
|
||||
*
|
||||
* @param CMIElement
|
||||
* @param value
|
||||
* @return {string}
|
||||
*/
|
||||
* Sets a value on the CMI Object
|
||||
*
|
||||
* @param {string} CMIElement
|
||||
* @param {*} value
|
||||
*/
|
||||
setCMIValue(CMIElement, value) {
|
||||
this._commonSetCMIValue('LMSSetValue', false, CMIElement, value);
|
||||
_self._commonSetCMIValue('LMSSetValue', false, CMIElement, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a value from the CMI Object
|
||||
*
|
||||
* @param CMIElement
|
||||
* @return {*}
|
||||
*/
|
||||
* Gets a value from the CMI Object
|
||||
*
|
||||
* @param {string} CMIElement
|
||||
* @return {*}
|
||||
*/
|
||||
getCMIValue(CMIElement) {
|
||||
return this._commonGetCMIValue('getCMIValue', false, CMIElement);
|
||||
return _self._commonGetCMIValue('getCMIValue', false, CMIElement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets or builds a new child element to add to the array.
|
||||
*
|
||||
* @param CMIElement
|
||||
* @param value
|
||||
* @param {string} CMIElement
|
||||
* @param {*} value
|
||||
* @return {object}
|
||||
*/
|
||||
getChildElement(CMIElement, value) {
|
||||
let newChild;
|
||||
|
||||
if (this.stringContains(CMIElement, 'cmi.objectives')) {
|
||||
if (_self.stringContains(CMIElement, 'cmi.objectives')) {
|
||||
newChild = new CMIObjectivesObject(this);
|
||||
} else if (this.stringContains(CMIElement, '.correct_responses')) {
|
||||
} else if (_self.stringContains(CMIElement, '.correct_responses')) {
|
||||
newChild = new CMIInteractionsCorrectResponsesObject(this);
|
||||
} else if (this.stringContains(CMIElement, '.objectives')) {
|
||||
} else if (_self.stringContains(CMIElement, '.objectives')) {
|
||||
newChild = new CMIInteractionsObjectivesObject(this);
|
||||
} else if (this.stringContains(CMIElement, 'cmi.interactions')) {
|
||||
} else if (_self.stringContains(CMIElement, 'cmi.interactions')) {
|
||||
newChild = new CMIInteractionsObject(this);
|
||||
}
|
||||
|
||||
return newChild;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates Correct Response values
|
||||
*
|
||||
* @param {string} CMIElement
|
||||
* @param {*} value
|
||||
* @return {boolean}
|
||||
*/
|
||||
validateCorrectResponse(CMIElement, value) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the message that corresponds to errorNumber.
|
||||
*/
|
||||
* Returns the message that corresponds to errorNumber.
|
||||
*
|
||||
* @param {*} errorNumber
|
||||
* @param {boolean }detail
|
||||
* @return {string}
|
||||
*/
|
||||
getLmsErrorMessageDetails(errorNumber, detail) {
|
||||
let basicMessage = 'No Error';
|
||||
let detailMessage = 'No Error';
|
||||
@@ -156,25 +192,26 @@ export default class Scorm12API extends BaseAPI {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the current session time to the existing total time.
|
||||
*/
|
||||
* Adds the current session time to the existing total time.
|
||||
*
|
||||
* @return {string}
|
||||
*/
|
||||
getCurrentTotalTime() {
|
||||
const timeRegex = new RegExp(scorm12_regex.CMITime);
|
||||
|
||||
const totalTime = this.cmi.core.total_time;
|
||||
const sessionTime = this.cmi.core.session_time;
|
||||
const totalTime = _self.cmi.core.total_time;
|
||||
const sessionTime = _self.cmi.core.session_time;
|
||||
|
||||
const totalSeconds = Utilities.getTimeAsSeconds(totalTime, timeRegex);
|
||||
const sessionSeconds = Utilities.getTimeAsSeconds(sessionTime, timeRegex);
|
||||
|
||||
return Utilities.getSecondsAsHHMMSS(totalSeconds + sessionSeconds);
|
||||
return Utilities.addHHMMSSTimeStrings(totalTime, sessionTime, timeRegex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the whole API with another
|
||||
*/
|
||||
* Replace the whole API with another
|
||||
*
|
||||
* @param {Scorm12API} newAPI
|
||||
*/
|
||||
replaceWithAnotherScormAPI(newAPI) {
|
||||
// Data Model
|
||||
this.cmi = newAPI.cmi;
|
||||
_self.cmi = newAPI.cmi;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ let _self;
|
||||
* API class for SCORM 2004
|
||||
*/
|
||||
class Scorm2004API extends BaseAPI {
|
||||
version: '1.0';
|
||||
#version: '1.0';
|
||||
|
||||
/**
|
||||
* Constructor for SCORM 2004 API
|
||||
@@ -36,28 +36,36 @@ class Scorm2004API extends BaseAPI {
|
||||
_self.cmi = new CMI(_self);
|
||||
_self.adl = new ADL(_self);
|
||||
|
||||
// Rename functions to match 2004 Spec
|
||||
_self.Initialize = _self.LMSInitialize;
|
||||
_self.Terminate = _self.LMSTerminate;
|
||||
_self.GetValue = _self.LMSGetValue;
|
||||
_self.SetValue = _self.LMSSetValue;
|
||||
_self.Commit = _self.LMSCommit;
|
||||
_self.GetLastError = _self.LMSGetLastError;
|
||||
_self.GetErrorString = _self.LMSGetErrorString;
|
||||
_self.GetDiagnostic = _self.LMSGetDiagnostic;
|
||||
// Rename functions to match 2004 Spec and expose to modules
|
||||
_self.Initialize = _self.lmsInitialize;
|
||||
_self.Terminate = _self.lmsTerminate;
|
||||
_self.GetValue = _self.lmsGetValue;
|
||||
_self.SetValue = _self.lmsSetValue;
|
||||
_self.Commit = _self.lmsCommit;
|
||||
_self.GetLastError = _self.lmsGetLastError;
|
||||
_self.GetErrorString = _self.lmsGetErrorString;
|
||||
_self.GetDiagnostic = _self.lmsGetDiagnostic;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for #version
|
||||
* @return {string}
|
||||
*/
|
||||
get version() {
|
||||
return this.#version;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {string} bool
|
||||
*/
|
||||
LMSInitialize() {
|
||||
lmsInitialize() {
|
||||
return _self.initialize('Initialize');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {string} bool
|
||||
*/
|
||||
LMSTerminate() {
|
||||
lmsTerminate() {
|
||||
return _self.terminate('Terminate', true);
|
||||
}
|
||||
|
||||
@@ -65,7 +73,7 @@ class Scorm2004API extends BaseAPI {
|
||||
* @param {string} CMIElement
|
||||
* @return {string}
|
||||
*/
|
||||
LMSGetValue(CMIElement) {
|
||||
lmsGetValue(CMIElement) {
|
||||
return _self.getValue('GetValue', true, CMIElement);
|
||||
}
|
||||
|
||||
@@ -74,7 +82,7 @@ class Scorm2004API extends BaseAPI {
|
||||
* @param {any} value
|
||||
* @return {string}
|
||||
*/
|
||||
LMSSetValue(CMIElement, value) {
|
||||
lmsSetValue(CMIElement, value) {
|
||||
return _self.setValue('SetValue', true, CMIElement, value);
|
||||
}
|
||||
|
||||
@@ -83,7 +91,7 @@ class Scorm2004API extends BaseAPI {
|
||||
*
|
||||
* @return {string} bool
|
||||
*/
|
||||
LMSCommit() {
|
||||
lmsCommit() {
|
||||
return _self.commit('Commit');
|
||||
}
|
||||
|
||||
@@ -92,27 +100,27 @@ class Scorm2004API extends BaseAPI {
|
||||
*
|
||||
* @return {string}
|
||||
*/
|
||||
LMSGetLastError() {
|
||||
lmsGetLastError() {
|
||||
return _self.getLastError('GetLastError');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the errorNumber error description
|
||||
*
|
||||
* @param CMIErrorCode
|
||||
* @param {(string|number)} CMIErrorCode
|
||||
* @return {string}
|
||||
*/
|
||||
LMSGetErrorString(CMIErrorCode) {
|
||||
lmsGetErrorString(CMIErrorCode) {
|
||||
return _self.getErrorString('GetErrorString', CMIErrorCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a comprehensive description of the errorNumber error.
|
||||
*
|
||||
* @param CMIErrorCode
|
||||
* @param {(string|number)} CMIErrorCode
|
||||
* @return {string}
|
||||
*/
|
||||
LMSGetDiagnostic(CMIErrorCode) {
|
||||
lmsGetDiagnostic(CMIErrorCode) {
|
||||
return _self.getDiagnostic('GetDiagnostic', CMIErrorCode);
|
||||
}
|
||||
|
||||
@@ -160,7 +168,7 @@ class Scorm2004API extends BaseAPI {
|
||||
const response_type = correct_responses[interaction_type];
|
||||
let nodes = [];
|
||||
if (response_type.delimiter !== '') {
|
||||
nodes = value.split(response_type.delimiter);
|
||||
nodes = String(value).split(response_type.delimiter);
|
||||
} else {
|
||||
nodes[0] = value;
|
||||
}
|
||||
@@ -191,7 +199,7 @@ class Scorm2004API extends BaseAPI {
|
||||
/**
|
||||
* Validate correct response.
|
||||
* @param {string} CMIElement
|
||||
* @param {any} value
|
||||
* @param {*} value
|
||||
*/
|
||||
validateCorrectResponse(CMIElement, value) {
|
||||
const parts = CMIElement.split('.');
|
||||
@@ -215,7 +223,7 @@ class Scorm2004API extends BaseAPI {
|
||||
response_type.limit) {
|
||||
let nodes = [];
|
||||
if (response_type.delimiter !== '') {
|
||||
nodes = value.split(response_type.delimiter);
|
||||
nodes = String(value).split(response_type.delimiter);
|
||||
} else {
|
||||
nodes[0] = value;
|
||||
}
|
||||
@@ -258,8 +266,8 @@ class Scorm2004API extends BaseAPI {
|
||||
/**
|
||||
* Returns the message that corresponds to errorNumber.
|
||||
*
|
||||
* @param {string,number} errorNumber
|
||||
* @param {string} detail
|
||||
* @param {(string|number)} errorNumber
|
||||
* @param {boolean} detail
|
||||
* @return {string}
|
||||
*/
|
||||
getLmsErrorMessageDetails(errorNumber, detail) {
|
||||
@@ -276,6 +284,13 @@ class Scorm2004API extends BaseAPI {
|
||||
return detail ? detailMessage : basicMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if a correct_response value has been duplicated
|
||||
* @param {CMIArray} correct_response
|
||||
* @param {number} current_index
|
||||
* @param {*} value
|
||||
* @return {boolean}
|
||||
*/
|
||||
#checkDuplicatedPattern = (correct_response, current_index, value) => {
|
||||
let found = false;
|
||||
const count = correct_response._count;
|
||||
@@ -287,6 +302,12 @@ class Scorm2004API extends BaseAPI {
|
||||
return found;
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks for a valid correct_response value
|
||||
* @param {string} interaction_type
|
||||
* @param {Array} nodes
|
||||
* @param {*} value
|
||||
*/
|
||||
#checkCorrectResponseValue = (interaction_type, nodes, value) => {
|
||||
const response = correct_responses[interaction_type];
|
||||
const formatRegex = new RegExp(response.format);
|
||||
@@ -334,6 +355,11 @@ class Scorm2004API extends BaseAPI {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove prefixes from correct_response
|
||||
* @param {string} node
|
||||
* @return {*}
|
||||
*/
|
||||
#removeCorrectResponsePrefixes = (node) => {
|
||||
let seenOrder = false;
|
||||
let seenCase = false;
|
||||
@@ -404,11 +430,7 @@ class Scorm2004API extends BaseAPI {
|
||||
const totalTime = _self.cmi.total_time;
|
||||
const sessionTime = _self.cmi.session_time;
|
||||
|
||||
const durationRegex = scorm2004_regex.CMITimespan;
|
||||
const totalSeconds = Util.getDurationAsSeconds(totalTime, durationRegex);
|
||||
const sessionSeconds = Util.getDurationAsSeconds(sessionTime,
|
||||
durationRegex);
|
||||
|
||||
return Util.getSecondsAsISODuration(totalSeconds + sessionSeconds);
|
||||
return Util.addTwoDurations(totalTime, sessionTime,
|
||||
scorm2004_regex.CMITimespan);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,17 +39,18 @@ class CMIEvaluation extends BaseCMI {
|
||||
*/
|
||||
constructor(API) {
|
||||
super(API);
|
||||
}
|
||||
|
||||
comments = new class extends CMIArray {
|
||||
/**
|
||||
* Constructor for AICC Evaluation Comments object
|
||||
* @param {AICC} API
|
||||
*/
|
||||
constructor(API) {
|
||||
super(API, constants.comments_children, 402);
|
||||
}
|
||||
};
|
||||
this.comments = new class extends CMIArray {
|
||||
/**
|
||||
* Constructor for AICC Evaluation Comments object
|
||||
* @param {AICC} API
|
||||
*/
|
||||
constructor(API) {
|
||||
super(API, constants.comments_children,
|
||||
scorm12_error_codes.INVALID_SET_VALUE);
|
||||
}
|
||||
}(API);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,6 +63,16 @@ class AICCCMIStudentData extends Scorm12CMI.CMIStudentData {
|
||||
*/
|
||||
constructor(API) {
|
||||
super(API, constants.student_data_children);
|
||||
|
||||
this.tries = new class extends CMIArray {
|
||||
/**
|
||||
* Constructor for inline Tries Array class
|
||||
* @param {AICC} API
|
||||
*/
|
||||
constructor(API) {
|
||||
super(API, aicc_constants.tries_children);
|
||||
}
|
||||
}(API);
|
||||
}
|
||||
|
||||
#tries_during_lesson = '';
|
||||
@@ -84,34 +95,20 @@ class AICCCMIStudentData extends Scorm12CMI.CMIStudentData {
|
||||
this.#tries_during_lesson = tries_during_lesson :
|
||||
throwReadOnlyError();
|
||||
}
|
||||
|
||||
tries = new class extends CMIArray {
|
||||
/**
|
||||
* Constructor for inline Tries Array class
|
||||
* @param {AICC} API
|
||||
*/
|
||||
constructor(API) {
|
||||
super(API, aicc_constants.tries_children);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
let _self;
|
||||
|
||||
/**
|
||||
* Class for AICC Tries
|
||||
*/
|
||||
export class CMITriesObject extends BaseCMI {
|
||||
#API;
|
||||
|
||||
/**
|
||||
* Constructor for AICC Tries object
|
||||
* @param {AICC} API
|
||||
*/
|
||||
constructor(API) {
|
||||
super(API);
|
||||
this.#API = API;
|
||||
_self = this;
|
||||
|
||||
this.score = new CMIScore(API);
|
||||
}
|
||||
|
||||
#status = '';
|
||||
@@ -152,8 +149,6 @@ export class CMITriesObject extends BaseCMI {
|
||||
this.#time = time;
|
||||
}
|
||||
}
|
||||
|
||||
score = new CMIScore(_self.#API);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -246,7 +241,9 @@ export class NAV extends BaseCMI {
|
||||
* @return {string}
|
||||
*/
|
||||
get event() {
|
||||
return (!this.jsonString) ? this.API.throwSCORMError(404) : this.#event;
|
||||
return (!this.jsonString) ?
|
||||
this.API.throwSCORMError(scorm12_error_codes.WRITE_ONLY_ELEMENT) :
|
||||
this.#event;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,78 +1,154 @@
|
||||
// @flow
|
||||
import {scorm12_constants} from '../constants/api_constants';
|
||||
import {scorm12_error_codes} from '../constants/error_codes';
|
||||
|
||||
/**
|
||||
* Base class for API cmi objects
|
||||
*/
|
||||
export class BaseCMI {
|
||||
jsonString = false;
|
||||
API;
|
||||
jsonString = false;
|
||||
API;
|
||||
|
||||
constructor(API: any) {
|
||||
this.API = API;
|
||||
}
|
||||
/**
|
||||
* Constructor for base cmi
|
||||
* @param {BaseAPI} API
|
||||
*/
|
||||
constructor(API: any) {
|
||||
this.API = API;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Base class for cmi *.score objects
|
||||
*/
|
||||
export class CMIScore extends BaseCMI {
|
||||
/**
|
||||
* Constructor for *.score
|
||||
* @param {BaseAPI} API
|
||||
* @param {string} score_children
|
||||
* @param {string} score_range
|
||||
* @param {number} invalidErrorCode
|
||||
*/
|
||||
constructor(API, score_children?, score_range?, invalidErrorCode) {
|
||||
super(API);
|
||||
|
||||
this.#_children = score_children? score_children : scorm12_constants.score_children;
|
||||
this.#_score_range = score_range? score_range : false;
|
||||
this.#_invalid_error_code = invalidErrorCode ? invalidErrorCode : scorm12_error_codes.INVALID_SET_VALUE;
|
||||
this.#_children = score_children ?
|
||||
score_children :
|
||||
scorm12_constants.score_children;
|
||||
this.#_score_range = score_range ? score_range : false;
|
||||
this.#_invalid_error_code = invalidErrorCode ?
|
||||
invalidErrorCode :
|
||||
scorm12_error_codes.INVALID_SET_VALUE;
|
||||
}
|
||||
|
||||
#_children;
|
||||
#_score_range;
|
||||
#_invalid_error_code;
|
||||
#raw = '';
|
||||
#min = '';
|
||||
#max = '100';
|
||||
#_children;
|
||||
#_score_range;
|
||||
#_invalid_error_code;
|
||||
#raw = '';
|
||||
#min = '';
|
||||
#max = '100';
|
||||
|
||||
get _children() {
|
||||
return this.#_children;
|
||||
}
|
||||
set _children(_children) {
|
||||
this.API.throwSCORMError(this.#_invalid_error_code);
|
||||
}
|
||||
/**
|
||||
* Getter for _children
|
||||
* @return {string}
|
||||
* @private
|
||||
*/
|
||||
get _children() {
|
||||
return this.#_children;
|
||||
}
|
||||
|
||||
get raw() {
|
||||
return this.#raw;
|
||||
}
|
||||
set raw(raw) {
|
||||
if (this.API.checkValidFormat(raw, scorm12_constants.CMIDecimal) &&
|
||||
(!this.#_score_range || this.API.checkValidRange(raw, this.#_score_range))) {
|
||||
this.#raw = raw;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Setter for _children. Just throws an error.
|
||||
* @param {string} _children
|
||||
* @private
|
||||
*/
|
||||
set _children(_children) {
|
||||
this.API.throwSCORMError(this.#_invalid_error_code);
|
||||
}
|
||||
|
||||
get min() {
|
||||
return this.#min;
|
||||
}
|
||||
set min(min) {
|
||||
if (this.API.checkValidFormat(min, scorm12_constants.CMIDecimal) &&
|
||||
(!this.#_score_range || this.API.checkValidRange(min, this.#_score_range))) {
|
||||
this.#min = min;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Getter for #raw
|
||||
* @return {string}
|
||||
*/
|
||||
get raw() {
|
||||
return this.#raw;
|
||||
}
|
||||
|
||||
get max() {
|
||||
return this.#max;
|
||||
}
|
||||
set max(max) {
|
||||
if (this.API.checkValidFormat(max, scorm12_constants.CMIDecimal) &&
|
||||
(!this.#_score_range || this.API.checkValidRange(max, this.#_score_range))) {
|
||||
this.#max = max;
|
||||
}
|
||||
/**
|
||||
* Setter for #raw
|
||||
* @param {string} raw
|
||||
*/
|
||||
set raw(raw) {
|
||||
if (this.API.checkValidFormat(raw, scorm12_constants.CMIDecimal) &&
|
||||
(!this.#_score_range ||
|
||||
this.API.checkValidRange(raw, this.#_score_range))) {
|
||||
this.#raw = raw;
|
||||
}
|
||||
}
|
||||
|
||||
toJSON = () => {
|
||||
return {
|
||||
'raw': this.raw,
|
||||
'min': this.min,
|
||||
'max': this.max,
|
||||
};
|
||||
/**
|
||||
* Getter for #min
|
||||
* @return {string}
|
||||
*/
|
||||
get min() {
|
||||
return this.#min;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for #min
|
||||
* @param {string} min
|
||||
*/
|
||||
set min(min) {
|
||||
if (this.API.checkValidFormat(min, scorm12_constants.CMIDecimal) &&
|
||||
(!this.#_score_range ||
|
||||
this.API.checkValidRange(min, this.#_score_range))) {
|
||||
this.#min = min;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for #max
|
||||
* @return {string}
|
||||
*/
|
||||
get max() {
|
||||
return this.#max;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for #max
|
||||
* @param {string} max
|
||||
*/
|
||||
set max(max) {
|
||||
if (this.API.checkValidFormat(max, scorm12_constants.CMIDecimal) &&
|
||||
(!this.#_score_range ||
|
||||
this.API.checkValidRange(max, this.#_score_range))) {
|
||||
this.#max = max;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* toJSON for *.score
|
||||
* @return {{min: string, max: string, raw: string}}
|
||||
*/
|
||||
toJSON() {
|
||||
return {
|
||||
'raw': this.raw,
|
||||
'min': this.min,
|
||||
'max': this.max,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Base class for cmi *.n objects
|
||||
*/
|
||||
export class CMIArray extends BaseCMI {
|
||||
/**
|
||||
* Constructor cmi *.n arrays
|
||||
* @param {BaseAPI} API
|
||||
* @param {string} children
|
||||
* @param {number} errorCode
|
||||
*/
|
||||
constructor({API, children, errorCode}) {
|
||||
super(API);
|
||||
this.#_children = children;
|
||||
@@ -80,30 +156,56 @@ export class CMIArray extends BaseCMI {
|
||||
this.childArray = [];
|
||||
}
|
||||
|
||||
#errorCode;
|
||||
#_children;
|
||||
#errorCode;
|
||||
#_children;
|
||||
|
||||
get _children() {
|
||||
return this.#_children;
|
||||
}
|
||||
set _children(_children) {
|
||||
this.API.throwSCORMError(this.#errorCode);
|
||||
}
|
||||
/**
|
||||
* Getter for _children
|
||||
* @return {*}
|
||||
* @private
|
||||
*/
|
||||
get _children() {
|
||||
return this.#_children;
|
||||
}
|
||||
|
||||
get _count() {
|
||||
return this.childArray.length;
|
||||
}
|
||||
set _count(_count) {
|
||||
this.API.throwSCORMError(this.#errorCode);
|
||||
}
|
||||
/**
|
||||
* Setter for _children. Just throws an error.
|
||||
* @param {string} _children
|
||||
* @private
|
||||
*/
|
||||
set _children(_children) {
|
||||
this.API.throwSCORMError(this.#errorCode);
|
||||
}
|
||||
|
||||
toJSON = () => {
|
||||
this.jsonString = true;
|
||||
const result = {};
|
||||
for (let i = 0; i < this.childArray.length; i++) {
|
||||
result[i + ''] = this.childArray[i];
|
||||
}
|
||||
delete this.jsonString;
|
||||
return result;
|
||||
/**
|
||||
* Getter for _count
|
||||
* @return {number}
|
||||
* @private
|
||||
*/
|
||||
get _count() {
|
||||
return this.childArray.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for _count. Just throws an error.
|
||||
* @param {number} _count
|
||||
* @private
|
||||
*/
|
||||
set _count(_count) {
|
||||
this.API.throwSCORMError(this.#errorCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* toJSON for *.n arrays
|
||||
* @return {object}
|
||||
*/
|
||||
toJSON() {
|
||||
this.jsonString = true;
|
||||
const result = {};
|
||||
for (let i = 0; i < this.childArray.length; i++) {
|
||||
result[i + ''] = this.childArray[i];
|
||||
}
|
||||
delete this.jsonString;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -30,7 +30,7 @@ export const scorm12_constants = {
|
||||
},
|
||||
'301': {
|
||||
basicMessage: 'Not initialized',
|
||||
detailMessage: 'Indicates that an API call was made before the call to LMSInitialize.',
|
||||
detailMessage: 'Indicates that an API call was made before the call to lmsInitialize.',
|
||||
},
|
||||
'401': {
|
||||
basicMessage: 'Not implemented error',
|
||||
|
||||
@@ -71,4 +71,4 @@ export const valid_languages = {
|
||||
'ukr': 'ukr', 'urd': 'urd', 'uzb': 'uzb', 'ven': 'ven', 'vie': 'vie',
|
||||
'vol': 'vol', 'wln': 'wln', 'wol': 'wol', 'xho': 'xho', 'yid': 'yid',
|
||||
'yor': 'yor', 'zha': 'zha', 'chi': 'chi', 'zho': 'zho', 'zul': 'zul',
|
||||
};
|
||||
};
|
||||
|
||||
126
src/regex.js
126
src/regex.js
@@ -1,76 +1,76 @@
|
||||
// @flow
|
||||
|
||||
export const scorm12_regex = {
|
||||
CMIString256: '^.{0,255}$',
|
||||
CMIString4096: '^.{0,4096}$',
|
||||
CMITime: '^([0-2]{1}[0-9]{1}):([0-5]{1}[0-9]{1}):([0-5]{1}[0-9]{1})(\.[0-9]{1,6})?$',
|
||||
CMITimespan: '^([0-9]{2,4}):([0-9]{2}):([0-9]{2})(\.[0-9]{1,2})?$',
|
||||
CMIInteger: '^\\d+$',
|
||||
CMISInteger: '^-?([0-9]+)$',
|
||||
CMIDecimal: '^-?([0-9]{0,3})(\.[0-9]*)?$',
|
||||
CMIIdentifier: '^[\\u0021-\\u007E]{0,255}$',
|
||||
CMIFeedback: '^.{0,255}$', // This must be redefined
|
||||
CMIIndex: '[._](\\d+).',
|
||||
CMIString256: '^.{0,255}$',
|
||||
CMIString4096: '^.{0,4096}$',
|
||||
CMITime: '^([0-2]{1}[0-9]{1}):([0-5]{1}[0-9]{1}):([0-5]{1}[0-9]{1})(\.[0-9]{1,6})?$', // eslint-disable-line
|
||||
CMITimespan: '^([0-9]{2,}):([0-9]{2}):([0-9]{2})(\.[0-9]{1,2})?$', // eslint-disable-line
|
||||
CMIInteger: '^\\d+$',
|
||||
CMISInteger: '^-?([0-9]+)$',
|
||||
CMIDecimal: '^-?([0-9]{0,3})(\.[0-9]*)?$', // eslint-disable-line
|
||||
CMIIdentifier: '^[\\u0021-\\u007E]{0,255}$',
|
||||
CMIFeedback: '^.{0,255}$', // This must be redefined
|
||||
CMIIndex: '[._](\\d+).',
|
||||
|
||||
// Vocabulary Data Type Definition
|
||||
CMIStatus: '^passed$|^completed$|^failed$|^incomplete$|^browsed$',
|
||||
CMIStatus2: '^passed$|^completed$|^failed$|^incomplete$|^browsed$|^not attempted$',
|
||||
CMIExit: '^time-out$|^suspend$|^logout$|^$',
|
||||
CMIType: '^true-false$|^choice$|^fill-in$|^matching$|^performance$|^sequencing$|^likert$|^numeric$',
|
||||
CMIResult: '^correct$|^wrong$|^unanticipated$|^neutral$|^([0-9]{0,3})?(\.[0-9]*)?$',
|
||||
NAVEvent: '^previous$|^continue$',
|
||||
// Vocabulary Data Type Definition
|
||||
CMIStatus: '^passed$|^completed$|^failed$|^incomplete$|^browsed$',
|
||||
CMIStatus2: '^passed$|^completed$|^failed$|^incomplete$|^browsed$|^not attempted$',
|
||||
CMIExit: '^time-out$|^suspend$|^logout$|^$',
|
||||
CMIType: '^true-false$|^choice$|^fill-in$|^matching$|^performance$|^sequencing$|^likert$|^numeric$',
|
||||
CMIResult: '^correct$|^wrong$|^unanticipated$|^neutral$|^([0-9]{0,3})?(\.[0-9]*)?$', // eslint-disable-line
|
||||
NAVEvent: '^previous$|^continue$',
|
||||
|
||||
// Data ranges
|
||||
score_range: '0#100',
|
||||
audio_range: '-1#100',
|
||||
speed_range: '-100#100',
|
||||
weighting_range: '-100#100',
|
||||
text_range: '-1#1',
|
||||
// Data ranges
|
||||
score_range: '0#100',
|
||||
audio_range: '-1#100',
|
||||
speed_range: '-100#100',
|
||||
weighting_range: '-100#100',
|
||||
text_range: '-1#1',
|
||||
};
|
||||
|
||||
export const aicc_regex = {
|
||||
...scorm12_regex, ...{
|
||||
CMIIdentifier: '^\\w{1,255}$',
|
||||
}
|
||||
...scorm12_regex, ...{
|
||||
CMIIdentifier: '^\\w{1,255}$',
|
||||
},
|
||||
};
|
||||
|
||||
export const scorm2004_regex = {
|
||||
CMIString200: '^[\\u0000-\\uFFFF]{0,200}$',
|
||||
CMIString250: '^[\\u0000-\\uFFFF]{0,250}$',
|
||||
CMIString1000: '^[\\u0000-\\uFFFF]{0,1000}$',
|
||||
CMIString4000: '^[\\u0000-\\uFFFF]{0,4000}$',
|
||||
CMIString64000: '^[\\u0000-\\uFFFF]{0,64000}$',
|
||||
CMILang: '^([a-zA-Z]{2,3}|i|x)(\-[a-zA-Z0-9\-]{2,8})?$|^$',
|
||||
CMILangString250: '^(\{lang=([a-zA-Z]{2,3}|i|x)(\-[a-zA-Z0-9\-]{2,8})?\})?([^\{].{0,250}$)?',
|
||||
CMILangcr: '^((\{lang=([a-zA-Z]{2,3}|i|x)?(\-[a-zA-Z0-9\-]{2,8})?\}))(.*?)$',
|
||||
CMILangString250cr: '^((\{lang=([a-zA-Z]{2,3}|i|x)?(\-[a-zA-Z0-9\-]{2,8})?\})?(.{0,250})?)?$',
|
||||
CMILangString4000: '^(\{lang=([a-zA-Z]{2,3}|i|x)(\-[a-zA-Z0-9\-]{2,8})?\})?([^\{].{0,4000}$)?',
|
||||
CMITime: '^(19[7-9]{1}[0-9]{1}|20[0-2]{1}[0-9]{1}|203[0-8]{1})((-(0[1-9]{1}|1[0-2]{1}))((-(0[1-9]{1}|[1-2]{1}[0-9]{1}|3[0-1]{1}))(T([0-1]{1}[0-9]{1}|2[0-3]{1})((:[0-5]{1}[0-9]{1})((:[0-5]{1}[0-9]{1})((\\.[0-9]{1,2})((Z|([+|-]([0-1]{1}[0-9]{1}|2[0-3]{1})))(:[0-5]{1}[0-9]{1})?)?)?)?)?)?)?)?$',
|
||||
CMITimespan: '^P(?:([.,\\d]+)Y)?(?:([.,\\d]+)M)?(?:([.,\\d]+)W)?(?:([.,\\d]+)D)?(?:T?(?:([.,\\d]+)H)?(?:([.,\\d]+)M)?(?:([.,\\d]+)S)?)?$',
|
||||
CMIInteger: '^\\d+$',
|
||||
CMISInteger: '^-?([0-9]+)$',
|
||||
CMIDecimal: '^-?([0-9]{1,5})(\\.[0-9]{1,18})?$',
|
||||
CMIIdentifier: '^\\S{1,250}[a-zA-Z0-9]$',
|
||||
CMIShortIdentifier: '^[\\w\.]{1,250}$',
|
||||
CMILongIdentifier: '^(?:(?!urn:)\\S{1,4000}|urn:[A-Za-z0-9-]{1,31}:\\S{1,4000})$',
|
||||
CMIFeedback: '^.*$', // This must be redefined
|
||||
CMIIndex: '[._](\\d+).',
|
||||
CMIIndexStore: '.N(\\d+).',
|
||||
CMIString200: '^[\\u0000-\\uFFFF]{0,200}$',
|
||||
CMIString250: '^[\\u0000-\\uFFFF]{0,250}$',
|
||||
CMIString1000: '^[\\u0000-\\uFFFF]{0,1000}$',
|
||||
CMIString4000: '^[\\u0000-\\uFFFF]{0,4000}$',
|
||||
CMIString64000: '^[\\u0000-\\uFFFF]{0,64000}$',
|
||||
CMILang: '^([a-zA-Z]{2,3}|i|x)(\-[a-zA-Z0-9\-]{2,8})?$|^$', // eslint-disable-line
|
||||
CMILangString250: '^(\{lang=([a-zA-Z]{2,3}|i|x)(\-[a-zA-Z0-9\-]{2,8})?\})?([^\{].{0,250}$)?', // eslint-disable-line
|
||||
CMILangcr: '^((\{lang=([a-zA-Z]{2,3}|i|x)?(\-[a-zA-Z0-9\-]{2,8})?\}))(.*?)$', // eslint-disable-line
|
||||
CMILangString250cr: '^((\{lang=([a-zA-Z]{2,3}|i|x)?(\-[a-zA-Z0-9\-]{2,8})?\})?(.{0,250})?)?$', // eslint-disable-line
|
||||
CMILangString4000: '^(\{lang=([a-zA-Z]{2,3}|i|x)(\-[a-zA-Z0-9\-]{2,8})?\})?([^\{].{0,4000}$)?', // eslint-disable-line
|
||||
CMITime: '^(19[7-9]{1}[0-9]{1}|20[0-2]{1}[0-9]{1}|203[0-8]{1})((-(0[1-9]{1}|1[0-2]{1}))((-(0[1-9]{1}|[1-2]{1}[0-9]{1}|3[0-1]{1}))(T([0-1]{1}[0-9]{1}|2[0-3]{1})((:[0-5]{1}[0-9]{1})((:[0-5]{1}[0-9]{1})((\\.[0-9]{1,2})((Z|([+|-]([0-1]{1}[0-9]{1}|2[0-3]{1})))(:[0-5]{1}[0-9]{1})?)?)?)?)?)?)?)?$',
|
||||
CMITimespan: '^P(?:([.,\\d]+)Y)?(?:([.,\\d]+)M)?(?:([.,\\d]+)W)?(?:([.,\\d]+)D)?(?:T?(?:([.,\\d]+)H)?(?:([.,\\d]+)M)?(?:([.,\\d]+)S)?)?$',
|
||||
CMIInteger: '^\\d+$',
|
||||
CMISInteger: '^-?([0-9]+)$',
|
||||
CMIDecimal: '^-?([0-9]{1,5})(\\.[0-9]{1,18})?$',
|
||||
CMIIdentifier: '^\\S{1,250}[a-zA-Z0-9]$',
|
||||
CMIShortIdentifier: '^[\\w\.]{1,250}$', // eslint-disable-line
|
||||
CMILongIdentifier: '^(?:(?!urn:)\\S{1,4000}|urn:[A-Za-z0-9-]{1,31}:\\S{1,4000})$',
|
||||
CMIFeedback: '^.*$', // This must be redefined
|
||||
CMIIndex: '[._](\\d+).',
|
||||
CMIIndexStore: '.N(\\d+).',
|
||||
|
||||
// Vocabulary Data Type Definition
|
||||
CMICStatus: '^completed$|^incomplete$|^not attempted$|^unknown$',
|
||||
CMISStatus: '^passed$|^failed$|^unknown$',
|
||||
CMIExit: '^time-out$|^suspend$|^logout$|^normal$|^$',
|
||||
CMIType: '^true-false$|^choice$|^(long-)?fill-in$|^matching$|^performance$|^sequencing$|^likert$|^numeric$|^other$',
|
||||
CMIResult: '^correct$|^incorrect$|^unanticipated$|^neutral$|^-?([0-9]{1,4})(\\.[0-9]{1,18})?$',
|
||||
NAVEvent: '^previous$|^continue$|^exit$|^exitAll$|^abandon$|^abandonAll$|^suspendAll$|^\{target=\\S{0,200}[a-zA-Z0-9]\}choice|jump$',
|
||||
NAVBoolean: '^unknown$|^true$|^false$',
|
||||
NAVTarget: '^previous$|^continue$|^choice.{target=\\S{0,200}[a-zA-Z0-9]}$',
|
||||
// Vocabulary Data Type Definition
|
||||
CMICStatus: '^completed$|^incomplete$|^not attempted$|^unknown$',
|
||||
CMISStatus: '^passed$|^failed$|^unknown$',
|
||||
CMIExit: '^time-out$|^suspend$|^logout$|^normal$|^$',
|
||||
CMIType: '^true-false$|^choice$|^(long-)?fill-in$|^matching$|^performance$|^sequencing$|^likert$|^numeric$|^other$',
|
||||
CMIResult: '^correct$|^incorrect$|^unanticipated$|^neutral$|^-?([0-9]{1,4})(\\.[0-9]{1,18})?$',
|
||||
NAVEvent: '^previous$|^continue$|^exit$|^exitAll$|^abandon$|^abandonAll$|^suspendAll$|^\{target=\\S{0,200}[a-zA-Z0-9]\}choice|jump$', // eslint-disable-line
|
||||
NAVBoolean: '^unknown$|^true$|^false$',
|
||||
NAVTarget: '^previous$|^continue$|^choice.{target=\\S{0,200}[a-zA-Z0-9]}$',
|
||||
|
||||
// Data ranges
|
||||
scaled_range: '-1#1',
|
||||
audio_range: '0#*',
|
||||
speed_range: '0#*',
|
||||
text_range: '-1#1',
|
||||
progress_range: '0#1',
|
||||
};
|
||||
// Data ranges
|
||||
scaled_range: '-1#1',
|
||||
audio_range: '0#*',
|
||||
speed_range: '0#*',
|
||||
text_range: '-1#1',
|
||||
progress_range: '0#1',
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// @flow
|
||||
export const SECONDS_PER_SECOND = 1;
|
||||
export const SECONDS_PER_SECOND = 1.0;
|
||||
export const SECONDS_PER_MINUTE = 60;
|
||||
export const SECONDS_PER_HOUR = 60 * SECONDS_PER_MINUTE;
|
||||
export const SECONDS_PER_DAY = 24 * SECONDS_PER_HOUR;
|
||||
@@ -27,11 +27,12 @@ export function getSecondsAsHHMMSS(totalSeconds: Number) {
|
||||
|
||||
const dateObj = new Date(totalSeconds * 1000);
|
||||
const minutes = dateObj.getUTCMinutes();
|
||||
const seconds = dateObj.getSeconds();
|
||||
// make sure we add any possible decimal value
|
||||
const seconds = dateObj.getSeconds() + (totalSeconds % 1.0);
|
||||
|
||||
return hours.toString().padStart(2, '0') + ':' +
|
||||
minutes.toString().padStart(2, '0') + ':' +
|
||||
seconds.toString().padStart(2, '0');
|
||||
minutes.toString().padStart(2, '0') + ':' +
|
||||
seconds.toString().padStart(2, '0');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,9 +51,14 @@ export function getSecondsAsISODuration(seconds: Number) {
|
||||
let remainder = seconds;
|
||||
|
||||
designations.forEach(([sign, current_seconds]) => {
|
||||
const value = Math.floor(remainder / current_seconds);
|
||||
let value = Math.floor(remainder / current_seconds);
|
||||
|
||||
remainder = remainder % current_seconds;
|
||||
// If we have anything left in the remainder, and we're currently adding
|
||||
// seconds to the duration, go ahead and add the decimal to the seconds
|
||||
if (sign === 'S' && remainder > 0) {
|
||||
value += remainder;
|
||||
}
|
||||
|
||||
if (value) {
|
||||
duration += `${value}${sign}`;
|
||||
@@ -104,10 +110,45 @@ export function getDurationAsSeconds(duration: String, durationRegex: RegExp) {
|
||||
anchor.setHours(anchor.getHours() + Number(hours || 0));
|
||||
anchor.setMinutes(anchor.getMinutes() + Number(minutes || 0));
|
||||
anchor.setSeconds(anchor.getSeconds() + Number(seconds || 0));
|
||||
if (seconds) {
|
||||
if (seconds && String(seconds).indexOf('.') > 0) {
|
||||
const milliseconds = Number(Number(seconds) % 1).toFixed(6) * 1000.0;
|
||||
anchor.setMilliseconds(anchor.getMilliseconds() + milliseconds);
|
||||
}
|
||||
|
||||
return (anchor - now) / 1000.0;
|
||||
return ((anchor * 1.0) - now) / 1000.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds together two ISO8601 Duration strings
|
||||
*
|
||||
* @param {string} first
|
||||
* @param {string} second
|
||||
* @param {RegExp} durationRegex
|
||||
* @return {string}
|
||||
*/
|
||||
export function addTwoDurations(
|
||||
first: String,
|
||||
second: String,
|
||||
durationRegex: RegExp) {
|
||||
const firstSeconds = getDurationAsSeconds(first, durationRegex);
|
||||
const secondSeconds = getDurationAsSeconds(second, durationRegex);
|
||||
|
||||
return getSecondsAsISODuration(firstSeconds + secondSeconds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add together two HH:MM:SS.DD strings
|
||||
*
|
||||
* @param {string} first
|
||||
* @param {string} second
|
||||
* @param {RegExp} timeRegex
|
||||
* @return {string}
|
||||
*/
|
||||
export function addHHMMSSTimeStrings(
|
||||
first: String,
|
||||
second: String,
|
||||
timeRegex: RegExp) {
|
||||
const firstSeconds = getTimeAsSeconds(first, timeRegex);
|
||||
const secondSeconds = getTimeAsSeconds(second, timeRegex);
|
||||
return getSecondsAsHHMMSS(firstSeconds + secondSeconds);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user