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

@dolphfi_/haiti-utils

v1.0.1

Published

A simple utility package to get geographical data about Haiti, such as departments and communes.

Downloads

9

Readme

English | Français | Kreyòl Ayisyen

Haiti Utils

npm version

haiti-utils is a lightweight, zero-dependency npm package that provides simple and reliable utilities for working with Haitian geographical data.

Why use haiti-utils?

  • Save Time: Stop searching for and hardcoding lists of departments, communes, or postal codes.
  • Reliable Data: Access a complete and structured dataset for all 10 departments.
  • Easy to Use: A simple and intuitive API that is fully typed with TypeScript.
  • Case-Insensitive: All search functions are case-insensitive for a better developer experience.

Installation

npm install haiti-utils
# or
yarn add haiti-utils
# or
bun add haiti-utils

Usage

Here are a few examples of how to use the package.

Get a list of all departments

import { getDepartments } from 'haiti-utils';

const departments = getDepartments();
console.log(departments);
// Output: ["Artibonite", "Centre", ...]

Get the communes of a specific department

import { getCommunes } from 'haiti-utils';

// The search is case-insensitive
const communes = getCommunes('Ouest'); 
console.log(communes);
// Output: ["Arcahaie", "Cabaret", ...]

Get the postal code of a commune

import { getPostalCode } from 'haiti-utils';

// The search is case-insensitive for both department and commune
const postalCode = getPostalCode('Ouest', 'Pétion-Ville');
console.log(postalCode);
// Output: "HT6122"

const notFound = getPostalCode('Nord', 'InvalidCommune');
console.log(notFound);
// Output: null

Get all data

import { getAllData } from 'haiti-utils';

const allData = getAllData();
console.log(allData[0].department); // "Artibonite"
console.log(allData[0].communes[0].name); // "Dessalines"

Validate a phone number

import { validatePhoneNumber } from 'haiti-utils';

validatePhoneNumber('+509 34 56 78 90'); // true
validatePhoneNumber('55555555'); // false

Format a phone number

import { formatPhoneNumber } from 'haiti-utils';

// Default format (international)
formatPhoneNumber('34567890'); // "+509 34 56 78 90"

// National format
formatPhoneNumber('+509 34.56.78.90', { format: 'national' }); // "3456-7890"

// Compact format
formatPhoneNumber('34567890', { format: 'compact' }); // "+50934567890"

// Invalid number
formatPhoneNumber('12345'); // null

API Reference

getDepartments(): string[]

Returns a list of all department names.

getCommunes(department: string): string[]

Returns a list of all communes for a given department. The search is case-insensitive. Returns an empty array if the department is not found.

getPostalCode(department: string, commune: string): string | null

Returns the postal code for a specific commune within a department. The search is case-insensitive for both department and commune. Returns null if not found or not available.

getAllData(): DepartmentData[]

Returns the complete dataset of all departments and their communes.

validatePhoneNumber(phoneNumber: string): boolean

Validates a Haitian phone number. It handles common formats, including the +509 country code, and ignores spaces or hyphens. Returns true if the number is valid, false otherwise.

formatPhoneNumber(phoneNumber: string, options?: { format: 'international' | 'national' | 'compact' }): string | null

Formats a Haitian phone number into a consistent, readable format. If the number is invalid, it returns null. The default format is international.

Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page.