mirror of
https://github.com/rzmk/czv.git
synced 2025-12-26 19:16:59 +00:00
refactor: use options object for WASM function args, improve docs
- Add relevant links to all READMEs and source code - Resolve clippy lints czv: - Add more docs for top-level items - Add suggestion to use builder methods instead of functions - Disable slice and slice tests until operation is complete czv-wasm: - Use tsify_next for allowing objects as parameters - Add nodejs example and instructions
This commit is contained in:
parent
ce260e9491
commit
e84c5bec8b
20 changed files with 564 additions and 168 deletions
1
czv-wasm/examples/basic-demo/README.md
Normal file
1
czv-wasm/examples/basic-demo/README.md
Normal file
|
|
@ -0,0 +1 @@
|
|||
If you want to modify the TypeScript code then after you save your modifications you must run `tsc script.ts --module es2022 --target es2022` to generate a compatible `script.js` file.
|
||||
|
|
@ -40,30 +40,7 @@
|
|||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<script type="module">
|
||||
const input = document.getElementById("upload")
|
||||
const progress = document.getElementById("progress")
|
||||
|
||||
import init, * as czv from "../../pkg/czv.js";
|
||||
// Must run `await init()` or `initSync()` first for web use
|
||||
await init();
|
||||
|
||||
const fileReader = new FileReader()
|
||||
|
||||
fileReader.onloadstart = () => {
|
||||
progress.style.display = "block";
|
||||
}
|
||||
|
||||
fileReader.onloadend = () => {
|
||||
document.getElementById("column-count").innerText = czv.columnCount(fileReader.result)
|
||||
document.getElementById("row-count").innerText = czv.rowCount(fileReader.result)
|
||||
progress.style.display = "none";
|
||||
}
|
||||
|
||||
input.addEventListener("change", () => {
|
||||
fileReader.readAsText(input.files[0])
|
||||
})
|
||||
</script>
|
||||
<script src="script.js" type="module"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
27
czv-wasm/examples/basic-demo/script.js
Normal file
27
czv-wasm/examples/basic-demo/script.js
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
const progress = document.getElementById("progress");
|
||||
import init, * as czv from "../../pkg/czv.js";
|
||||
// Must run `await init()` or `initSync()` first for web use
|
||||
await init();
|
||||
const fileReader = new FileReader();
|
||||
fileReader.onloadstart = () => {
|
||||
if (progress)
|
||||
progress.style.display = "block";
|
||||
};
|
||||
fileReader.onloadend = () => {
|
||||
const rowCountElement = document.getElementById("row-count");
|
||||
const columnCountElement = document.getElementById("column-count");
|
||||
if (rowCountElement)
|
||||
rowCountElement.innerText = String(czv.rowCount({
|
||||
file_data: fileReader.result,
|
||||
}));
|
||||
if (columnCountElement)
|
||||
columnCountElement.innerText = String(czv.columnCount({ file_data: fileReader.result }));
|
||||
if (progress)
|
||||
progress.style.display = "none";
|
||||
};
|
||||
const input = document.getElementById("upload");
|
||||
if (input)
|
||||
input.addEventListener("change", () => {
|
||||
// @ts-ignore
|
||||
fileReader.readAsText(input.files[0]);
|
||||
});
|
||||
34
czv-wasm/examples/basic-demo/script.ts
Normal file
34
czv-wasm/examples/basic-demo/script.ts
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
const progress = document.getElementById("progress");
|
||||
|
||||
import init, * as czv from "../../pkg/czv.js";
|
||||
// Must run `await init()` or `initSync()` first for web use
|
||||
await init();
|
||||
|
||||
const fileReader = new FileReader();
|
||||
|
||||
fileReader.onloadstart = () => {
|
||||
if (progress) progress.style.display = "block";
|
||||
};
|
||||
|
||||
fileReader.onloadend = () => {
|
||||
const rowCountElement = document.getElementById("row-count");
|
||||
const columnCountElement = document.getElementById("column-count");
|
||||
if (rowCountElement)
|
||||
rowCountElement.innerText = String(
|
||||
czv.rowCount({
|
||||
file_data: fileReader.result as string,
|
||||
})
|
||||
);
|
||||
if (columnCountElement)
|
||||
columnCountElement.innerText = String(
|
||||
czv.columnCount({ file_data: fileReader.result as string })
|
||||
);
|
||||
if (progress) progress.style.display = "none";
|
||||
};
|
||||
|
||||
const input = document.getElementById("upload");
|
||||
if (input)
|
||||
input.addEventListener("change", () => {
|
||||
// @ts-ignore
|
||||
fileReader.readAsText(input.files[0]);
|
||||
});
|
||||
4
czv-wasm/examples/node-demo/README.md
Normal file
4
czv-wasm/examples/node-demo/README.md
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
To run this example:
|
||||
|
||||
1. Build the `nodejs` compatible bundle in the `czv-wasm` directory with `wasm-pack build -t nodejs --release --out-name czv-ts`.
|
||||
2. Run `bunx tsx sample.ts` (or `npx`, `pnpx`, etc.).
|
||||
12
czv-wasm/examples/node-demo/sample.ts
Normal file
12
czv-wasm/examples/node-demo/sample.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import czv from "../../pkg/czv-ts";
|
||||
|
||||
const options: czv.RowCountOptions = {
|
||||
file_data: `fruit,price,
|
||||
apple,2.50
|
||||
banana,3.00
|
||||
strawberry,1.50`,
|
||||
};
|
||||
|
||||
const output = czv.rowCount(options);
|
||||
|
||||
console.log(output); // 4
|
||||
Loading…
Add table
Add a link
Reference in a new issue