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

ubigeo-fns

v1.2.0

Published

Funciones utilitarias para trabajar con ubigeos del Perú en JavaScript y TypeScript.

Readme

ubigeo-fns

npm version License: MIT Downloads npm bundle size Security

Funciones utilitarias para trabajar con ubigeos del Perú en JavaScript y TypeScript. Permite obtener distrito, provincia y departamento, validar códigos UBIGEO y trabajar con información geográfica completa (coordenadas, población, área) de manera sencilla.

🔹 Características

  • Obtener distrito, provincia y departamento por código UBIGEO
  • Acceder a información completa del ubigeo (coordenadas, población, área)
  • Validar códigos UBIGEO a nivel de departamento, provincia y distrito
  • Formatear ubigeos en texto listo para mostrar
  • Parsear códigos UBIGEO en sus partes jerárquicas
  • Búsquedas y validaciones optimizadas (O(1) con estructuras eficientes)
  • Compatible con JavaScript y TypeScript (tipado incluido)
  • Optimizado para Node.js, React y bundlers modernos
  • Soporta tree-shaking y minificación

💡 Casos de uso

  • Formularios con selección de ubigeo (departamento, provincia, distrito)
  • Validación de direcciones en sistemas ERP
  • Aplicaciones de delivery y logística
  • Dashboards y análisis geográfico
  • Integración con APIs de facturación electrónica

⚡ Instalación

npm install ubigeo-fns
# o usando yarn
yarn add ubigeo-fns

📦 Uso

Compatible con JavaScript y TypeScript. Los tipos se infieren automáticamente.

import {
  getDistrict,
  getProvince,
  getDepartment,
  getDepartments,
  getProvinces,
  getDistricts
  validateUbigeo,
  getUbigeoData,
  parseUbigeo,
  formatUbigeo,
  isValidDepartment,
  isValidProvince,
  isValidDistrict
} from "ubigeo-fns";

// Ejemplo básico
const ubigeo = "150131";

getDepartment(ubigeo); // Lima
getProvince(ubigeo);   // Lima
getDistrict(ubigeo);   // San Isidro

getDepartments(); // [{ code: "15", name: "Lima" }, ...]
getProvinces("15"); // [{ code: "1501", name: "Lima" }, ...]
getDistricts("1501"); // [{ code: "150131", name: "San Isidro" }, ...]

// Validación
validateUbigeo(ubigeo); // true

// Data completa
const data = getUbigeoData(ubigeo);

// Formato
formatUbigeo(ubigeo);         // "San Isidro, Lima, Lima"
formatUbigeo(ubigeo, "short");// "San Isidro, Lima"

// Parseo
parseUbigeo(ubigeo);
// { departmentCode: "15", provinceCode: "1501", districtCode: "150131" }

// Validaciones específicas
isValidDepartment("15");
isValidProvince("1501");
isValidDistrict("150131");

🧩 Tipos

interface UbigeoData {
  ubigeo: string;
  district: string;
  province: string;
  department: string;
  population: string;
  area: string;
  lat: string;
  lng: string;
}

🔧 Funciones disponibles

| Función | Descripción | Parámetros | Retorno | | --------------------- | ------------------------------------------ | -------------------------------------------- | -------------------- | | getDepartment() | Devuelve el nombre del departamento | ubigeo: string | string | | getProvince() | Devuelve el nombre de la provincia | ubigeo: string | string | | getDistrict() | Devuelve el nombre del distrito | ubigeo: string | string | | getDepartments() | Lista todos los departamentos | - | { code, name }[] | | getProvinces() | Lista provincias por departamento | code: string| { code, name }[] | | getDistricts() | Lista distritos por provincia | code: string| { code, name }[] | | validateUbigeo() | Valida si el UBIGEO existe | ubigeo: string | boolean | | getUbigeoData() | Devuelve toda la información del ubigeo | ubigeo: string | UbigeoData \| null | | parseUbigeo() | Separa el ubigeo en códigos jerárquicos | ubigeo: string | object \| null | | formatUbigeo() | Devuelve el ubigeo formateado | ubigeo: string, format?: 'full' \| 'short' | string | | isValidDepartment() | Valida si el código de departamento existe | code: string | boolean | | isValidProvince() | Valida si el código de provincia existe | code: string | boolean | | isValidDistrict() | Valida si el código de distrito existe | code: string | boolean |

⚙️ Minificación y Build

El proyecto está preparado con tsup:

npm run build
  • Genera dist/ con módulos ESM y tipados TypeScript (.d.ts)
  • Minificado para producción
  • Listo para publicar en npm

📦 Changelog

v1.2.0

✨ Nuevas funciones:

  • getDepartments
  • getProvinces
  • getDistricts

⚡ Mejora:

  • Acceso jerárquico optimizado con Map (O(1))
  • Ideal para formularios y selects dependientes

v1.1.0

✨ Nuevas funciones:

  • getUbigeoData
  • parseUbigeo
  • formatUbigeo
  • isValidDepartment
  • isValidProvince
  • isValidDistrict

⚡ Mejora:

  • Validaciones optimizadas usando Set (O(1))

v1.0.0

🎉 Lanzamiento inicial

✨ Funciones:

  • getDistrict
  • getProvince
  • getDepartment
  • validateUbigeo

⚙️ Características:

  • Compatible con JavaScript y TypeScript
  • Soporte para ES Modules (ESM)
  • Tipado incluido (.d.ts)
  • Optimizado para Node.js y bundlers
  • Soporta tree-shaking

📝 Licencia

MIT © 2026 Franco Caballero LICENSE

🌎 Enlaces