kalk v2.0.0

This commit is contained in:
bakk 2021-05-23 18:43:22 +02:00
parent 04644dc54f
commit e40428016f
8 changed files with 11276 additions and 36 deletions

4
Cargo.lock generated
View File

@ -127,7 +127,7 @@ dependencies = [
[[package]]
name = "kalk"
version = "1.4.9"
version = "2.0.0"
dependencies = [
"lazy_static",
"regex",
@ -139,7 +139,7 @@ dependencies = [
[[package]]
name = "kalk_cli"
version = "0.4.1"
version = "0.5.0"
dependencies = [
"ansi_term",
"kalk",

View File

@ -1,6 +1,6 @@
[package]
name = "kalk"
version = "1.4.9"
version = "2.0.0"
authors = ["PaddiM8"]
edition = "2018"
readme = "README.md"

View File

@ -54,6 +54,11 @@ impl KalkNum {
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)]
pub fn to_string_big_js(&self) -> String {
self.to_string_big()

1
kalk/wasm-build.sh Normal file → Executable file
View File

@ -1 +1,2 @@
#!/bin/sh
wasm-pack build --scope paddim8 -- --no-default-features

View File

@ -9,7 +9,7 @@ license = "MIT"
name = "kalk_cli"
readme = "../README.md"
repository = "https://github.com/PaddiM8/kalk"
version = "0.4.1"
version = "0.5.0"
[[bin]]
name = "kalk"
@ -17,7 +17,7 @@ path = "src/main.rs"
[dependencies]
ansi_term = "0.12.1"
kalk = { path = "../kalk", version = "^1.4.9" }
kalk = { path = "../kalk", version = "^2.0.0" }
lazy_static = "1.4.0"
regex = "1"
rustyline = "7.1.0"

11272
kalk_web/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"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.",
"svelte": "src/main.ts",
"main": "public/build/bundle.js",
@ -55,7 +55,7 @@
"webpack-dev-server": "^3.11.0"
},
"dependencies": {
"@paddim8/kalk": "^1.4.8",
"@paddim8/kalk": "^2.0.0",
"shadow-selection-polyfill": "^1.1.0"
},
"browserslist": [

View File

@ -55,21 +55,14 @@
function calculate(
kalk: Kalk,
input: string
): [result: string, estimate: string, success: boolean] {
): [result: string, success: boolean] {
try {
if (!kalkContext) kalkContext = new kalk.Context();
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) {
return [err, null, false];
return [err, false];
}
}
@ -85,16 +78,13 @@
href="https://kalk.netlify.app/#usage"
target="blank">Link to usage guide</a>`;
} else {
const [result, estimate, success] = calculate(
const [result, success] = calculate(
kalk,
input.replace(/\s+/g, "") // Temporary fix, since it for some reason complains about spaces on chrome
);
const resultWithEstimate = estimate
? result + " ≈ " + estimate
: result;
output = success
? highlight(resultWithEstimate)[0]
? highlight(result)[0]
: `<span style="color: ${errorcolor}">${result}</span>`;
}