@khanacademy/perseus-score 2.3.4 → 2.3.6

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
@@ -1,10 +1,9 @@
1
+ import _extends from '@babel/runtime/helpers/extends';
1
2
  import * as KAS from '@khanacademy/kas';
2
3
  import { KhanMath, number, geometry, angles, coefficients } from '@khanacademy/kmath';
3
4
  import { PerseusError, Errors, getDecimalSeparator, GrapherUtil, approximateDeepEqual, approximateEqual, deepClone, getMatrixSize, getWidgetIdsFromContent, getUpgradedWidgetOptions } from '@khanacademy/perseus-core';
4
- import $ from 'jquery';
5
5
  import _ from 'underscore';
6
6
  import { ErrorCodes as ErrorCodes$1 } from '@khanacademy/perseus-score';
7
- import _extends from '@babel/runtime/helpers/extends';
8
7
 
9
8
  const MISSING_PERCENT_ERROR = "MISSING_PERCENT_ERROR";
10
9
  const NEEDS_TO_BE_SIMPLIFIED_ERROR = "NEEDS_TO_BE_SIMPLIFIED_ERROR";
@@ -31,7 +30,6 @@ const ErrorCodes = {
31
30
  FILL_ALL_CELLS_ERROR
32
31
  };
33
32
 
34
- /* eslint-disable no-useless-escape */
35
33
  const MAXERROR_EPSILON = Math.pow(2, -42);
36
34
 
37
35
  // TOOD(kevinb): Figure out how this relates to KEScore in
@@ -219,7 +217,8 @@ const KhanAnswerTypes = {
219
217
  },
220
218
  // A proper fraction
221
219
  proper: function (text) {
222
- return $.map(fractionTransformer(text), function (o) {
220
+ const transformed = fractionTransformer(text);
221
+ return transformed.flatMap(o => {
223
222
  // All fractions that are less than 1
224
223
  if (Math.abs(o.value) < 1) {
225
224
  return [o];
@@ -237,7 +236,8 @@ const KhanAnswerTypes = {
237
236
  if (!fractionExists) {
238
237
  return [];
239
238
  }
240
- return $.map(fractionTransformer(text), function (o) {
239
+ const transformed = fractionTransformer(text);
240
+ return transformed.flatMap(o => {
241
241
  // All fractions that are greater than 1
242
242
  if (Math.abs(o.value) >= 1) {
243
243
  return [o];
@@ -338,7 +338,7 @@ const KhanAnswerTypes = {
338
338
  if (text.match(/pau/)) {
339
339
  multiplier = Math.PI * 1.5;
340
340
  }
341
- $.each(possibilities, function (ix, possibility) {
341
+ possibilities.forEach(possibility => {
342
342
  possibility.value *= multiplier;
343
343
  });
344
344
  return possibilities;
@@ -385,15 +385,15 @@ const KhanAnswerTypes = {
385
385
  },
386
386
  // Numbers with percent signs
387
387
  percent: function (text) {
388
- text = $.trim(text);
388
+ text = String(text).trim();
389
389
  // store whether or not there is a percent sign
390
390
  let hasPercentSign = false;
391
391
  if (text.indexOf("%") === text.length - 1) {
392
- text = $.trim(text.substring(0, text.length - 1));
392
+ text = text.substring(0, text.length - 1).trim();
393
393
  hasPercentSign = true;
394
394
  }
395
395
  const transformed = forms.decimal(text);
396
- $.each(transformed, function (ix, t) {
396
+ transformed.forEach(t => {
397
397
  t.exact = hasPercentSign;
398
398
  // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
399
399
  t.value = t.value / 100;
@@ -430,7 +430,7 @@ const KhanAnswerTypes = {
430
430
  // precision == 1.)
431
431
  decimal: function (text, precision = 1e10) {
432
432
  const normal = function normal(text) {
433
- text = $.trim(text);
433
+ text = String(text).trim();
434
434
  const match = text
435
435
  // Replace unicode minus sign with hyphen
436
436
  .replace(/\u2212/, "-")
@@ -473,7 +473,7 @@ const KhanAnswerTypes = {
473
473
  // The fallback variable is used in place of the answer, if no
474
474
  // answer is provided (i.e. the field is left blank)
475
475
  const fallback = options.fallback != null ? "" + options.fallback : "";
476
- guess = $.trim(guess) || fallback;
476
+ guess = String(guess).trim() || fallback;
477
477
  const score = {
478
478
  empty: guess === "",
479
479
  correct: false,
@@ -483,7 +483,7 @@ const KhanAnswerTypes = {
483
483
 
484
484
  // iterate over all the acceptable forms, and if one of the
485
485
  // answers is correct, return true
486
- $.each(acceptableForms, function (i, form) {
486
+ acceptableForms.forEach(form => {
487
487
  const transformed = forms[form](guess);
488
488
  for (let j = 0, l = transformed.length; j < l; j++) {
489
489
  const val = transformed[j].value;
@@ -554,7 +554,7 @@ const KhanAnswerTypes = {
554
554
  const correctFloat = parseFloat(correctAnswer);
555
555
  return [function (guess, maxError) {
556
556
  return Math.abs(guess - correctFloat) < maxError;
557
- }, $.extend({}, options, {
557
+ }, _extends({}, options, {
558
558
  type: "predicate"
559
559
  })];
560
560
  },
@@ -2221,7 +2221,13 @@ function flattenScores(widgetScoreMap) {
2221
2221
  return Object.values(widgetScoreMap).reduce(combineScores, noScore);
2222
2222
  }
2223
2223
 
2224
- // once scorePerseusItem is the only one calling scoreWidgetsFunctional
2224
+ /**
2225
+ * score a Perseus item
2226
+ *
2227
+ * @param perseusRenderData - the full answer data, includes the correct answer
2228
+ * @param userInputMap - the user's input for each widget, mapped by ID
2229
+ * @param locale - string locale for math parsing ("de" 1.000,00 vs "en" 1,000.00)
2230
+ */
2225
2231
  function scorePerseusItem(perseusRenderData, userInputMap, locale) {
2226
2232
  // There seems to be a chance that PerseusRenderer.widgets might include
2227
2233
  // widget data for widgets that are not in PerseusRenderer.content,