@khanacademy/perseus-score 0.0.0-PR875-20250221232857 → 0.0.0-PR875-20250225011257
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/es/index.js +18 -0
- package/dist/es/index.js.map +1 -1
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -256,6 +256,14 @@ const KhanAnswerTypes = {
|
|
|
256
256
|
},
|
|
257
257
|
// an improper fraction
|
|
258
258
|
improper: function (text) {
|
|
259
|
+
// As our answer keys are always in simplest form, we need
|
|
260
|
+
// to check for the existence of a fraction in the input before
|
|
261
|
+
// validating the answer. If no fraction is found, we consider
|
|
262
|
+
// the answer to be incorrect.
|
|
263
|
+
const fractionExists = text.includes("/") || text.match(/\\(d?frac)/);
|
|
264
|
+
if (!fractionExists) {
|
|
265
|
+
return [];
|
|
266
|
+
}
|
|
259
267
|
return $__default["default"].map(fractionTransformer(text), function (o) {
|
|
260
268
|
// All fractions that are greater than 1
|
|
261
269
|
if (Math.abs(o.value) >= 1) {
|
|
@@ -1484,6 +1492,16 @@ function parseNextExpression(tex, currentIndex, handler) {
|
|
|
1484
1492
|
// Find the first '{' and grab subsequent TeX
|
|
1485
1493
|
// Ex) tex: '{3}{7}', and we want the '3'
|
|
1486
1494
|
const openBracketIndex = tex.indexOf("{", currentIndex);
|
|
1495
|
+
|
|
1496
|
+
// If there is no open bracket, set the endpoint to the end of the string
|
|
1497
|
+
// and the expression to an empty string. This helps ensure we don't
|
|
1498
|
+
// get stuck in an infinite loop when users handtype TeX.
|
|
1499
|
+
if (openBracketIndex === -1) {
|
|
1500
|
+
return {
|
|
1501
|
+
endpoint: tex.length,
|
|
1502
|
+
expression: ""
|
|
1503
|
+
};
|
|
1504
|
+
}
|
|
1487
1505
|
const nextExpIndex = openBracketIndex + 1;
|
|
1488
1506
|
|
|
1489
1507
|
// Truncate to only contain remaining TeX
|