@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.
- package/dist/compare.d.ts +6 -1
- package/dist/es/index.js +14 -11
- package/dist/es/index.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +15 -11
- package/dist/index.js.map +1 -1
- package/dist/nodes.d.ts +5 -5
- 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.0";
|
|
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
|
|
|
@@ -5875,9 +5875,12 @@ var derivedUnits = {
|
|
|
5875
5875
|
const Zero = NumZero;
|
|
5876
5876
|
const One = NumOne;
|
|
5877
5877
|
|
|
5878
|
-
|
|
5879
|
-
|
|
5880
|
-
|
|
5878
|
+
/**
|
|
5879
|
+
* Compares two expressions for equality.
|
|
5880
|
+
*
|
|
5881
|
+
* Assumes that both expressions have already been parsed.
|
|
5882
|
+
*/ // TODO(alex): be able to pass a random() function to compare()
|
|
5883
|
+
const compare = function compare(expr1, expr2, options = {}) {
|
|
5881
5884
|
const defaults = {
|
|
5882
5885
|
form: false,
|
|
5883
5886
|
simplify: false
|
|
@@ -5888,7 +5891,7 @@ const compare = function compare(expr1, expr2, options) {
|
|
|
5888
5891
|
* like slope
|
|
5889
5892
|
* - Allow student to choose their own variable names
|
|
5890
5893
|
*/
|
|
5891
|
-
|
|
5894
|
+
const optionsWithDefaults = _extends({}, defaults, options);
|
|
5892
5895
|
|
|
5893
5896
|
// TODO(CP-1614): Figure out how to make these messages translatable
|
|
5894
5897
|
|
|
@@ -5918,7 +5921,7 @@ const compare = function compare(expr1, expr2, options) {
|
|
|
5918
5921
|
}
|
|
5919
5922
|
|
|
5920
5923
|
// Syntactic check
|
|
5921
|
-
if (
|
|
5924
|
+
if (optionsWithDefaults.form && !expr1.sameForm(expr2)) {
|
|
5922
5925
|
return {
|
|
5923
5926
|
equal: false,
|
|
5924
5927
|
message: "Your answer is not in the correct form."
|
|
@@ -5926,7 +5929,7 @@ const compare = function compare(expr1, expr2, options) {
|
|
|
5926
5929
|
}
|
|
5927
5930
|
|
|
5928
5931
|
// Syntactic check
|
|
5929
|
-
if (
|
|
5932
|
+
if (optionsWithDefaults.simplify && !expr1.isSimplified()) {
|
|
5930
5933
|
return {
|
|
5931
5934
|
equal: false,
|
|
5932
5935
|
message: "Your answer is not fully expanded and simplified."
|