strictjs-runtime 2.0.0 → 2.0.2

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/index.js +24 -37
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,7 +1,5 @@
1
-
2
-
3
- import { fileURLToPath } from "url";
4
- import {
1
+ // index.js
2
+ import initWASM, {
5
3
  StrictNumber,
6
4
  StrictString,
7
5
  get_memory,
@@ -13,43 +11,34 @@ import {
13
11
  Schema
14
12
  } from "./pkg/strictjs_runtime.js";
15
13
 
16
- // Check if we're in Node.js environment
17
- const isNode = typeof process !== 'undefined' &&
18
- process.versions != null &&
19
- process.versions.node != null;
20
-
21
- let initWASM;
22
14
  let wasmInitialized = false;
23
15
 
24
- // Dynamic import to handle different environments
25
- if (isNode) {
16
+ /**
17
+ * Initialize StrictJS Runtime.
18
+ * Works in both Node.js and Browser.
19
+ */
20
+ export async function initStrict() {
21
+ if (wasmInitialized) return { StrictNumber, StrictString, get_memory, HeapType, StrictArray, StrictForLoop, StrictFunction, StrictObject, Schema };
22
+
26
23
  // Node.js environment
27
- const fs = await import("fs");
28
- const path = await import("path");
29
-
30
- const __filename = fileURLToPath(import.meta.url);
31
- const __dirname = path.dirname(__filename);
32
-
33
- initWASM = (await import("./pkg/strictjs_runtime.js")).initWASM;
34
-
35
- const wasmPath = path.resolve(__dirname, "pkg/strictjs_runtime_bg.wasm");
36
- const wasmBuffer = fs.readFileSync(wasmPath);
37
-
38
- await initWASM(wasmBuffer);
39
- wasmInitialized = true;
40
-
41
- } else {
42
- // Browser environment
43
- initWASM = (await import("./pkg/strictjs_runtime.js")).initWASM;
44
- }
24
+ if (typeof window === "undefined") {
25
+ const fs = await import("fs");
26
+ const path = await import("path");
27
+ const url = await import("url");
45
28
 
46
- export default async function strictInit() {
47
- if (!wasmInitialized && !isNode) {
48
- // Initialize WASM for browser
29
+ const __filename = url.fileURLToPath(import.meta.url);
30
+ const __dirname = path.dirname(__filename);
31
+ const wasmPath = path.resolve(__dirname, "pkg/strictjs_runtime_bg.wasm");
32
+ const wasmBuffer = fs.readFileSync(wasmPath);
33
+
34
+ await initWASM(wasmBuffer);
35
+ } else {
36
+ // Browser environment: fetch automatically
49
37
  await initWASM();
50
- wasmInitialized = true;
51
38
  }
52
39
 
40
+ wasmInitialized = true;
41
+
53
42
  return {
54
43
  StrictNumber,
55
44
  StrictString,
@@ -63,9 +52,8 @@ export default async function strictInit() {
63
52
  };
64
53
  }
65
54
 
55
+ // Re-export types for convenience
66
56
  export {
67
- StrictNumber,
68
- StrictString,
69
57
  get_memory,
70
58
  HeapType,
71
59
  StrictArray,
@@ -74,4 +62,3 @@ export {
74
62
  StrictObject,
75
63
  Schema
76
64
  };
77
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strictjs-runtime",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "A lightweight low-level runtime for StrictJS with WebAssembly support.",
5
5
  "main": "index.js",
6
6
  "module": "index.js",