@khanacademy/perseus 41.3.0 → 41.4.0

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 CHANGED
@@ -1464,7 +1464,7 @@ const MAXERROR_EPSILON = Math.pow(2, -42);
1464
1464
  // TOOD(kevinb): Figure out how this relates to KEScore in
1465
1465
  // perseus-all-package/types.js and see if there's a way to
1466
1466
  // unify these types.
1467
- /*
1467
+ /**
1468
1468
  * Answer types
1469
1469
  *
1470
1470
  * Utility for creating answerable questions displayed in exercises
@@ -1507,7 +1507,6 @@ const MAXERROR_EPSILON = Math.pow(2, -42);
1507
1507
  * TODO(alpert): Think of a less-absurd name for createValidatorFunctional.
1508
1508
  *
1509
1509
  */
1510
-
1511
1510
  const KhanAnswerTypes = {
1512
1511
  /*
1513
1512
  * predicate answer type
@@ -1978,9 +1977,7 @@ const KhanAnswerTypes = {
1978
1977
  })];
1979
1978
  },
1980
1979
  createValidatorFunctional: function (correctAnswer, options, strings) {
1981
- return KhanAnswerTypes.predicate.createValidatorFunctional(
1982
- // @ts-expect-error - TS2556 - A spread argument must either have a tuple type or be passed to a rest parameter.
1983
- ...KhanAnswerTypes.number.convertToPredicate(correctAnswer, options), strings);
1980
+ return KhanAnswerTypes.predicate.createValidatorFunctional(...KhanAnswerTypes.number.convertToPredicate(correctAnswer, options), strings);
1984
1981
  }
1985
1982
  },
1986
1983
  /*
@@ -32064,6 +32061,9 @@ function replaceOutsideTeX(mathString) {
32064
32061
  // Condense adjacent text nodes into a single text node
32065
32062
  function condenseTextNodes(nodes) {
32066
32063
  const result = [];
32064
+ if (!nodes) {
32065
+ return result;
32066
+ }
32067
32067
  let currentText = "";
32068
32068
  for (const node of nodes) {
32069
32069
  if (node.type === "math") {
@@ -44149,17 +44149,23 @@ var Sorter$1 = {
44149
44149
  scorer: scoreSorter
44150
44150
  };
44151
44151
 
44152
- function scoreTable(state, rubric, strings) {
44153
- const filterNonEmpty = function filterNonEmpty(table) {
44154
- return _.filter(table, function (row) {
44155
- // Check if row has a cell that is nonempty
44156
- return _.some(row, _.identity);
44157
- });
44158
- };
44159
- const solution = filterNonEmpty(rubric.answers);
44160
- const supplied = filterNonEmpty(state);
44161
- const hasEmptyCell = _.some(supplied, function (row) {
44162
- return _.some(row, function (cell) {
44152
+ /**
44153
+ * Filters the given table (modelled as a 2D array) to remove any rows that are
44154
+ * completely empty.
44155
+ *
44156
+ * @returns A new table with only non-empty rows.
44157
+ */
44158
+ const filterNonEmpty = function filterNonEmpty(table) {
44159
+ return table.filter(function (row) {
44160
+ // Return only rows that are non-empty.
44161
+ return row.some(cell => cell);
44162
+ });
44163
+ };
44164
+
44165
+ function validateTable(userInput) {
44166
+ const supplied = filterNonEmpty(userInput);
44167
+ const hasEmptyCell = supplied.some(function (row) {
44168
+ return row.some(function (cell) {
44163
44169
  return cell === "";
44164
44170
  });
44165
44171
  });
@@ -44169,6 +44175,16 @@ function scoreTable(state, rubric, strings) {
44169
44175
  message: null
44170
44176
  };
44171
44177
  }
44178
+ return null;
44179
+ }
44180
+
44181
+ function scoreTable(userInput, rubric, strings) {
44182
+ const validationResult = validateTable(userInput);
44183
+ if (validationResult != null) {
44184
+ return validationResult;
44185
+ }
44186
+ const supplied = filterNonEmpty(userInput);
44187
+ const solution = filterNonEmpty(rubric.answers);
44172
44188
  if (supplied.length !== solution.length) {
44173
44189
  return {
44174
44190
  type: "points",
@@ -44179,17 +44195,16 @@ function scoreTable(state, rubric, strings) {
44179
44195
  }
44180
44196
  const createValidator = KhanAnswerTypes.number.createValidatorFunctional;
44181
44197
  let message = null;
44182
- const allCorrect = _.every(solution, function (rowSolution) {
44198
+ const allCorrect = solution.every(function (rowSolution) {
44183
44199
  for (let i = 0; i < supplied.length; i++) {
44184
44200
  const rowSupplied = supplied[i];
44185
- const correct = _.every(rowSupplied, function (cellSupplied, i) {
44201
+ const correct = rowSupplied.every(function (cellSupplied, i) {
44186
44202
  const cellSolution = rowSolution[i];
44187
44203
  const validator = createValidator(cellSolution, {
44188
44204
  simplify: true
44189
44205
  }, strings);
44190
44206
  const result = validator(cellSupplied);
44191
44207
  if (result.message) {
44192
- // @ts-expect-error - TS2322 - Type 'string' is not assignable to type 'null'.
44193
44208
  message = result.message;
44194
44209
  }
44195
44210
  return result.correct;
@@ -44205,7 +44220,7 @@ function scoreTable(state, rubric, strings) {
44205
44220
  type: "points",
44206
44221
  earned: allCorrect ? 1 : 0,
44207
44222
  total: 1,
44208
- message: message
44223
+ message
44209
44224
  };
44210
44225
  }
44211
44226
 
@@ -44609,7 +44624,7 @@ const init = function init() {
44609
44624
 
44610
44625
  // This file is processed by a Rollup plugin (replace) to inject the production
44611
44626
  const libName = "@khanacademy/perseus";
44612
- const libVersion = "41.3.0";
44627
+ const libVersion = "41.4.0";
44613
44628
  addLibraryVersionToPerseusDebug(libName, libVersion);
44614
44629
 
44615
44630
  const apiVersion = {