Skip to content

Commit 7ae91f6

Browse files
committed
feat(docs): add cli, docs and fix issues
1 parent 47eab47 commit 7ae91f6

File tree

8 files changed

+2046
-163
lines changed

8 files changed

+2046
-163
lines changed

cli/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env node
2+
3+
import evalNumExpr from "../src/index";
4+
5+
const [, , ...args] = process.argv;
6+
7+
if (args.length) {
8+
const str = args.join("");
9+
const value = evalNumExpr(str);
10+
process.stdout.write(`${str} = ${value}\n`);
11+
} else {
12+
process.stderr.write("Error: Please provide an expression to evaluate");
13+
}

docs/app.svelte

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<script>
2+
import evalNumExpr from "../src/index.ts"
3+
$: expr = ""
4+
$: value = expr ? (function (expr) { try{ return `${evalNumExpr(expr)}` } catch(e) { return e.message }})(expr) : ''
5+
</script>
6+
<style>
7+
.outline-none { outline: none !important;}
8+
.block { display: block; }
9+
.flex { display: flex; }
10+
.flex-1 { flex: 1; }
11+
.w-full { width: 100%; }
12+
.p-4 { padding: 1rem;}
13+
.pr-4 { padding-right: 1rem; }
14+
.text-lg { font-size: 1.25rem; }
15+
.max-w-sm { max-width: 756px; }
16+
.mx-auto { margin-left: auto; margin-right: auto;}
17+
.rounded-lg { border-radius: 1rem; }
18+
.border { border: 2px solid black; }
19+
</style>
20+
21+
<div class="max-w-sm mx-auto">
22+
<div class="p-4">
23+
<h1>Evaluate Numeric Expressions (Playground)</h1>
24+
<a href="https://craftsys.github.io/eval-num-expr">GitHub</a>
25+
</div>
26+
<div class="p-4">
27+
<div class="flex">
28+
<div class="flex-1 pr-4">
29+
<label for="string">Expressions</label>
30+
<input
31+
id="string"
32+
type="text"
33+
class="block w-full p-4 text-lg outline-none rounded-lg border"
34+
bind:value={expr}
35+
placeholder="1 + 10 x 1000 / 20"
36+
/>
37+
</div>
38+
</div>
39+
<h2>Value: {value}</h2>
40+
</div>
41+
</div>

docs/main.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import App from "./app.svelte";
2+
3+
const app = new App({
4+
target: document.getElementById("root"),
5+
});

0 commit comments

Comments
 (0)