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 🙏

© 2024 – Pkg Stats / Ryan Hefner

use-postal-ph

v1.1.10

Published

This utility library is specifically designed for the Philippines, providing comprehensive information on postal codes, municipalities, locations, and regions. Moreover, searching within the library is case insensitive.

Downloads

167

Readme

use-postal-ph

This utility library is specifically designed for the Philippines, providing comprehensive information on postal codes, municipalities, locations, and regions. Moreover, searching within the library is case insensitive.

use-postal-ph

npm version Bundlephobia Downloads MIT License jsDocs.io Playwright Tests

Contents

Installation

Install via NPM:

npm install use-postal-ph

Or via Yarn:

yarn add use-postal-ph

Usage

To start using the use-postal-ph library, follow these steps:

import usePostalPH from 'use-postal-ph';

You can now utilize the library's methods to retrieve postal code, municipality, location, and region information.

const postalPH = usePostalPH();

// Fetch a list of municipalities
const municipalities = postalPH.fetchMunicipalities();
console.log(municipalities);

// Fetch postal codes
const postalCodes = postalPH.fetchPostCodes();
console.log(postalCodes);

// Fetch locations
const locations = postalPH.fetchLocations();
console.log(locations);

// Fetch regions
const regions = postalPH.fetchRegions();
console.log(regions);

// Fetch all data lists
const dataLimit = postalPH.fetchDataLists();
console.log(dataLimit);

You can also specify search criteria and limit the number of results returned:

// Fetch a list of municipalities starting with 'Manila' and limit the result to 10
const municipalities = postalPH.fetchMunicipalities({search: 'Manila', limit: 10});
console.log(municipalities);

// Fetch postal code for 6045
const postalCodes = postalPH.fetchPostCodes({search: 6045});
console.log(postalCodes);

// Fetch postal codes with a limit of 5
const postalCodesLimit = postalPH.fetchPostCodes({limit: 5});
console.log(postalCodesLimit);

// Fetch locations containing 'Cebu' and limit the result to 3
const locations = postalPH.fetchLocations({search: 'Cebu', limit: 3});
console.log(locations);

// Fetch regions starting with 'NCR' and limit the result to 8
const regions = postalPH.fetchRegions({search: 'NCR', limit: 8});
console.log(regions);

// Fetch all data lists with a limit of 15
const dataLimit = postalPH.fetchDataLists({limit: 15});
console.log(dataLimit);

// Fetch data based on the search criteria
const dataList = postalPH.fetchDataLists({
    post_code: 6045,
    location: "Talisay",
    region: "VII",
    municipality: "Cebu"
});
console.log(dataList);

Demo

Explore the live demo to experience fetching and searching functionalities for municipalities, post codes, locations, and regions. Interact with the application to witness its efficiency and responsiveness in action.

https://use-postal-ph.vercel.app

Importing Types

You can also import specific types provided by use-postal-ph:

import type {PlaceProps, SearchCriteriaProps, PlaceListCriteriaProps} from "use-postal-ph";

Type Definitions

Here are the type definitions provided by use-postal-ph:


export type PlaceDataProps = {
    data: PlaceProps[];
};

export type PlaceProps = {
    municipality?: string;
    location?: string;
    post_code?: number | string;
    region?: string;
};

export type SearchCriteriaProps = {
    search?: number | string;
    limit?: number;
};

export type PlaceListCriteriaProps = PlaceProps & {
    limit?: number;
};

Query Options

When using the library's methods, you have the option to include an object containing parameters for more specific queries:

  • search: This parameter is used to find specific information. For postal codes, search directly for the code itself. You can also search for municipalities, locations, and regions based on your query.
  • limit: This parameter restricts the number of results returned for municipalities, locations, and regions. However, it does not affect the results when searching for postal codes.
  • municipality: Search by the name of the municipality.
  • post_code: Search by the postal code.
  • location: Search by the specific district or neighborhood.
  • region: Search by the region where the place is located.

ECMAScript Module (ESM) Entry Point

If you prefer not to install the package and want to include the ECMAScript module (ESM) entry point directly in your project, you can use the following script tag:

Import Statement:


<script type="module">
    import usePostalPH from 'https://unpkg.com/[email protected]/dist/index.mjs';

    const {
        fetchDataLists,
        fetchLocations,
        fetchMunicipalities,
        fetchPostCodes,
        fetchRegions
    } = usePostalPH();

    console.log(fetchPostCodes({search: "6045"}))
</script>

This script imports the fetchPostCodes function from the use-postal-ph package and retrieves information for the postal code '6045'. It then logs the result to the console.

{
  "location": "Cebu",
  "region": "VII",
  "municipality": "Talisay",
  "post_code": 6045
}

Contribution Guidelines

Contributions are highly appreciated! To contribute, fork the repository, create a new branch for your changes, and submit a pull request. Please ensure your code adheres to the existing coding standards and conventions. While this library provides information, it may not be comprehensive. Contributions aimed at enhancing the comprehensiveness of the data are welcome.

References

The use-postal-ph library utilizes data sourced from Wikipedia, including information on regions, provinces, and municipalities of the Philippines.

License

MIT © blckclov3r