npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@versatiles/versatiles-rs

v3.2.0

Published

Node.js bindings for VersaTiles - convert, serve, and process map tiles

Readme

@versatiles/versatiles-rs

Node.js bindings for VersaTiles - convert, serve, and process map tiles in various formats.

Features

  • 🚀 Fast & Native - Powered by Rust with zero-copy operations
  • 🔄 Format Conversion - Convert between MBTiles, PMTiles, VersaTiles, TAR, and directories
  • 🗺️ Tile Server - Built-in HTTP tile server with dynamic source management
  • 📊 Metadata Access - Read TileJSON and inspect container details
  • 🌍 Coordinate Utils - Convert between tile and geographic coordinates
  • Async API - Non-blocking operations with Promise-based interface
  • 📦 Dual Format - Supports both ESM and CommonJS

Installation

npm install @versatiles/versatiles-rs
# or
yarn add @versatiles/versatiles-rs

Pre-built binaries are available for:

  • macOS (arm64, x64)
  • Linux (x64, arm64, musl)
  • Windows (x64, arm64)

Quick Start

Convert Tiles

import { convert } from '@versatiles/versatiles-rs';

await convert('input.mbtiles', 'output.versatiles', {
  minZoom: 0,
  maxZoom: 14,
  bbox: [-180, -85, 180, 85],
  compress: 'gzip',
});

Serve Tiles

import { TileServer } from '@versatiles/versatiles-rs';

const server = new TileServer({ port: 8080 });
await server.addTileSourceFromPath('osm', 'tiles.mbtiles');
await server.start();

console.log(`Server running at http://localhost:${server.port}`);

Read Tiles

import { TileSource } from '@versatiles/versatiles-rs';

const source = await TileSource.open('tiles.mbtiles');

// Get a single tile
const tile = await source.getTile(5, 16, 10);
if (tile) {
  console.log('Tile size:', tile.length, 'bytes');
}

// Get metadata
const metadata = source.metadata();
console.log('Format:', metadata.tileFormat);
console.log('Zoom levels:', metadata.minZoom, '-', metadata.maxZoom);

// Get TileJSON
const tileJSON = source.tileJson();
console.log('Bounds:', tileJSON.bounds);

Probe Container

import { TileSource } from '@versatiles/versatiles-rs';

const source = await TileSource.open('tiles.mbtiles');
const sourceType = source.sourceType();
const metadata = source.metadata();

console.log('Type:', sourceType.kind);
console.log('Format:', metadata.tileFormat);
console.log('Compression:', metadata.tileCompression);

Coordinate Conversion

import { TileCoord } from '@versatiles/versatiles-rs';

// Geographic to tile coordinates
const coord = TileCoord.fromGeo(13.4, 52.5, 10);
console.log(`Tile: z=${coord.z}, x=${coord.x}, y=${coord.y}`);

// Tile to geographic coordinates
const tile = new TileCoord(10, 550, 335);
const [lon, lat] = tile.toGeo();
console.log(`Location: ${lon}, ${lat}`);

// Get bounding box
const bbox = tile.toGeoBbox();
console.log('BBox:', bbox); // [west, south, east, north]

CommonJS Support

The package also supports CommonJS:

const { convert, TileSource, TileServer, TileCoord } = require('@versatiles/versatiles-rs');

API Reference

convert(input, output, options?, onProgress?, onMessage?)

Convert tiles from one format to another.

Parameters:

  • input (string): Input file path (.versatiles, .mbtiles, .pmtiles, .tar, directory)
  • output (string): Output file path
  • options (ConvertOptions, optional):
    • minZoom (number): Minimum zoom level
    • maxZoom (number): Maximum zoom level
    • bbox (array): Bounding box [west, south, east, north]
    • bboxBorder (number): Border around bbox in tiles
    • compress (string): Compression "gzip", "brotli", or "uncompressed"
    • flipY (boolean): Flip tiles vertically
    • swapXy (boolean): Swap x and y coordinates
  • onProgress (function, optional): Progress callback (data: ProgressData) => void
  • onMessage (function, optional): Message callback (data: MessageData) => void

Returns: Promise<void>

class TileSource

