@khanacademy/perseus-score 7.7.6 → 7.7.8

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.
package/dist/index.js CHANGED
@@ -44,7 +44,7 @@ function scoreDropdown(userInput,rubric){if(userInput==null){return {type:"inval
44
44
 
45
45
  function validateDropdown(userInput){if(userInput==null){return {type:"invalid",message:null}}if(userInput.value===0){return {type:"invalid",message:null}}return null}
46
46
 
47
- function scoreExpression(userInput,rubric,locale){if(userInput==null){return {type:"invalid",message:null}}const options=___default.default.clone(rubric);___default.default.extend(options,{decimal_separator:perseusCore.getDecimalSeparator(locale)});if(!KAS__namespace.parse(userInput,options).parsed){return {type:"invalid",message:ErrorCodes.EXTRA_SYMBOLS_ERROR}}const createValidator=answer=>{const expression=KAS__namespace.parse(answer.value,rubric);if(!expression.parsed){throw new perseusCore.PerseusError("Unable to parse solution answer for expression",perseusCore.Errors.InvalidInput,{metadata:{rubric:JSON.stringify(rubric)}})}return KhanAnswerTypes.expression.createValidatorFunctional(expression.expr,___default.default({}).extend(options,{simplify:answer.simplify,form:answer.form}))};let matchingAnswerForm;let matchMessage;let allEmpty=true;let firstUngradedResult;for(const answerForm of rubric.answerForms||[]){const validator=createValidator(answerForm);if(!validator){continue}const result=validator(userInput);if(result.correct){matchingAnswerForm=answerForm;matchMessage=result.message||"";break}allEmpty=allEmpty&&result.empty;if(answerForm.considered==="correct"&&result.ungraded&&!firstUngradedResult){firstUngradedResult=result;}}if(!matchingAnswerForm){if(firstUngradedResult){return {type:"invalid",message:firstUngradedResult.message,suppressAlmostThere:firstUngradedResult.suppressAlmostThere}}if(allEmpty){return {type:"invalid",message:null}}return {type:"points",earned:0,total:1}}if(matchingAnswerForm.considered==="ungraded"){return {type:"invalid",message:matchMessage}}return {type:"points",earned:matchingAnswerForm.considered==="correct"?1:0,total:1,message:matchMessage}}
47
+ function scoreExpression(userInput,rubric,locale){if(userInput==null){return {type:"invalid",message:null}}const options=___default.default.clone(rubric);___default.default.extend(options,{decimal_separator:perseusCore.getDecimalSeparator(locale),divide_symbol:perseusCore.getDivideSymbol(locale)});if(!KAS__namespace.parse(userInput,options).parsed){return {type:"invalid",message:ErrorCodes.EXTRA_SYMBOLS_ERROR}}const createValidator=answer=>{const expression=KAS__namespace.parse(answer.value,rubric);if(!expression.parsed){throw new perseusCore.PerseusError("Unable to parse solution answer for expression",perseusCore.Errors.InvalidInput,{metadata:{rubric:JSON.stringify(rubric)}})}return KhanAnswerTypes.expression.createValidatorFunctional(expression.expr,___default.default({}).extend(options,{simplify:answer.simplify,form:answer.form}))};let matchingAnswerForm;let matchMessage;let allEmpty=true;let firstUngradedResult;for(const answerForm of rubric.answerForms||[]){const validator=createValidator(answerForm);if(!validator){continue}const result=validator(userInput);if(result.correct){matchingAnswerForm=answerForm;matchMessage=result.message||"";break}allEmpty=allEmpty&&result.empty;if(answerForm.considered==="correct"&&result.ungraded&&!firstUngradedResult){firstUngradedResult=result;}}if(!matchingAnswerForm){if(firstUngradedResult){return {type:"invalid",message:firstUngradedResult.message,suppressAlmostThere:firstUngradedResult.suppressAlmostThere}}if(allEmpty){return {type:"invalid",message:null}}return {type:"points",earned:0,total:1}}if(matchingAnswerForm.considered==="ungraded"){return {type:"invalid",message:matchMessage}}return {type:"points",earned:matchingAnswerForm.considered==="correct"?1:0,total:1,message:matchMessage}}
48
48
 
49
49
  function validateExpression(userInput){if(userInput===""||userInput==null){return {type:"invalid",message:null}}return null}
50
50