Rework of constants and some additional tests

This commit is contained in:
Jonathan Putney
2020-01-15 12:21:57 -05:00
parent eaa80394a7
commit 7882608fb6
23 changed files with 766 additions and 578 deletions

View File

@@ -1,16 +1,17 @@
import * as Scorm12CMI from './scorm12_cmi';
import {BaseCMI, CMIArray, CMIScore} from './common';
import {aicc_constants} from '../constants/api_constants';
import {aicc_regex} from '../constants/regex';
import {scorm12_error_codes} from '../constants/error_codes';
import APIConstants from '../constants/api_constants';
import Regex from '../constants/regex';
import ErrorCodes from '../constants/error_codes';
import {
check12ValidFormat,
throwReadOnlyError,
throwWriteOnlyError,
} from './scorm12_cmi';
const constants = aicc_constants;
const regex = aicc_regex;
const aicc_constants = APIConstants.aicc;
const aicc_regex = Regex.aicc;
const scorm12_error_codes = ErrorCodes.scorm12;
/**
* CMI Class for AICC
@@ -21,7 +22,7 @@ export class CMI extends Scorm12CMI.CMI {
* @param {boolean} initialized
*/
constructor(initialized: boolean) {
super(constants.cmi_children);
super(aicc_constants.cmi_children);
if (initialized) this.initialize();
@@ -117,7 +118,7 @@ class CMIEvaluationComments extends CMIArray {
* Constructor for AICC Evaluation Comments object
*/
constructor() {
super(constants.comments_children,
super(aicc_constants.comments_children,
scorm12_error_codes.INVALID_SET_VALUE);
}
}
@@ -130,7 +131,7 @@ class AICCCMIStudentData extends Scorm12CMI.CMIStudentData {
* Constructor for AICC StudentData object
*/
constructor() {
super(constants.student_data_children);
super(aicc_constants.student_data_children);
this.tries = new CMITries();
}
@@ -212,8 +213,8 @@ export class CMITriesObject extends BaseCMI {
this.score = new CMIScore(
{
score_children: constants.score_children,
score_range: regex.score_range,
score_children: aicc_constants.score_children,
score_range: aicc_regex.score_range,
invalidErrorCode: scorm12_error_codes.INVALID_SET_VALUE,
invalidTypeCode: scorm12_error_codes.TYPE_MISMATCH,
invalidRangeCode: scorm12_error_codes.VALUE_OUT_OF_RANGE,
@@ -244,7 +245,7 @@ export class CMITriesObject extends BaseCMI {
* @param {string} status
*/
set status(status) {
if (check12ValidFormat(status, regex.CMIStatus2)) {
if (check12ValidFormat(status, aicc_regex.CMIStatus2)) {
this.#status = status;
}
}
@@ -262,7 +263,7 @@ export class CMITriesObject extends BaseCMI {
* @param {string} time
*/
set time(time) {
if (check12ValidFormat(time, regex.CMITime)) {
if (check12ValidFormat(time, aicc_regex.CMITime)) {
this.#time = time;
}
}
@@ -317,7 +318,7 @@ export class CMIEvaluationCommentsObject extends BaseCMI {
* @param {string} content
*/
set content(content) {
if (check12ValidFormat(content, regex.CMIString256)) {
if (check12ValidFormat(content, aicc_regex.CMIString256)) {
this.#content = content;
}
}
@@ -335,7 +336,7 @@ export class CMIEvaluationCommentsObject extends BaseCMI {
* @param {string} location
*/
set location(location) {
if (check12ValidFormat(location, regex.CMIString256)) {
if (check12ValidFormat(location, aicc_regex.CMIString256)) {
this.#location = location;
}
}
@@ -353,7 +354,7 @@ export class CMIEvaluationCommentsObject extends BaseCMI {
* @param {string} time
*/
set time(time) {
if (check12ValidFormat(time, regex.CMITime)) {
if (check12ValidFormat(time, aicc_regex.CMITime)) {
this.#time = time;
}
}

View File

@@ -1,8 +1,12 @@
// @flow
import {scorm12_constants} from '../constants/api_constants';
import {scorm12_error_codes} from '../constants/error_codes';
import APIConstants from '../constants/api_constants';
import ErrorCodes from '../constants/error_codes';
import {ValidationError} from '../exceptions';
import {scorm12_regex} from '../constants/regex';
import Regex from '../constants/regex';
const scorm12_constants = APIConstants.scorm12;
const scorm12_regex = Regex.scorm12;
const scorm12_error_codes = ErrorCodes.scorm12;
/**
* Check if the value matches the proper format. If not, throw proper error code.

View File

@@ -6,14 +6,15 @@ import {
CMIArray,
CMIScore,
} from './common';
import {scorm12_constants} from '../constants/api_constants';
import {scorm12_error_codes} from '../constants/error_codes';
import {scorm12_regex} from '../constants/regex';
import APIConstants from '../constants/api_constants';
import ErrorCodes from '../constants/error_codes';
import Regex from '../constants/regex';
import {ValidationError} from '../exceptions';
import * as Utilities from '../utilities';
const constants = scorm12_constants;
const regex = scorm12_regex;
const scorm12_constants = APIConstants.scorm12;
const scorm12_regex = Regex.scorm12;
const scorm12_error_codes = ErrorCodes.scorm12;
/**
* Helper method for throwing Read Only error
@@ -90,7 +91,7 @@ export class CMI extends BaseCMI {
if (initialized) this.initialize();
this.#_children = cmi_children ? cmi_children : constants.cmi_children;
this.#_children = cmi_children ? cmi_children : scorm12_constants.cmi_children;
this.core = new CMICore();
this.objectives = new CMIObjectives();
this.student_data = student_data ? student_data : new CMIStudentData();
@@ -189,7 +190,7 @@ export class CMI extends BaseCMI {
* @param {string} suspend_data
*/
set suspend_data(suspend_data) {
if (check12ValidFormat(suspend_data, regex.CMIString4096)) {
if (check12ValidFormat(suspend_data, scorm12_regex.CMIString4096, true)) {
this.#suspend_data = suspend_data;
}
}
@@ -223,7 +224,7 @@ export class CMI extends BaseCMI {
* @param {string} comments
*/
set comments(comments) {
if (check12ValidFormat(comments, regex.CMIString4096)) {
if (check12ValidFormat(comments, scorm12_regex.CMIString4096)) {
this.#comments = comments;
}
}
@@ -269,8 +270,8 @@ class CMICore extends BaseCMI {
this.score = new CMIScore(
{
score_children: constants.score_children,
score_range: regex.score_range,
score_children: scorm12_constants.score_children,
score_range: scorm12_regex.score_range,
invalidErrorCode: scorm12_error_codes.INVALID_SET_VALUE,
invalidTypeCode: scorm12_error_codes.TYPE_MISMATCH,
invalidRangeCode: scorm12_error_codes.VALUE_OUT_OF_RANGE,
@@ -285,7 +286,7 @@ class CMICore extends BaseCMI {
this.score?.initialize();
}
#_children = constants.core_children;
#_children = scorm12_constants.core_children;
#student_id = '';
#student_name = '';
#lesson_location = '';
@@ -362,7 +363,7 @@ class CMICore extends BaseCMI {
* @param {string} lesson_location
*/
set lesson_location(lesson_location) {
if (check12ValidFormat(lesson_location, regex.CMIString256, true)) {
if (check12ValidFormat(lesson_location, scorm12_regex.CMIString256, true)) {
this.#lesson_location = lesson_location;
}
}
@@ -396,7 +397,7 @@ class CMICore extends BaseCMI {
* @param {string} lesson_status
*/
set lesson_status(lesson_status) {
if (check12ValidFormat(lesson_status, regex.CMIStatus)) {
if (check12ValidFormat(lesson_status, scorm12_regex.CMIStatus)) {
this.#lesson_status = lesson_status;
}
}
@@ -462,7 +463,7 @@ class CMICore extends BaseCMI {
* @param {string} exit
*/
set exit(exit) {
if (check12ValidFormat(exit, regex.CMIExit, true)) {
if (check12ValidFormat(exit, scorm12_regex.CMIExit, true)) {
this.#exit = exit;
}
}
@@ -480,7 +481,7 @@ class CMICore extends BaseCMI {
* @param {string} session_time
*/
set session_time(session_time) {
if (check12ValidFormat(session_time, regex.CMITimespan)) {
if (check12ValidFormat(session_time, scorm12_regex.CMITimespan)) {
this.#session_time = session_time;
}
}
@@ -545,7 +546,7 @@ class CMIObjectives extends CMIArray {
*/
constructor() {
super({
children: constants.objectives_children,
children: scorm12_constants.objectives_children,
errorCode: scorm12_error_codes.INVALID_SET_VALUE,
});
}
@@ -570,7 +571,7 @@ export class CMIStudentData extends BaseCMI {
this.#_children = student_data_children ?
student_data_children :
constants.student_data_children;
scorm12_constants.student_data_children;
}
/**
@@ -680,7 +681,7 @@ class CMIStudentPreference extends BaseCMI {
super();
}
#_children = constants.student_preference_children;
#_children = scorm12_constants.student_preference_children;
#audio = '';
#language = '';
#speed = '';
@@ -717,8 +718,8 @@ class CMIStudentPreference extends BaseCMI {
* @param {string} audio
*/
set audio(audio) {
if (check12ValidFormat(audio, regex.CMISInteger) &&
check12ValidRange(audio, regex.audio_range)) {
if (check12ValidFormat(audio, scorm12_regex.CMISInteger) &&
check12ValidRange(audio, scorm12_regex.audio_range)) {
this.#audio = audio;
}
}
@@ -736,7 +737,7 @@ class CMIStudentPreference extends BaseCMI {
* @param {string} language
*/
set language(language) {
if (check12ValidFormat(language, regex.CMIString256)) {
if (check12ValidFormat(language, scorm12_regex.CMIString256)) {
this.#language = language;
}
}
@@ -754,8 +755,8 @@ class CMIStudentPreference extends BaseCMI {
* @param {string} speed
*/
set speed(speed) {
if (check12ValidFormat(speed, regex.CMISInteger) &&
check12ValidRange(speed, regex.speed_range)) {
if (check12ValidFormat(speed, scorm12_regex.CMISInteger) &&
check12ValidRange(speed, scorm12_regex.speed_range)) {
this.#speed = speed;
}
}
@@ -773,8 +774,8 @@ class CMIStudentPreference extends BaseCMI {
* @param {string} text
*/
set text(text) {
if (check12ValidFormat(text, regex.CMISInteger) &&
check12ValidRange(text, regex.text_range)) {
if (check12ValidFormat(text, scorm12_regex.CMISInteger) &&
check12ValidRange(text, scorm12_regex.text_range)) {
this.#text = text;
}
}
@@ -814,7 +815,7 @@ class CMIInteractions extends CMIArray {
*/
constructor() {
super({
children: constants.interactions_children,
children: scorm12_constants.interactions_children,
errorCode: scorm12_error_codes.INVALID_SET_VALUE,
});
}
@@ -833,11 +834,11 @@ export class CMIInteractionsObject extends BaseCMI {
this.objectives = new CMIArray({
errorCode: scorm12_error_codes.INVALID_SET_VALUE,
children: constants.objectives_children,
children: scorm12_constants.objectives_children,
});
this.correct_responses = new CMIArray({
errorCode: scorm12_error_codes.INVALID_SET_VALUE,
children: constants.correct_responses_children,
children: scorm12_constants.correct_responses_children,
});
}
@@ -871,7 +872,7 @@ export class CMIInteractionsObject extends BaseCMI {
* @param {string} id
*/
set id(id) {
if (check12ValidFormat(id, regex.CMIIdentifier)) {
if (check12ValidFormat(id, scorm12_regex.CMIIdentifier)) {
this.#id = id;
}
}
@@ -889,7 +890,7 @@ export class CMIInteractionsObject extends BaseCMI {
* @param {string} time
*/
set time(time) {
if (check12ValidFormat(time, regex.CMITime)) {
if (check12ValidFormat(time, scorm12_regex.CMITime)) {
this.#time = time;
}
}
@@ -907,7 +908,7 @@ export class CMIInteractionsObject extends BaseCMI {
* @param {string} type
*/
set type(type) {
if (check12ValidFormat(type, regex.CMIType)) {
if (check12ValidFormat(type, scorm12_regex.CMIType)) {
this.#type = type;
}
}
@@ -927,8 +928,8 @@ export class CMIInteractionsObject extends BaseCMI {
* @param {string} weighting
*/
set weighting(weighting) {
if (check12ValidFormat(weighting, regex.CMIDecimal) &&
check12ValidRange(weighting, regex.weighting_range)) {
if (check12ValidFormat(weighting, scorm12_regex.CMIDecimal) &&
check12ValidRange(weighting, scorm12_regex.weighting_range)) {
this.#weighting = weighting;
}
}
@@ -946,7 +947,7 @@ export class CMIInteractionsObject extends BaseCMI {
* @param {string} student_response
*/
set student_response(student_response) {
if (check12ValidFormat(student_response, regex.CMIFeedback, true)) {
if (check12ValidFormat(student_response, scorm12_regex.CMIFeedback, true)) {
this.#student_response = student_response;
}
}
@@ -964,7 +965,7 @@ export class CMIInteractionsObject extends BaseCMI {
* @param {string} result
*/
set result(result) {
if (check12ValidFormat(result, regex.CMIResult)) {
if (check12ValidFormat(result, scorm12_regex.CMIResult)) {
this.#result = result;
}
}
@@ -982,7 +983,7 @@ export class CMIInteractionsObject extends BaseCMI {
* @param {string} latency
*/
set latency(latency) {
if (check12ValidFormat(latency, regex.CMITimespan)) {
if (check12ValidFormat(latency, scorm12_regex.CMITimespan)) {
this.#latency = latency;
}
}
@@ -1035,8 +1036,8 @@ export class CMIObjectivesObject extends BaseCMI {
this.score = new CMIScore(
{
score_children: constants.score_children,
score_range: regex.score_range,
score_children: scorm12_constants.score_children,
score_range: scorm12_regex.score_range,
invalidErrorCode: scorm12_error_codes.INVALID_SET_VALUE,
invalidTypeCode: scorm12_error_codes.TYPE_MISMATCH,
invalidRangeCode: scorm12_error_codes.VALUE_OUT_OF_RANGE,
@@ -1059,7 +1060,7 @@ export class CMIObjectivesObject extends BaseCMI {
* @param {string} id
*/
set id(id) {
if (check12ValidFormat(id, regex.CMIIdentifier)) {
if (check12ValidFormat(id, scorm12_regex.CMIIdentifier)) {
this.#id = id;
}
}
@@ -1077,7 +1078,7 @@ export class CMIObjectivesObject extends BaseCMI {
* @param {string} status
*/
set status(status) {
if (check12ValidFormat(status, regex.CMIStatus2)) {
if (check12ValidFormat(status, scorm12_regex.CMIStatus2)) {
this.#status = status;
}
}
@@ -1131,7 +1132,7 @@ export class CMIInteractionsObjectivesObject extends BaseCMI {
* @param {string} id
*/
set id(id) {
if (check12ValidFormat(id, regex.CMIIdentifier)) {
if (check12ValidFormat(id, scorm12_regex.CMIIdentifier)) {
this.#id = id;
}
}
@@ -1181,7 +1182,7 @@ export class CMIInteractionsCorrectResponsesObject extends BaseCMI {
* @param {string} pattern
*/
set pattern(pattern) {
if (check12ValidFormat(pattern, regex.CMIFeedback, true)) {
if (check12ValidFormat(pattern, scorm12_regex.CMIFeedback, true)) {
this.#pattern = pattern;
}
}
@@ -1230,7 +1231,7 @@ export class NAV extends BaseCMI {
* @param {string} event
*/
set event(event) {
if (check12ValidFormat(event, regex.NAVEvent)) {
if (check12ValidFormat(event, scorm12_regex.NAVEvent)) {
this.#event = event;
}
}

View File

@@ -6,15 +6,18 @@ import {
CMIArray,
CMIScore,
} from './common';
import {scorm2004_constants} from '../constants/api_constants';
import {scorm2004_regex} from '../constants/regex';
import {scorm2004_error_codes} from '../constants/error_codes';
import {learner_responses} from '../constants/response_constants';
import APIConstants from '../constants/api_constants';
import Regex from '../constants/regex';
import ErrorCodes from '../constants/error_codes';
import Responses from '../constants/response_constants';
import {ValidationError} from '../exceptions';
import * as Util from '../utilities';
const constants = scorm2004_constants;
const regex = scorm2004_regex;
const scorm2004_constants = APIConstants.scorm2004;
const scorm2004_error_codes = ErrorCodes.scorm2004;
const learner_responses = Responses.learner;
const scorm2004_regex = Regex.scorm2004;
/**
* Helper method for throwing Read Only error
@@ -85,7 +88,7 @@ export class CMI extends BaseCMI {
}
#_version = '1.0';
#_children = constants.cmi_children;
#_children = scorm2004_constants.cmi_children;
#completion_status = 'unknown';
#completion_threshold = '';
#credit = 'credit';
@@ -167,7 +170,7 @@ export class CMI extends BaseCMI {
* @param {string} completion_status
*/
set completion_status(completion_status) {
if (check2004ValidFormat(completion_status, regex.CMICStatus)) {
if (check2004ValidFormat(completion_status, scorm2004_regex.CMICStatus)) {
this.#completion_status = completion_status;
}
}
@@ -235,7 +238,7 @@ export class CMI extends BaseCMI {
* @param {string} exit
*/
set exit(exit) {
if (check2004ValidFormat(exit, regex.CMIExit, true)) {
if (check2004ValidFormat(exit, scorm2004_regex.CMIExit, true)) {
this.#exit = exit;
}
}
@@ -303,7 +306,7 @@ export class CMI extends BaseCMI {
* @param {string} location
*/
set location(location) {
if (check2004ValidFormat(location, regex.CMIString1000)) {
if (check2004ValidFormat(location, scorm2004_regex.CMIString1000)) {
this.#location = location;
}
}
@@ -355,8 +358,8 @@ export class CMI extends BaseCMI {
* @param {string} progress_measure
*/
set progress_measure(progress_measure) {
if (check2004ValidFormat(progress_measure, regex.CMIDecimal) &&
check2004ValidRange(progress_measure, regex.progress_range)) {
if (check2004ValidFormat(progress_measure, scorm2004_regex.CMIDecimal) &&
check2004ValidRange(progress_measure, scorm2004_regex.progress_range)) {
this.#progress_measure = progress_measure;
}
}
@@ -392,7 +395,7 @@ export class CMI extends BaseCMI {
* @param {string} session_time
*/
set session_time(session_time) {
if (check2004ValidFormat(session_time, regex.CMITimespan)) {
if (check2004ValidFormat(session_time, scorm2004_regex.CMITimespan)) {
this.#session_time = session_time;
}
}
@@ -410,7 +413,7 @@ export class CMI extends BaseCMI {
* @param {string} success_status
*/
set success_status(success_status) {
if (check2004ValidFormat(success_status, regex.CMISStatus)) {
if (check2004ValidFormat(success_status, scorm2004_regex.CMISStatus)) {
this.#success_status = success_status;
}
}
@@ -428,7 +431,7 @@ export class CMI extends BaseCMI {
* @param {string} suspend_data
*/
set suspend_data(suspend_data) {
if (check2004ValidFormat(suspend_data, regex.CMIString64000, true)) {
if (check2004ValidFormat(suspend_data, scorm2004_regex.CMIString64000, true)) {
this.#suspend_data = suspend_data;
}
}
@@ -547,7 +550,7 @@ export class CMI extends BaseCMI {
* Class for SCORM 2004's cmi.learner_preference object
*/
class CMILearnerPreference extends BaseCMI {
#_children = constants.student_preference_children;
#_children = scorm2004_constants.student_preference_children;
#audio_level = '1';
#language = '';
#delivery_speed = '1';
@@ -591,8 +594,8 @@ class CMILearnerPreference extends BaseCMI {
* @param {string} audio_level
*/
set audio_level(audio_level) {
if (check2004ValidFormat(audio_level, regex.CMIDecimal) &&
check2004ValidRange(audio_level, regex.audio_range)) {
if (check2004ValidFormat(audio_level, scorm2004_regex.CMIDecimal) &&
check2004ValidRange(audio_level, scorm2004_regex.audio_range)) {
this.#audio_level = audio_level;
}
}
@@ -610,7 +613,7 @@ class CMILearnerPreference extends BaseCMI {
* @param {string} language
*/
set language(language) {
if (check2004ValidFormat(language, regex.CMILang)) {
if (check2004ValidFormat(language, scorm2004_regex.CMILang)) {
this.#language = language;
}
}
@@ -628,8 +631,8 @@ class CMILearnerPreference extends BaseCMI {
* @param {string} delivery_speed
*/
set delivery_speed(delivery_speed) {
if (check2004ValidFormat(delivery_speed, regex.CMIDecimal) &&
check2004ValidRange(delivery_speed, regex.speed_range)) {
if (check2004ValidFormat(delivery_speed, scorm2004_regex.CMIDecimal) &&
check2004ValidRange(delivery_speed, scorm2004_regex.speed_range)) {
this.#delivery_speed = delivery_speed;
}
}
@@ -647,8 +650,8 @@ class CMILearnerPreference extends BaseCMI {
* @param {string} audio_captioning
*/
set audio_captioning(audio_captioning) {
if (check2004ValidFormat(audio_captioning, regex.CMISInteger) &&
check2004ValidRange(audio_captioning, regex.text_range)) {
if (check2004ValidFormat(audio_captioning, scorm2004_regex.CMISInteger) &&
check2004ValidRange(audio_captioning, scorm2004_regex.text_range)) {
this.#audio_captioning = audio_captioning;
}
}
@@ -687,7 +690,7 @@ class CMIInteractions extends CMIArray {
*/
constructor() {
super({
children: constants.interactions_children,
children: scorm2004_constants.interactions_children,
errorCode: scorm2004_error_codes.READ_ONLY_ELEMENT,
});
}
@@ -702,7 +705,7 @@ class CMIObjectives extends CMIArray {
*/
constructor() {
super({
children: constants.objectives_children,
children: scorm2004_constants.objectives_children,
errorCode: scorm2004_error_codes.READ_ONLY_ELEMENT,
});
}
@@ -717,7 +720,7 @@ class CMICommentsFromLMS extends CMIArray {
*/
constructor() {
super({
children: constants.comments_children,
children: scorm2004_constants.comments_children,
errorCode: scorm2004_error_codes.READ_ONLY_ELEMENT,
});
}
@@ -732,7 +735,7 @@ class CMICommentsFromLearner extends CMIArray {
*/
constructor() {
super({
children: constants.comments_children,
children: scorm2004_constants.comments_children,
errorCode: scorm2004_error_codes.READ_ONLY_ELEMENT,
});
}
@@ -759,11 +762,11 @@ export class CMIInteractionsObject extends BaseCMI {
this.objectives = new CMIArray({
errorCode: scorm2004_error_codes.READ_ONLY_ELEMENT,
children: constants.objectives_children,
children: scorm2004_constants.objectives_children,
});
this.correct_responses = new CMIArray({
errorCode: scorm2004_error_codes.READ_ONLY_ELEMENT,
children: constants.correct_responses_children,
children: scorm2004_constants.correct_responses_children,
});
}
@@ -789,7 +792,7 @@ export class CMIInteractionsObject extends BaseCMI {
* @param {string} id
*/
set id(id) {
if (check2004ValidFormat(id, regex.CMILongIdentifier)) {
if (check2004ValidFormat(id, scorm2004_regex.CMILongIdentifier)) {
this.#id = id;
}
}
@@ -807,7 +810,7 @@ export class CMIInteractionsObject extends BaseCMI {
* @param {string} type
*/
set type(type) {
if (check2004ValidFormat(type, regex.CMIType)) {
if (check2004ValidFormat(type, scorm2004_regex.CMIType)) {
this.#type = type;
}
}
@@ -825,7 +828,7 @@ export class CMIInteractionsObject extends BaseCMI {
* @param {string} timestamp
*/
set timestamp(timestamp) {
if (check2004ValidFormat(timestamp, regex.CMITime)) {
if (check2004ValidFormat(timestamp, scorm2004_regex.CMITime)) {
this.#timestamp = timestamp;
}
}
@@ -843,7 +846,7 @@ export class CMIInteractionsObject extends BaseCMI {
* @param {string} weighting
*/
set weighting(weighting) {
if (check2004ValidFormat(weighting, regex.CMIDecimal)) {
if (check2004ValidFormat(weighting, scorm2004_regex.CMIDecimal)) {
this.#weighting = weighting;
}
}
@@ -868,44 +871,48 @@ export class CMIInteractionsObject extends BaseCMI {
} else {
let nodes = [];
const response_type = learner_responses[this.type];
if (response_type.delimiter !== '') {
nodes = learner_response.split(response_type.delimiter);
} else {
nodes[0] = learner_response;
}
if (response_type) {
if (response_type?.delimiter) {
nodes = learner_response.split(response_type.delimiter);
} else {
nodes[0] = learner_response;
}
if ((nodes.length > 0) && (nodes.length <= response_type.max)) {
const formatRegex = new RegExp(response_type.format);
for (let i = 0; i < nodes.length; i++) {
if (typeof response_type.delimiter2 !== 'undefined') {
const values = nodes[i].split(response_type.delimiter2);
if (values.length === 2) {
if (!values[0].match(formatRegex)) {
throwTypeMismatchError();
} else {
if (!values[1].match(new RegExp(response_type.format2))) {
if ((nodes.length > 0) && (nodes.length <= response_type.max)) {
const formatRegex = new RegExp(response_type.format);
for (let i = 0; i < nodes.length; i++) {
if (response_type?.delimiter2) {
const values = nodes[i].split(response_type.delimiter2);
if (values.length === 2) {
if (!values[0].match(formatRegex)) {
throwTypeMismatchError();
} else {
if (!values[1].match(new RegExp(response_type.format2))) {
throwTypeMismatchError();
}
}
} else {
throwTypeMismatchError();
}
} else {
throwTypeMismatchError();
}
} else {
if (!nodes[i].match(formatRegex)) {
throwTypeMismatchError();
} else {
if (nodes[i] !== '' && response_type.unique) {
for (let j = 0; j < i; j++) {
if (nodes[i] === nodes[j]) {
throwTypeMismatchError();
if (!nodes[i].match(formatRegex)) {
throwTypeMismatchError();
} else {
if (nodes[i] !== '' && response_type.unique) {
for (let j = 0; j < i; j++) {
if (nodes[i] === nodes[j]) {
throwTypeMismatchError();
}
}
}
}
}
}
} else {
throw new ValidationError(scorm2004_error_codes.GENERAL_SET_FAILURE);
}
} else {
throw new ValidationError(scorm2004_error_codes.GENERAL_SET_FAILURE);
throw new ValidationError(scorm2004_error_codes.TYPE_MISMATCH);
}
}
}
@@ -923,7 +930,7 @@ export class CMIInteractionsObject extends BaseCMI {
* @param {string} result
*/
set result(result) {
if (check2004ValidFormat(result, regex.CMIResult)) {
if (check2004ValidFormat(result, scorm2004_regex.CMIResult)) {
this.#result = result;
}
}
@@ -941,7 +948,7 @@ export class CMIInteractionsObject extends BaseCMI {
* @param {string} latency
*/
set latency(latency) {
if (check2004ValidFormat(latency, regex.CMITimespan)) {
if (check2004ValidFormat(latency, scorm2004_regex.CMITimespan)) {
this.#latency = latency;
}
}
@@ -959,7 +966,7 @@ export class CMIInteractionsObject extends BaseCMI {
* @param {string} description
*/
set description(description) {
if (check2004ValidFormat(description, regex.CMILangString250, true)) {
if (check2004ValidFormat(description, scorm2004_regex.CMILangString250, true)) {
this.#description = description;
}
}
@@ -1041,7 +1048,7 @@ export class CMIObjectivesObject extends BaseCMI {
* @param {string} id
*/
set id(id) {
if (check2004ValidFormat(id, regex.CMILongIdentifier)) {
if (check2004ValidFormat(id, scorm2004_regex.CMILongIdentifier)) {
this.#id = id;
}
}
@@ -1059,7 +1066,7 @@ export class CMIObjectivesObject extends BaseCMI {
* @param {string} success_status
*/
set success_status(success_status) {
if (check2004ValidFormat(success_status, regex.CMISStatus)) {
if (check2004ValidFormat(success_status, scorm2004_regex.CMISStatus)) {
this.#success_status = success_status;
}
}
@@ -1077,7 +1084,7 @@ export class CMIObjectivesObject extends BaseCMI {
* @param {string} completion_status
*/
set completion_status(completion_status) {
if (check2004ValidFormat(completion_status, regex.CMICStatus)) {
if (check2004ValidFormat(completion_status, scorm2004_regex.CMICStatus)) {
this.#completion_status = completion_status;
}
}
@@ -1095,8 +1102,8 @@ export class CMIObjectivesObject extends BaseCMI {
* @param {string} progress_measure
*/
set progress_measure(progress_measure) {
if (check2004ValidFormat(progress_measure, regex.CMIDecimal) &&
check2004ValidRange(progress_measure, regex.progress_range)) {
if (check2004ValidFormat(progress_measure, scorm2004_regex.CMIDecimal) &&
check2004ValidRange(progress_measure, scorm2004_regex.progress_range)) {
this.#progress_measure = progress_measure;
}
}
@@ -1114,7 +1121,7 @@ export class CMIObjectivesObject extends BaseCMI {
* @param {string} description
*/
set description(description) {
if (check2004ValidFormat(description, regex.CMILangString250, true)) {
if (check2004ValidFormat(description, scorm2004_regex.CMILangString250, true)) {
this.#description = description;
}
}
@@ -1160,7 +1167,7 @@ class Scorm2004CMIScore extends CMIScore {
constructor() {
super(
{
score_children: constants.score_children,
score_children: scorm2004_constants.score_children,
max: '',
invalidErrorCode: scorm2004_error_codes.READ_ONLY_ELEMENT,
invalidTypeCode: scorm2004_error_codes.TYPE_MISMATCH,
@@ -1182,8 +1189,8 @@ class Scorm2004CMIScore extends CMIScore {
* @param {string} scaled
*/
set scaled(scaled) {
if (check2004ValidFormat(scaled, regex.CMIDecimal) &&
check2004ValidRange(scaled, regex.scaled_range)) {
if (check2004ValidFormat(scaled, scorm2004_regex.CMIDecimal) &&
check2004ValidRange(scaled, scorm2004_regex.scaled_range)) {
this.#scaled = scaled;
}
}
@@ -1250,7 +1257,7 @@ export class CMICommentsObject extends BaseCMI {
if (this.initialized && this.#readOnlyAfterInit) {
throwReadOnlyError();
} else {
if (check2004ValidFormat(comment, regex.CMILangString4000, true)) {
if (check2004ValidFormat(comment, scorm2004_regex.CMILangString4000, true)) {
this.#comment = comment;
}
}
@@ -1272,7 +1279,7 @@ export class CMICommentsObject extends BaseCMI {
if (this.initialized && this.#readOnlyAfterInit) {
throwReadOnlyError();
} else {
if (check2004ValidFormat(location, regex.CMIString250)) {
if (check2004ValidFormat(location, scorm2004_regex.CMIString250)) {
this.#location = location;
}
}
@@ -1294,7 +1301,7 @@ export class CMICommentsObject extends BaseCMI {
if (this.initialized && this.#readOnlyAfterInit) {
throwReadOnlyError();
} else {
if (check2004ValidFormat(timestamp, regex.CMITime)) {
if (check2004ValidFormat(timestamp, scorm2004_regex.CMITime)) {
this.#timestamp = timestamp;
}
}
@@ -1348,7 +1355,7 @@ export class CMIInteractionsObjectivesObject extends BaseCMI {
* @param {string} id
*/
set id(id) {
if (check2004ValidFormat(id, regex.CMILongIdentifier)) {
if (check2004ValidFormat(id, scorm2004_regex.CMILongIdentifier)) {
this.#id = id;
}
}
@@ -1397,7 +1404,7 @@ export class CMIInteractionsCorrectResponsesObject extends BaseCMI {
* @param {string} pattern
*/
set pattern(pattern) {
if (check2004ValidFormat(pattern, regex.CMIFeedback)) {
if (check2004ValidFormat(pattern, scorm2004_regex.CMIFeedback)) {
this.#pattern = pattern;
}
}
@@ -1497,7 +1504,7 @@ class ADLNav extends BaseCMI {
* @param {string} request
*/
set request(request) {
if (check2004ValidFormat(request, regex.NAVEvent)) {
if (check2004ValidFormat(request, scorm2004_regex.NAVEvent)) {
this.#request = request;
}
}