@khanacademy/perseus-score 2.3.5 → 2.3.7

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