@khanacademy/kas 0.2.3
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/CHANGELOG.md +7 -0
- package/LICENSE.txt +21 -0
- package/README.md +94 -0
- package/dist/es/index.js +2 -0
- package/dist/es/index.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.flow +2 -0
- package/dist/index.js.map +1 -0
- package/experimenter.html +75 -0
- package/package.json +38 -0
- package/src/__genfiles__/parser.js +840 -0
- package/src/__genfiles__/unitparser.js +679 -0
- package/src/__tests__/checking-form_test.js +76 -0
- package/src/__tests__/comparing_test.js +322 -0
- package/src/__tests__/compilation_test.js +97 -0
- package/src/__tests__/evaluating_test.js +73 -0
- package/src/__tests__/index_test.js +364 -0
- package/src/__tests__/parsing_test.js +480 -0
- package/src/__tests__/rendering_test.js +272 -0
- package/src/__tests__/transforming_test.js +331 -0
- package/src/__tests__/units_test.js +188 -0
- package/src/compare.js +69 -0
- package/src/index.js +2 -0
- package/src/nodes.js +3504 -0
- package/src/parser-generator.js +212 -0
- package/src/unitvalue.jison +161 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>KAS Experimenter</title>
|
|
5
|
+
<!-- Include Underscore -->
|
|
6
|
+
<script src="node_modules/underscore/underscore.js"></script>
|
|
7
|
+
<!-- Include KAS -->
|
|
8
|
+
<script src="src/parser.js"></script>
|
|
9
|
+
<script src="src/nodes.js"></script>
|
|
10
|
+
<script src="src/compare.js"></script>
|
|
11
|
+
<style>
|
|
12
|
+
* {
|
|
13
|
+
font-family: "Courier New"
|
|
14
|
+
}
|
|
15
|
+
body {
|
|
16
|
+
font-size: 28px;
|
|
17
|
+
}
|
|
18
|
+
#input {
|
|
19
|
+
width: 100%;
|
|
20
|
+
font-size: 72px;
|
|
21
|
+
}
|
|
22
|
+
.label {
|
|
23
|
+
display: inline-block;
|
|
24
|
+
margin-right:30px;
|
|
25
|
+
width:400px;
|
|
26
|
+
vertical-align: top;
|
|
27
|
+
}
|
|
28
|
+
.value {
|
|
29
|
+
display: inline-block;
|
|
30
|
+
}
|
|
31
|
+
.code {
|
|
32
|
+
font-size: 12px;
|
|
33
|
+
}
|
|
34
|
+
</style>
|
|
35
|
+
</head>
|
|
36
|
+
<body>
|
|
37
|
+
<input type="text" id="input"></input>
|
|
38
|
+
<div id="output"></div>
|
|
39
|
+
<script>
|
|
40
|
+
window.onload = function() {
|
|
41
|
+
var input = document.getElementById("input");
|
|
42
|
+
var out = document.getElementById("output");
|
|
43
|
+
|
|
44
|
+
if ("oninput" in input) {
|
|
45
|
+
input.addEventListener("input", reprocess, false);
|
|
46
|
+
} else {
|
|
47
|
+
input.attachEvent("onkeyup", reprocess);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function addInfo(el, label, value) {
|
|
51
|
+
el.innerHTML += "<div>"
|
|
52
|
+
+ "<div class='label'>" + label + "</div>"
|
|
53
|
+
+ "<div class='value'>" + value + "</div>"
|
|
54
|
+
+ "</div>";
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function reprocess() {
|
|
58
|
+
out.innerHTML = "";
|
|
59
|
+
var parsed = KAS.parse(input.value, {}).expr;
|
|
60
|
+
if (input.value === "") { return; }
|
|
61
|
+
if (parsed === undefined) { return; }
|
|
62
|
+
addInfo(out, "AST Representation:", parsed.repr());
|
|
63
|
+
addInfo(out, "Printed Representation:", parsed.normalize().print());
|
|
64
|
+
addInfo(out, "TeX Representation:", parsed.tex());
|
|
65
|
+
addInfo(out, "Simplified?", parsed.isSimplified() ? "Yes" : "No");
|
|
66
|
+
addInfo(out, "Simplified", parsed.simplify().normalize().print());
|
|
67
|
+
addInfo(out, "JSON Representation:", "<pre class='code'>"
|
|
68
|
+
+ JSON.stringify(parsed, null, 2)
|
|
69
|
+
+ "</pre>");
|
|
70
|
+
addInfo(out, "Compiled", parsed.compile().toString());
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
</script>
|
|
74
|
+
</body>
|
|
75
|
+
</html>
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"publishConfig": {
|
|
3
|
+
"access": "public"
|
|
4
|
+
},
|
|
5
|
+
"name": "@khanacademy/kas",
|
|
6
|
+
"version": "0.2.3",
|
|
7
|
+
"description": "A lightweight JavaScript CAS for comparing expressions and equations.",
|
|
8
|
+
"module": "dist/es/index.js",
|
|
9
|
+
"main": "dist/index.js",
|
|
10
|
+
"source": "src/index.js",
|
|
11
|
+
"scripts": {
|
|
12
|
+
"gen:parsers": "node src/parser-generator.js",
|
|
13
|
+
"test": "bash -c 'yarn --silent --cwd \"../..\" test ${@:0} $($([[ ${@: -1} = -* ]] || [[ ${@: -1} = bash ]]) && echo $PWD)'"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/Khan/KAS.git"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"parsing",
|
|
21
|
+
"equation",
|
|
22
|
+
"expression",
|
|
23
|
+
"algebra",
|
|
24
|
+
"symbolic"
|
|
25
|
+
],
|
|
26
|
+
"author": "alopatin",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/Khan/KAS/issues"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"jison": "0.4.15",
|
|
33
|
+
"underscore": "1.4.4"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"underscore": "1.4.4"
|
|
37
|
+
}
|
|
38
|
+
}
|