@khanacademy/kas 0.3.16 → 0.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.
@@ -0,0 +1,3 @@
1
+ export { libVersion } from "./version";
2
+ export * from "./nodes";
3
+ export { compare } from "./compare";
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ var ___default = /*#__PURE__*/_interopDefaultLegacy(_);
11
11
 
12
12
  // This file is processed by a Rollup plugin (replace) to inject the production
13
13
  const libName = "@khanacademy/kas";
14
- const libVersion = "0.3.16";
14
+ const libVersion = "0.4.0";
15
15
  perseusCore.addLibraryVersionToPerseusDebug(libName, libVersion);
16
16
 
17
17
  // this is a @generated file
@@ -2734,8 +2734,8 @@ class Expr {
2734
2734
  for (var _len = arguments.length, passed = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
2735
2735
  passed[_key - 1] = arguments[_key];
2736
2736
  }
2737
- var args = ___default["default"].map(this.args(), function (arg) {
2738
- return ___default["default"].isString(arg) || ___default["default"].isNumber(arg) ? arg : arg[method].apply(arg, passed);
2737
+ var args = this.args().map(function (arg) {
2738
+ return ___default["default"].isString(arg) || ___default["default"].isNumber(arg) ? arg : arg?.[method].apply(arg, passed);
2739
2739
  });
2740
2740
  return this.construct(args);
2741
2741
  }
@@ -2803,8 +2803,8 @@ class Expr {
2803
2803
 
2804
2804
  // returns a string representing current node structure
2805
2805
  repr() {
2806
- return this.name() + "(" + ___default["default"].map(this.args(), function (arg) {
2807
- return ___default["default"].isString(arg) || ___default["default"].isNumber(arg) ? arg : arg.repr();
2806
+ return this.name() + "(" + this.args().map(function (arg) {
2807
+ return ___default["default"].isString(arg) || ___default["default"].isNumber(arg) ? arg : arg?.repr();
2808
2808
  }).join(",") + ")";
2809
2809
  }
2810
2810
 
@@ -5898,9 +5898,13 @@ var derivedUnits = {
5898
5898
  const Zero = NumZero;
5899
5899
  const One = NumOne;
5900
5900
 
5901
- // Assumes that both expressions have already been parsed
5902
- // TODO(alex): be able to pass a random() function to compare()
5903
- const compare = function (expr1, expr2, options) {
5901
+ /**
5902
+ * Compares two expressions for equality.
5903
+ *
5904
+ * Assumes that both expressions have already been parsed.
5905
+ */ // TODO(alex): be able to pass a random() function to compare()
5906
+ const compare = function (expr1, expr2) {
5907
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
5904
5908
  const defaults = {
5905
5909
  form: false,
5906
5910
  simplify: false
@@ -5911,7 +5915,7 @@ const compare = function (expr1, expr2, options) {
5911
5915
  * like slope
5912
5916
  * - Allow student to choose their own variable names
5913
5917
  */
5914
- options = {
5918
+ const optionsWithDefaults = {
5915
5919
  ...defaults,
5916
5920
  ...options
5917
5921
  };
@@ -5944,7 +5948,7 @@ const compare = function (expr1, expr2, options) {
5944
5948
  }
5945
5949
 
5946
5950
  // Syntactic check
5947
- if (options.form && !expr1.sameForm(expr2)) {
5951
+ if (optionsWithDefaults.form && !expr1.sameForm(expr2)) {
5948
5952
  return {
5949
5953
  equal: false,
5950
5954
  message: "Your answer is not in the correct form."
@@ -5952,7 +5956,7 @@ const compare = function (expr1, expr2, options) {
5952
5956
  }
5953
5957
 
5954
5958
  // Syntactic check
5955
- if (options.simplify && !expr1.isSimplified()) {
5959
+ if (optionsWithDefaults.simplify && !expr1.isSimplified()) {
5956
5960
  return {
5957
5961
  equal: false,
5958
5962
  message: "Your answer is not fully expanded and simplified."