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

@cargoffer/polyline

v1.0.1

Published

decode()/encode() del algoritmo Google Polyline (precision 5/6) — reemplazo minimalista y 100% compatible de @mapbox/polyline para TRANSCEND

Downloads

161

Readme

@cargoffer/polyline

npm version npm downloads CI License: MIT

decode() / encode() del algoritmo Google Polyline (precision 5 y 6), sin dependencias runtime. Reemplazo minimalista y 100 % compatible de @mapbox/polyline para el ecosistema TRANSCEND de Cargoffer.

  • 🔬 Mismo algoritmo bit a bit que @mapbox/[email protected] (solo las dos funciones que usa TRANSCEND: decode y encode).
  • 🧪 Bateria de compatibilidad: vectores oficiales de la suite de @mapbox/polyline + vector real de Valhalla + test diferencial contra el paquete original (fuzz determinista de miles de polylines).
  • 📦 Build dual ESM + CJS con tipos TypeScript (exports map).
  • ⚖️ Licencia MIT. Cero dependencias runtime.

🚛 Hecho para TRANSCEND — calculo de rutas, costes y tiempos para transporte por carretera en Europa: transcend.cargoffer.com

Instalacion

npm install @cargoffer/polyline

Uso

import polyline from '@cargoffer/polyline';
// o: import * as polyline from '@cargoffer/polyline';
// o: import { decode, encode } from '@cargoffer/polyline';

// decode: string polyline -> [lat, lng][]
const coords = polyline.decode('_p~iF~ps|U_ulLnnqC_mqNvxq`@');
// => [[38.5, -120.2], [40.7, -120.95], [43.252, -126.453]]

// encode: [lat, lng][] -> string
const shape = polyline.encode([[38.5, -120.2], [40.7, -120.95]]);
// => '_p~iF~ps|U_ulLnnqC_mqNvxq`@'

Precision

  • Por defecto 5 decimales (igual que @mapbox/polyline).
  • Valhalla emite precision 6 por defecto (shape_format: polyline6): hay que pasar 6 explícitamente.
polyline.decode(shape, 6); // shapes de Valhalla
polyline.encode(coords, 6);

API

| Funcion | Firma | Devuelve | | --- | --- | --- | | decode | decode(str: string, precision?: number) | [lat, lng][] | | encode | encode(coordinates: [lat, lng][], precision?: number) | string |

  • decode('') → [] · encode([]) → ''
  • precision no entero (incl. undefined) → se usa 5 (semantica identica a @mapbox/polyline).
  • Las coordenadas con tercera componente ([lat, lng, z]) se aceptan; z se ignora (igual que el original).

Desarrollo

npm install          # devDeps: typescript + @mapbox/polyline (solo para tests)
npm run build        # compila dist/esm + dist/cjs + dist/types
npm test             # node --test: vectores oficiales + Valhalla + diferencial
npm pack             # comprueba el contenido del tarball antes de publicar

@mapbox/polyline es solo devDependency (para el test diferencial). Si no esta instalada, los tests diferenciales se saltan sin fallar.

Compatibilidad con @mapbox/polyline

Verificado ejecutando el paquete original lado a lado:

| Caso | Resultado | | --- | --- | | Vectores oficiales de la suite de @mapbox/polyline (p0, p5, p6, p13, redondeos, backslashes) | ✔ identicos | | Vector real de Valhalla p6 (e~epoA|jfpOiDaK) | ✔ identico | | Fuzz 9000 polylines aleatorios (p5 y p6, encode y decode) | ✔ strings y arrays identicos |

Licencia

MIT — Cargoffer (TRANSCEND).


Algoritmo de referencia: Google Encoded Polyline Algorithm Format. Formato Valhalla: Valhalla API — Decoding shape.