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 🙏

© 2025 – Pkg Stats / Ryan Hefner

quad-hexer

v0.2.1

Published

A library for converting between quad and hex representations of geocodes.

Downloads

29

Readme

quad-hexer

GitHub Actions Status Version License

Overview

quad-hexer is a JavaScript library that losslessly compresses location coordinate encodings by approximately 50% by converting the quaternary part (base-4 expression) of geocode formats such as Quadkey, S2 Hilbert Quadkey, and Spatial ID Tilehash (Z-order curve) into a hexadecimal format starting with x.

When converting each quaternary digit (2 bits) into hexadecimal (4 bits), if the total number of digits (level) is odd, a # symbol is added as an indicator, followed by a single quaternary character (0–3).
This mechanism preserves both prefix-matching searchability and sort order of the original quaternary representation.

Example (latitude/longitude 35.675, 139.762):

| Geocode Type | Level | Original Value | Encoded Value | |--------------|-------|----------------|---------------| | Quadkey | 22 | 1330021123120010111021 | x7c25b604549 | | Quadkey | 23 | 13300211231200101110210 | x7c25b604549#0 | | Quadkey | 24 | 133002112312001011102101 | x7c25b6045491 | | S2 Hilbert Quadkey | 20 | 3/00003010113313330121 | 3x00c45f7f19 | | S2 Hilbert Quadkey | 21 | 3/000030101133133301211 | 3x00c45f7f19#1 | | S2 Hilbert Quadkey | 22 | 3/0000301011331333012112 | 3x00c45f7f196 | | Spatial ID Tilehash (Z-order curve) | 22 | 2441132234231121222132 | x7c25b604549 | | Spatial ID Tilehash (Z-order curve) | 23 | 24411322342311212221321 | x7c25b604549#0 | | Spatial ID Tilehash (Z-order curve) | 24 | 244113223423112122213212 | x7c25b6045491 |

When using Spatial ID with a nonzero F (Floor / Altitude) component, the hexadecimal encoding appends a + or - to indicate the sign, followed by the hexadecimal value of the F component after the XYZ part.

  • Example: Latitude/longitude 35.675, 139.762 with altitude 100 meters at zoom level 23
    • ZFXY format: 23/25/7450994/3303428
    • Tilehash (Z-order curve): 24411322342311212265325
    • Encoded value: x7c25b604549#0+19

Demo

https://sanak.github.io/quad-hexer/

Installation

npm install quad-hexer
# or
# yarn add quad-hexer
# pnpm add quad-hexer

Usage

Quadkey

import { quadHexer } from 'quad-hexer';

const hexQuadkey = quadHexer.encodeQuadkey('13300211231200101110210');
console.log(hexQuadkey);
// => x7c25b604549#0
console.log(quadHexer.decodeHexQuadkey(hexQuadkey));
// => 13300211231200101110210

S2 Hilbert Quadkey

import { quadHexer } from 'quad-hexer';

const hexS2HilbertQuadkey = quadHexer.encodeS2HilbertQuadkey('3/000030101133133301211');
console.log(hexS2HilbertQuadkey);
// => 3x00c45f7f19#1
console.log(quadHexer.decodeHexS2HilbertQuadkey(hexS2HilbertQuadkey));
// => 3/000030101133133301211

Spatial ID Tilehash (Z-order curve)

import { quadHexer } from 'quad-hexer';

const hexSpatialIdTileHash = quadHexer.encodeSpatialIdTilehash('24411322342311212221321');
console.log(hexSpatialIdTileHash);
// => x7c25b604549#0
console.log(quadHexer.decodeHexSpatialIdTilehash(hexSpatialIdTileHash));
// => 24411322342311212221321

License

MIT License

Contribution

Bug reports and feature requests are welcome via GitHub Issues.
Pull requests are also highly appreciated!