TileSource.open(path)

Open a tile container.

Parameters:

  • path (string): File path or URL

Returns: Promise<TileSource>

TileSource.fromVpl(vpl, basePath?)

Create a tile source from VPL (VersaTiles Pipeline Language).

Parameters:

  • vpl (string): VPL query string
  • basePath (string, optional): Base path for resolving relative paths

Returns: Promise<TileSource>

source.getTile(z, x, y)

Get a single tile.

Parameters:

  • z (number): Zoom level
  • x (number): Tile column
  • y (number): Tile row

Returns: Promise<Buffer | null>

source.tileJson()

Get TileJSON metadata.

Returns: TileJSON

interface TileJSON {
  tilejson: string;
  tiles?: string[];
  vector_layers?: VectorLayer[];
  attribution?: string;
  bounds?: [number, number, number, number];
  center?: [number, number, number];
  // ... and more
}

source.metadata()

Get source metadata.

Returns: SourceMetadata

interface SourceMetadata {
  tileFormat: string;
  tileCompression: string;
  minZoom: number;
  maxZoom: number;
}

source.sourceType()

Get source type information.

Returns: SourceType

source.convertTo(output, options?, onProgress?, onMessage?)

Convert this source to another format.

Parameters:

  • output (string): Output file path
  • options (ConvertOptions, optional): Same as convert()
  • onProgress (function, optional): Progress callback
  • onMessage (function, optional): Message callback

Returns: Promise<void>

class TileServer

new TileServer(options?)

Create a new tile server.

Parameters:

  • options (object, optional):
    • ip (string): IP address to bind (default: "0.0.0.0")
    • port (number): Port number (default: 8080)
    • minimalRecompression (boolean): Use minimal recompression

server.addTileSourceFromPath(name, path)

Add a tile source from a file path.

Parameters:

  • name (string): Source name (URL will be /tiles/{name}/...)
  • path (string): Container file path

Returns: Promise<void>

server.addTileSource(name, source)

Add a tile source from a TileSource instance.

Parameters:

  • name (string): Source name
  • source (TileSource): TileSource instance

Returns: Promise<void>

server.removeTileSource(name)

Remove a tile source.

Parameters:

  • name (string): Source name to remove

Returns: Promise<void>

server.addStaticSource(path, urlPrefix?)

Add static file source.

Parameters:

  • path (string): Directory or .tar file
  • urlPrefix (string, optional): URL prefix (default: "/")

Returns: Promise<void>

server.start()

Start the HTTP server.

Returns: Promise<void>

server.stop()

Stop the HTTP server.

Returns: Promise<void>

server.port

Get server port (getter).

Returns: number

class TileCoord

new TileCoord(z, x, y)

Create a tile coordinate.

Parameters:

  • z (number): Zoom level
  • x (number): Column
  • y (number): Row

TileCoord.fromGeo(lon, lat, z)

Create from geographic coordinates (static).

Parameters:

  • lon (number): Longitude
  • lat (number): Latitude
  • z (number): Zoom level

Returns: TileCoord

coord.toGeo()

Convert to geographic coordinates.

Returns: [number, number] - [lon, lat]

coord.toGeoBbox()

Get geographic bounding box.

Returns: [number, number, number, number] - [west, south, east, north]

coord.toJson()

Get JSON representation.

Returns: string

Properties

  • coord.z (number): Zoom level
  • coord.x (number): Column
  • coord.y (number): Row

Supported Formats

  • VersaTiles (.versatiles) - Native format
  • MBTiles (.mbtiles) - SQLite-based format
  • PMTiles (.pmtiles) - Cloud-optimized format
  • TAR (.tar) - Archive format
  • Directory - File system based

Examples

See the examples directory for more usage examples:

All examples use TypeScript and can be run with:

npx tsx examples/<filename>.ts

Development

Building from Source

# Install dependencies
npm install

# Build debug version
npm run build:debug

# Build release version
npm run build

# Run tests
npm test

Requirements

  • Node.js >= 16
  • Rust toolchain (for building from source)

License

MIT License - see LICENSE for details.

Links

Contributing

Contributions are welcome! Please see the main versatiles-rs repository for contribution guidelines.