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

s2polyline-ts

v1.0.1

Published

Encoding/decoding S2 polylines for JavaScript

Readme

s2polyline-ts

npm version

Encoding/decoding S2 polylines for JavaScript. This library is a TypeScript port of the S2 Geometry Library's polyline encoding/decoding functionality.

Overview

This package provides utilities for manipulating geometric shapes on a sphere, making it suitable for working with geographic data. It's based on the S2 Geometry Library, which is designed for spherical geometry rather than planar 2D maps.

This library specifically focuses on encoding and decoding S2 polylines, which are sequences of points on the sphere represented in a compact, encoded format.

Installation

npm install s2polyline-ts

Demo

A demo of the is published to GitHub Pages: https://regeter.github.io/s2polyline-ts/

Usage

import { encode, decode } from 's2polyline-ts';
import { S2LatLng } from 's2polyline-ts';

// Encoding
const coordinates: S2LatLng[] = [
    S2LatLng.fromDegrees(37.7749, -122.4194), // San Francisco
    S2LatLng.fromDegrees(40.7128, -74.0060),  // New York
    S2LatLng.fromDegrees(34.0522, -118.2437)  // Los Angeles
];
console.log("Encoding::", coordinates);
const encoded: string = encode(coordinates);
console.log("Encoded::", encoded);

// Decoding
const encodedPolyline = 'AhoGJjx2y008lAIA1rLcAaXivALU9BzoKYu8cgA';
const decoded = decode(encodedPolyline);
console.log("Decoded::", decoded);

API Reference

  • encode(coordinates: S2LatLng[]): string: Encodes an array of S2LatLng objects into an S2 encoded polyline string.
  • decode(encodedPolyline: string): S2LatLng[]: Decodes an S2 encoded polyline string into an array of S2LatLng objects.
  • S2LatLng class for representing a latitude and longitude
    • S2LatLng.fromDegrees(latDegrees: number, lngDegrees: number): Create from degrees

Contributing

Contributions are welcome! Please see the GitHub repository for issues and pull requests.

License

Apache 2.0

Credits

This library is based on the S2 Geometry Library. Initial code created by Sukolsak Sakshuwong.

Disclaimer

This is not an official Google product.