@khanacademy/kas 0.3.16 → 0.4.1
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/compare.d.ts +6 -1
- package/dist/es/index.js +27 -14
- package/dist/es/index.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +28 -14
- package/dist/index.js.map +1 -1
- package/dist/nodes.d.ts +6 -6
- package/package.json +2 -2
package/dist/compare.d.ts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
import type { CompareOptions, CompareResult, Expression } from "./types";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Compares two expressions for equality.
|
|
4
|
+
*
|
|
5
|
+
* Assumes that both expressions have already been parsed.
|
|
6
|
+
*/
|
|
7
|
+
export declare const compare: (expr1: Expression, expr2: Expression, options?: Partial<CompareOptions>) => CompareResult;
|
package/dist/es/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import _ from 'underscore';
|
|
|
3
3
|
|
|
4
4
|
// This file is processed by a Rollup plugin (replace) to inject the production
|
|
5
5
|
const libName = "@khanacademy/kas";
|
|
6
|
-
const libVersion = "0.
|
|
6
|
+
const libVersion = "0.4.1";
|
|
7
7
|
addLibraryVersionToPerseusDebug(libName, libVersion);
|
|
8
8
|
|
|
9
9
|
function _extends() {
|
|
@@ -2733,8 +2733,8 @@ class Expr {
|
|
|
2733
2733
|
// NOTE(kevinb): This method is highly dynamic. It's possible that it
|
|
2734
2734
|
// could be made more type-safe using overload signatures.
|
|
2735
2735
|
recurse(method, ...passed) {
|
|
2736
|
-
var args =
|
|
2737
|
-
return _.isString(arg) || _.isNumber(arg) ? arg : arg[method].apply(arg, passed);
|
|
2736
|
+
var args = this.args().map(function (arg) {
|
|
2737
|
+
return _.isString(arg) || _.isNumber(arg) ? arg : arg == null ? void 0 : arg[method].apply(arg, passed);
|
|
2738
2738
|
});
|
|
2739
2739
|
return this.construct(args);
|
|
2740
2740
|
}
|
|
@@ -2802,8 +2802,8 @@ class Expr {
|
|
|
2802
2802
|
|
|
2803
2803
|
// returns a string representing current node structure
|
|
2804
2804
|
repr() {
|
|
2805
|
-
return this.name() + "(" +
|
|
2806
|
-
return _.isString(arg) || _.isNumber(arg) ? arg : arg.repr();
|
|
2805
|
+
return this.name() + "(" + this.args().map(function (arg) {
|
|
2806
|
+
return _.isString(arg) || _.isNumber(arg) ? arg : arg == null ? void 0 : arg.repr();
|
|
2807
2807
|
}).join(",") + ")";
|
|
2808
2808
|
}
|
|
2809
2809
|
|
|
@@ -2877,6 +2877,7 @@ class Expr {
|
|
|
2877
2877
|
|
|
2878
2878
|
// return the child nodes of this node
|
|
2879
2879
|
exprArgs() {
|
|
2880
|
+
// @ts-expect-error: Type 'string | number | Expr | undefined' is not assignable to type 'string | Expr'.
|
|
2880
2881
|
return this.args().filter(isExpr);
|
|
2881
2882
|
}
|
|
2882
2883
|
|
|
@@ -3303,7 +3304,9 @@ class Add extends Seq {
|
|
|
3303
3304
|
return Mul.createOrAppend(left, right).flatten();
|
|
3304
3305
|
}
|
|
3305
3306
|
reduce(options) {
|
|
3306
|
-
return _.reduce(this.terms,
|
|
3307
|
+
return _.reduce(this.terms,
|
|
3308
|
+
// @ts-expect-error: Type 'Expr' is not assignable to type 'Num'.
|
|
3309
|
+
(memo, term) => {
|
|
3307
3310
|
return memo.add(term, options);
|
|
3308
3311
|
}, this.identity);
|
|
3309
3312
|
}
|
|
@@ -3684,7 +3687,9 @@ class Mul extends Seq {
|
|
|
3684
3687
|
}
|
|
3685
3688
|
}
|
|
3686
3689
|
reduce(options) {
|
|
3687
|
-
return _.reduce(this.terms,
|
|
3690
|
+
return _.reduce(this.terms,
|
|
3691
|
+
// @ts-expect-error: Type 'Expr' is not assignable to type 'Num'.
|
|
3692
|
+
(memo, term) => {
|
|
3688
3693
|
return memo.mul(term, options);
|
|
3689
3694
|
}, this.identity);
|
|
3690
3695
|
}
|
|
@@ -3885,9 +3890,14 @@ class Mul extends Seq {
|
|
|
3885
3890
|
var posOrNeg = function posOrNeg(num) {
|
|
3886
3891
|
return pos(num) || neg(num);
|
|
3887
3892
|
};
|
|
3893
|
+
|
|
3894
|
+
// @ts-expect-error: Type 'Expr' is not assignable to type 'Num'.
|
|
3888
3895
|
const posNum = numbers.find(pos);
|
|
3896
|
+
// @ts-expect-error: Type 'Expr' is not assignable to type 'Num'.
|
|
3889
3897
|
const negNum = numbers.find(neg);
|
|
3890
|
-
if (numbers.length > 1 && negNum && posNum &&
|
|
3898
|
+
if (numbers.length > 1 && negNum && posNum &&
|
|
3899
|
+
// @ts-expect-error: Type 'Expr' is not assignable to type 'Num'.
|
|
3900
|
+
_.every(numbers, posOrNeg)) {
|
|
3891
3901
|
var firstNeg = _.indexOf(expr.terms, negNum);
|
|
3892
3902
|
var firstNum = _.indexOf(expr.terms, posNum);
|
|
3893
3903
|
|
|
@@ -5875,9 +5885,12 @@ var derivedUnits = {
|
|
|
5875
5885
|
const Zero = NumZero;
|
|
5876
5886
|
const One = NumOne;
|
|
5877
5887
|
|
|
5878
|
-
|
|
5879
|
-
|
|
5880
|
-
|
|
5888
|
+
/**
|
|
5889
|
+
* Compares two expressions for equality.
|
|
5890
|
+
*
|
|
5891
|
+
* Assumes that both expressions have already been parsed.
|
|
5892
|
+
*/ // TODO(alex): be able to pass a random() function to compare()
|
|
5893
|
+
const compare = function compare(expr1, expr2, options = {}) {
|
|
5881
5894
|
const defaults = {
|
|
5882
5895
|
form: false,
|
|
5883
5896
|
simplify: false
|
|
@@ -5888,7 +5901,7 @@ const compare = function compare(expr1, expr2, options) {
|
|
|
5888
5901
|
* like slope
|
|
5889
5902
|
* - Allow student to choose their own variable names
|
|
5890
5903
|
*/
|
|
5891
|
-
|
|
5904
|
+
const optionsWithDefaults = _extends({}, defaults, options);
|
|
5892
5905
|
|
|
5893
5906
|
// TODO(CP-1614): Figure out how to make these messages translatable
|
|
5894
5907
|
|
|
@@ -5918,7 +5931,7 @@ const compare = function compare(expr1, expr2, options) {
|
|
|
5918
5931
|
}
|
|
5919
5932
|
|
|
5920
5933
|
// Syntactic check
|
|
5921
|
-
if (
|
|
5934
|
+
if (optionsWithDefaults.form && !expr1.sameForm(expr2)) {
|
|
5922
5935
|
return {
|
|
5923
5936
|
equal: false,
|
|
5924
5937
|
message: "Your answer is not in the correct form."
|
|
@@ -5926,7 +5939,7 @@ const compare = function compare(expr1, expr2, options) {
|
|
|
5926
5939
|
}
|
|
5927
5940
|
|
|
5928
5941
|
// Syntactic check
|
|
5929
|
-
if (
|
|
5942
|
+
if (optionsWithDefaults.simplify && !expr1.isSimplified()) {
|
|
5930
5943
|
return {
|
|
5931
5944
|
equal: false,
|
|
5932
5945
|
message: "Your answer is not fully expanded and simplified."
|