mirror of
https://github.com/PaddiM8/kalker.git
synced 2025-02-01 17:39:13 +01:00
kalk v2.0.0
This commit is contained in:
parent
04644dc54f
commit
e40428016f
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -127,7 +127,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "kalk"
|
name = "kalk"
|
||||||
version = "1.4.9"
|
version = "2.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"regex",
|
"regex",
|
||||||
@ -139,7 +139,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "kalk_cli"
|
name = "kalk_cli"
|
||||||
version = "0.4.1"
|
version = "0.5.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ansi_term",
|
"ansi_term",
|
||||||
"kalk",
|
"kalk",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "kalk"
|
name = "kalk"
|
||||||
version = "1.4.9"
|
version = "2.0.0"
|
||||||
authors = ["PaddiM8"]
|
authors = ["PaddiM8"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
@ -54,6 +54,11 @@ impl KalkNum {
|
|||||||
self.to_string()
|
self.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen(js_name = toPrettyString)]
|
||||||
|
pub fn to_string_pretty_js(&self) -> String {
|
||||||
|
self.to_string_pretty()
|
||||||
|
}
|
||||||
|
|
||||||
#[wasm_bindgen(js_name = toStringBig)]
|
#[wasm_bindgen(js_name = toStringBig)]
|
||||||
pub fn to_string_big_js(&self) -> String {
|
pub fn to_string_big_js(&self) -> String {
|
||||||
self.to_string_big()
|
self.to_string_big()
|
||||||
|
1
kalk/wasm-build.sh
Normal file → Executable file
1
kalk/wasm-build.sh
Normal file → Executable file
@ -1 +1,2 @@
|
|||||||
|
#!/bin/sh
|
||||||
wasm-pack build --scope paddim8 -- --no-default-features
|
wasm-pack build --scope paddim8 -- --no-default-features
|
||||||
|
@ -9,7 +9,7 @@ license = "MIT"
|
|||||||
name = "kalk_cli"
|
name = "kalk_cli"
|
||||||
readme = "../README.md"
|
readme = "../README.md"
|
||||||
repository = "https://github.com/PaddiM8/kalk"
|
repository = "https://github.com/PaddiM8/kalk"
|
||||||
version = "0.4.1"
|
version = "0.5.0"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "kalk"
|
name = "kalk"
|
||||||
@ -17,7 +17,7 @@ path = "src/main.rs"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ansi_term = "0.12.1"
|
ansi_term = "0.12.1"
|
||||||
kalk = { path = "../kalk", version = "^1.4.9" }
|
kalk = { path = "../kalk", version = "^2.0.0" }
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
regex = "1"
|
regex = "1"
|
||||||
rustyline = "7.1.0"
|
rustyline = "7.1.0"
|
||||||
|
11272
kalk_web/package-lock.json
generated
11272
kalk_web/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@paddim8/kalk-component",
|
"name": "@paddim8/kalk-component",
|
||||||
"version": "1.0.17",
|
"version": "1.1.0",
|
||||||
"description": "A Svelte component for kalk, a calculator that supports user-defined functions and variables.",
|
"description": "A Svelte component for kalk, a calculator that supports user-defined functions and variables.",
|
||||||
"svelte": "src/main.ts",
|
"svelte": "src/main.ts",
|
||||||
"main": "public/build/bundle.js",
|
"main": "public/build/bundle.js",
|
||||||
@ -55,7 +55,7 @@
|
|||||||
"webpack-dev-server": "^3.11.0"
|
"webpack-dev-server": "^3.11.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@paddim8/kalk": "^1.4.8",
|
"@paddim8/kalk": "^2.0.0",
|
||||||
"shadow-selection-polyfill": "^1.1.0"
|
"shadow-selection-polyfill": "^1.1.0"
|
||||||
},
|
},
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
|
@ -55,21 +55,14 @@
|
|||||||
function calculate(
|
function calculate(
|
||||||
kalk: Kalk,
|
kalk: Kalk,
|
||||||
input: string
|
input: string
|
||||||
): [result: string, estimate: string, success: boolean] {
|
): [result: string, success: boolean] {
|
||||||
try {
|
try {
|
||||||
if (!kalkContext) kalkContext = new kalk.Context();
|
if (!kalkContext) kalkContext = new kalk.Context();
|
||||||
const result = kalkContext.evaluate(input);
|
const result = kalkContext.evaluate(input);
|
||||||
const estimate = result?.estimate() ?? null;
|
|
||||||
if (result && result.getValue() != 0) {
|
|
||||||
const sciNot = result.toScientificNotation();
|
|
||||||
if (sciNot.exponent > 7 || sciNot.exponent < -6) {
|
|
||||||
return [sciNot.toString(), estimate, true];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return [result?.toString(), estimate, true];
|
return [result?.toPrettyString(), true];
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return [err, null, false];
|
return [err, false];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,16 +78,13 @@
|
|||||||
href="https://kalk.netlify.app/#usage"
|
href="https://kalk.netlify.app/#usage"
|
||||||
target="blank">Link to usage guide</a>`;
|
target="blank">Link to usage guide</a>`;
|
||||||
} else {
|
} else {
|
||||||
const [result, estimate, success] = calculate(
|
const [result, success] = calculate(
|
||||||
kalk,
|
kalk,
|
||||||
input.replace(/\s+/g, "") // Temporary fix, since it for some reason complains about spaces on chrome
|
input.replace(/\s+/g, "") // Temporary fix, since it for some reason complains about spaces on chrome
|
||||||
);
|
);
|
||||||
|
|
||||||
const resultWithEstimate = estimate
|
|
||||||
? result + " ≈ " + estimate
|
|
||||||
: result;
|
|
||||||
output = success
|
output = success
|
||||||
? highlight(resultWithEstimate)[0]
|
? highlight(result)[0]
|
||||||
: `<span style="color: ${errorcolor}">${result}</span>`;
|
: `<span style="color: ${errorcolor}">${result}</span>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user