@khanacademy/perseus-score 2.3.5 → 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/index.js CHANGED
@@ -5,7 +5,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var KAS = require('@khanacademy/kas');
6
6
  var kmath = require('@khanacademy/kmath');
7
7
  var perseusCore = require('@khanacademy/perseus-core');
8
- var $ = require('jquery');
9
8
  var _ = require('underscore');
10
9
  var perseusScore = require('@khanacademy/perseus-score');
11
10
 
@@ -30,7 +29,6 @@ function _interopNamespace(e) {
30
29
  }
31
30
 
32
31
  var KAS__namespace = /*#__PURE__*/_interopNamespace(KAS);
33
- var $__default = /*#__PURE__*/_interopDefaultLegacy($);
34
32
  var ___default = /*#__PURE__*/_interopDefaultLegacy(_);
35
33
 
36
34
  const MISSING_PERCENT_ERROR = "MISSING_PERCENT_ERROR";
@@ -246,7 +244,8 @@ const KhanAnswerTypes = {
246
244
  },
247
245
  // A proper fraction
248
246
  proper: function (text) {
249
- return $__default["default"].map(fractionTransformer(text), function (o) {
247
+ const transformed = fractionTransformer(text);
248
+ return transformed.flatMap(o => {
250
249
  // All fractions that are less than 1
251
250
  if (Math.abs(o.value) < 1) {
252
251
  return [o];
@@ -264,7 +263,8 @@ const KhanAnswerTypes = {
264
263
  if (!fractionExists) {
265
264
  return [];
266
265
  }
267
- return $__default["default"].map(fractionTransformer(text), function (o) {
266
+ const transformed = fractionTransformer(text);
267
+ return transformed.flatMap(o => {
268
268
  // All fractions that are greater than 1
269
269
  if (Math.abs(o.value) >= 1) {
270
270
  return [o];
@@ -365,7 +365,7 @@ const KhanAnswerTypes = {
365
365
  if (text.match(/pau/)) {
366
366
  multiplier = Math.PI * 1.5;
367
367
  }
368
- $__default["default"].each(possibilities, function (ix, possibility) {
368
+ possibilities.forEach(possibility => {
369
369
  possibility.value *= multiplier;
370
370
  });
371
371
  return possibilities;
@@ -412,15 +412,15 @@ const KhanAnswerTypes = {
412
412
  },
413
413
  // Numbers with percent signs
414
414
  percent: function (text) {
415
- text = $__default["default"].trim(text);
415
+ text = String(text).trim();
416
416
  // store whether or not there is a percent sign
417
417
  let hasPercentSign = false;
418
418
  if (text.indexOf("%") === text.length - 1) {
419
- text = $__default["default"].trim(text.substring(0, text.length - 1));
419
+ text = text.substring(0, text.length - 1).trim();
420
420
  hasPercentSign = true;
421
421
  }
422
422
  const transformed = forms.decimal(text);
423
- $__default["default"].each(transformed, function (ix, t) {
423
+ transformed.forEach(t => {
424
424
  t.exact = hasPercentSign;
425
425
  // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
426
426
  t.value = t.value / 100;
@@ -458,7 +458,7 @@ const KhanAnswerTypes = {
458
458
  decimal: function (text) {
459
459
  let precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1e10;
460
460
  const normal = function (text) {
461
- text = $__default["default"].trim(text);
461
+ text = String(text).trim();
462
462
  const match = text
463
463
  // Replace unicode minus sign with hyphen
464
464
  .replace(/\u2212/, "-")
@@ -501,7 +501,7 @@ const KhanAnswerTypes = {
501
501
  // The fallback variable is used in place of the answer, if no
502
502
  // answer is provided (i.e. the field is left blank)
503
503
  const fallback = options.fallback != null ? "" + options.fallback : "";
504
- guess = $__default["default"].trim(guess) || fallback;
504
+ guess = String(guess).trim() || fallback;
505
505
  const score = {
506
506
  empty: guess === "",
507
507
  correct: false,
@@ -511,7 +511,7 @@ const KhanAnswerTypes = {
511
511
 
512
512
  // iterate over all the acceptable forms, and if one of the
513
513
  // answers is correct, return true
514
- $__default["default"].each(acceptableForms, function (i, form) {
514
+ acceptableForms.forEach(form => {
515
515
  const transformed = forms[form](guess);
516
516
  for (let j = 0, l = transformed.length; j < l; j++) {
517
517
  const val = transformed[j].value;
@@ -582,9 +582,10 @@ const KhanAnswerTypes = {
582
582
  const correctFloat = parseFloat(correctAnswer);
583
583
  return [function (guess, maxError) {
584
584
  return Math.abs(guess - correctFloat) < maxError;
585
- }, $__default["default"].extend({}, options, {
585
+ }, {
586
+ ...options,
586
587
  type: "predicate"
587
- })];
588
+ }];
588
589
  },
589
590
  createValidatorFunctional: function (correctAnswer, options) {
590
591
  return KhanAnswerTypes.predicate.createValidatorFunctional(...KhanAnswerTypes.number.convertToPredicate(correctAnswer, options));
@@ -2247,7 +2248,13 @@ function flattenScores(widgetScoreMap) {
2247
2248
  return Object.values(widgetScoreMap).reduce(combineScores, noScore);
2248
2249
  }
2249
2250
 
2250
- // once scorePerseusItem is the only one calling scoreWidgetsFunctional
2251
+ /**
2252
+ * score a Perseus item
2253
+ *
2254
+ * @param perseusRenderData - the full answer data, includes the correct answer
2255
+ * @param userInputMap - the user's input for each widget, mapped by ID
2256
+ * @param locale - string locale for math parsing ("de" 1.000,00 vs "en" 1,000.00)
2257
+ */
2251
2258
  function scorePerseusItem(perseusRenderData, userInputMap, locale) {
2252
2259
  // There seems to be a chance that PerseusRenderer.widgets might include
2253
2260
  // widget data for widgets that are not in PerseusRenderer.content,