@tgrv/void-math 1.0.5 → 1.0.6

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.
Files changed (2) hide show
  1. package/README.md +72 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # Void Math Plugin (Go)
2
+
3
+ This is a high-performance mathematical computation plugin written in **Go**, compiled to WebAssembly (WASM), and optimized for standard Node.js applications using the **Void** framework.
4
+
5
+ ---
6
+
7
+ ## Prerequisites
8
+ * **Go** (1.24+ recommended)
9
+ * **Node.js** (22.6+)
10
+ * **Void CLI** (available via `npx` or installed globally)
11
+
12
+ ---
13
+
14
+ ## How to Install and Use from Scratch
15
+
16
+ Follow these steps to initialize a new host application, compile the math plugin, link it, and run it.
17
+
18
+ ### Step 1: Initialize Your Node.js Host Application
19
+ If you have an existing or new Node.js/Express project, navigate to its directory and run:
20
+ ```bash
21
+ npx void init
22
+ ```
23
+ This initializes standard Void configurations and automatically installs the `@tgrv/void-runtime` engine in your host application.
24
+
25
+ ### Step 2: Build the Math Plugin
26
+ Navigate to this directory (`plugins/math`) and run the build command:
27
+ ```bash
28
+ npx void build
29
+ ```
30
+ This compiles the Go source code (`main.go`) to WebAssembly and places the final NPM-ready package structure inside the `@void/void-math` subdirectory (as configured in `void.json`).
31
+
32
+ ### Step 3: Link the Plugin to Your Application
33
+ Navigate back to your Node.js application directory and run:
34
+ ```bash
35
+ npx void add <path-to-this-plugin>/@void/void-math
36
+ ```
37
+ *Example (if your app is in `examples/express-void`):*
38
+ ```bash
39
+ npx void add ../../plugins/math/@void/void-math
40
+ ```
41
+ This command automatically:
42
+ 1. Copies/links the build output into your host app's `node_modules`.
43
+ 2. Resolves type declarations for TypeScript so you get auto-complete in your editor.
44
+
45
+ ### Step 4: Import and Run in Your Code
46
+ Now, you can import and call the math plugin functions directly inside your JavaScript/TypeScript files.
47
+
48
+ ```typescript
49
+ import math from '@tgrv/void-math';
50
+
51
+ // 1. Basic addition (supporting multiple signatures)
52
+ const sum1 = math.add({ a: 10, b: 20 });
53
+ const sum2 = math.add({ numbers: [1, 2, 3, 4, 5] });
54
+ console.log(`Sum: ${sum1}, Array Sum: ${sum2}`);
55
+
56
+ // 2. Count primes up to a limit (CPU-intensive nested loop)
57
+ const primes = math.count_primes({ limit: 1000000 });
58
+ console.log(`Primes Count: ${primes}`);
59
+
60
+ // 3. Gravitational N-Body simulation (Floating-point intensive)
61
+ const result = math.nbody({ n: 150, steps: 1000 });
62
+ console.log(`Simulation checksum: ${result}`);
63
+ ```
64
+
65
+ ---
66
+
67
+ ## Exported Functions
68
+ The math plugin registers and exports the following functions:
69
+ * `add(args: { a: number; b: number } | { numbers: number[] }): number` — Performs arithmetic addition.
70
+ * `format_message(args: { template: string; value: number }): string` — Formats strings within WASM.
71
+ * `count_primes(args: { limit: number }): number` — Heavy integer calculation (prime counting).
72
+ * `nbody(args: { n: number; steps: number }): number` — High-performance floating-point physics simulation.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tgrv/void-math",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "types": "types.d.ts",