Registry / data / quadbin

quadbin

JSON →
library0.2.2jsnpmunverified

The `quadbin` library (version 0.4.2) provides essential utility functions for working with the Quadbin spatial index, a hierarchical geospatial indexing system developed by CARTO. Quadbins represent map cells using 64-bit integers, offering a distinct approach compared to variable-length indexing systems like Quadkey. This TypeScript-first library emphasizes performance and type safety, making it suitable for geospatial data processing in Node.js environments (requiring Node.js >=18). It's primarily used in WebGL and visualization contexts for efficient spatial queries and data aggregation. The library's main differentiator is its use of JavaScript's `BigInt` type for quadbin indices, which necessitates explicit conversion functions like `bigIntToHex` and `hexToBigInt` when serializing or deserializing data (e.g., for JSON). While specific release cadences aren't strictly defined, the package receives active maintenance, with recent dependency updates reflecting ongoing support.

npm install quadbin
INSTALL
IMPORT
SIG · QUADBIN
Q
quadbin
datajavascriptv0.2.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

tileToCell
import { tileToCell } from 'quadbin';
const tileToCell = require('quadbin').tileToCell;
The library is primarily designed for ESM imports. All Quadbin indices are BigInts.
cellToTile
import { cellToTile } from 'quadbin';
import cellToTile from 'quadbin/cellToTile';
All functions are named exports from the main package entry point.
bigIntToHex
import { bigIntToHex, hexToBigInt } from 'quadbin';
import { BigIntToHex } from 'quadbin';
Use `bigIntToHex` and `hexToBigInt` for JSON serialization as `BigInt` cannot be directly serialized. Note the camelCase naming.

Demonstrates converting an XYZ tile to a Quadbin BigInt, handling JSON serialization via hex strings, and converting back.

import { tileToCell, cellToTile, bigIntToHex, hexToBigInt } from 'quadbin'; // Example: Convert an XYZ tile to a Quadbin BigInt const zoom = 10; const x = 325; const y = 373; const tile = { x, y, z: zoom }; const quadbinBigInt = tileToCell(tile); console.log(`Tile {z: ${zoom}, x: ${x}, y: ${y}} converts to Quadbin BigInt: ${quadbinBigInt}n`); // Quadbin BigInts cannot be directly serialized to JSON. Convert to hex string. const quadbinHexString = bigIntToHex(quadbinBigInt); console.log(`Quadbin BigInt as hex string for JSON: ${quadbinHexString}n`); // To use the hex string back in the library, convert it back to BigInt. const restoredQuadbinBigInt = hexToBigInt(quadbinHexString); console.log(`Restored Quadbin BigInt from hex string: ${restoredQuadbinBigInt}n`); // Convert the Quadbin BigInt back to an XYZ tile const convertedTile = cellToTile(restoredQuadbinBigInt); console.log(`Quadbin BigInt ${restoredQuadbinBigInt} converts back to Tile: {z: ${convertedTile.z}, x: ${convertedTile.x}, y: ${convertedTile.y}}`); // Verify the conversion if (convertedTile.z === zoom && convertedTile.x === x && convertedTile.y === y) { console.log('\nConversion successful and consistent!'); } else { console.error('\nConversion resulted in a different tile!'); }
Debug
Known issues
gotchaQuadbin indices are represented as JavaScript `BigInt` types. Standard JSON serialization does not support `BigInt`s, leading to `TypeError: Do not know how to serialize a BigInt`.
fix
Use `bigIntToHex(quadbin: bigint): string` to convert BigInts to hexadecimal strings before JSON serialization, and `hexToBigInt(hex: string): bigint` to convert them back for library use.
affects: >=0.1.0
gotchaThis library explicitly requires Node.js version 18 or newer due to its modern JavaScript features and dependencies.
fix
Ensure your Node.js environment is updated to version 18 or higher. Use `node -v` to check your current version.
affects: <=0.4.2
Errors
Common errors & fixes
TypeError: Do not know how to serialize a BigInt
Attempting to serialize a Quadbin BigInt index directly to JSON without conversion.
fix
Before `JSON.stringify()`, convert BigInt indices to hexadecimal strings using `bigIntToHex(quadbinBigInt)`. When deserializing, use `hexToBigInt(hexString)`.
quadbin_1.tileToCell is not a function (or similar for other functions)
Incorrect CommonJS `require()` syntax or attempting to use `quadbin` as a default export.
fix
This is an ESM-first library. Use named imports: `import { tileToCell } from 'quadbin';`. If using CommonJS, ensure your build setup transpiles correctly or consider `const { tileToCell } = require('quadbin');` as a last resort, though full ESM is recommended.
Upgrade
Version history
0.2.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
quadbin — npm install quadbin · libregistry