geos-wasm provides a high-performance WebAssembly (WASM) build of GEOS, a robust C/C++ port of the Java Topology Suite (JTS), enabling advanced planar geometry operations directly within JavaScript environments. Currently at version 3.1.1, this library allows developers to leverage a battle-tested geospatial engine without relying on native system dependencies, making it suitable for both browser-based applications and server-side contexts like Node.js, Bun, or Deno. Built using Emscripten, geos-wasm translates GEOS's extensive C/C++ core into an efficient WebAssembly module. Its key differentiator is bringing the full power and precision of GEOS's algorithms—such as buffering, intersection, union, and area calculation—to JavaScript with a minimal setup, abstracting away the complexities of the underlying C/C++ memory management through its WASM interface. While no fixed release cadence is stated, updates typically align with upstream GEOS advancements and community-driven requirements, ensuring access to the latest topological functionalities.
npm install geos-wasmVerified import paths — ran on the pinned version, not inferred.
Demonstrates initializing the GEOS WASM module, creating a WKT reader, parsing a polygon, calculating its area, and performing crucial manual memory management by freeing allocated resources.
Always ensure that every allocated pointer and created GEOS object (e.g., geometries, readers) is explicitly freed or destroyed once it's no longer needed. Refer to the `quickstart` example for a demonstration of correct cleanup.
Carefully follow the API documentation for each GEOS function regarding pointer usage and data types. Utilize `geos.Module.stringToUTF8()`, `geos.Module.getValue()`, `geos.Module._malloc()`, and `geos.Module._free()` as demonstrated in examples.
Always `await` the `initGeosJs()` call, e.g., `const geos = await initGeosJs();` within an `async` function, ensuring the GEOS object is ready before use.
Ensure `const geos = await initGeosJs();` is called and successfully resolves within an `async` context before attempting to access any `geos` methods.
Thoroughly review your code to ensure all GEOS objects are destroyed (`geos.GEOSGeom_destroy()`, `geos.GEOSWKTReader_destroy()`) and all manually allocated pointers are freed (`geos.Module._free()`, `geos.GEOSFree()`) once they are no longer needed.
Configure your Node.js project for ESM by adding `"type": "module"` to your `package.json`, or rename your file to `.mjs`. If you must use CommonJS, consider dynamic `import()`: `const { default: initGeosJs } = await import('geos-wasm');`No dependency data recorded yet.