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

psgc-reader

v1.0.13

Published

Reads a PSGC publicaton file

Downloads

33

Readme

psgc-reader

GitHub Actions Workflow Status GitHub package.json dynamic Codecov

A package for ingesting PSGC publication files

Quickstart

import psgcReader from "psgc-reader";

const result = await psgcReader.read(filePath);
// result contains regions, provinces, cities, municipalities, subMunicipalities, and barangays that are associated with each other

// if statistical columns are not needed
const resultWithoutStatistics = await psgcReader.readWithoutStatistics(
    filePath
);

Or, just the raw data

import psgcReader, { PsgcRecord } from "psgc-reader";

const resultRaw: PsgcRecord[] = await psgcReader.readRaw(filePath);
// result is an array or records

Quickly convert the publication file into a json to inspect

import psgcReader from "psgc-reader";

await psgcReader.readToJson(filePath, jsonFilePath);

Or do it step by step

1. Import the package

import psgcReader from "psgc-reader";

2. Read

  • supply the publication file to filePath
    • You can get publication files here: https://psa.gov.ph/classification/psgc
  • sheetName has default value set to "PSGC"
  • Records will be stored in locations
await psgcReader.readPublicationFile(filePath, sheetName);

console.log(psgcReader.locations);

2.1 Before filtering, select a builder

import psgcReader, { BasicBuilder, CompleteBuilder } from "psgc-reader";

// The BasicBuilder will omit statistical fields
psgcReader.setBuilder(new BasicBuilder());

// Default builder: includes all fields
psgcReader.setBuilder(new CompleteBuilder());

3. Filter

  • regions
  • provinces
  • cities
  • municipalities
  • subMunicipalities
  • barangays
psgcReader.filter();

console.log(psgcReader.regions);
console.log(psgcReader.provinces);
console.log(psgcReader.cities);
console.log(psgcReader.municipalities);
console.log(psgcReader.subMunicipalities);
console.log(psgcReader.barangays);

4. Associate

This will link regions, provinces, cities, municipalities, subMunicipalities, and barangays

psgcReader.associate();

5. Explore

console.log("[Regions]");
psgcReader.regions.map((region) => console.log(" >", region.name));

console.log("[SubMunicipalities under Manila]");
psgcReader.cities
    .filter((city) => city.code === "1380600000")[0]
    .subMunicipalities?.map((subMunicipality) =>
        console.log(" >", subMunicipality.name)
    );

// https://stackoverflow.com/a/66523350
const barangayCountByName = psgcReader.barangays.reduce(
    (barangay, { name }) => {
        barangay[name] = barangay[name] || 0;
        barangay[name] += 1;

        return barangay;
    },
    {}
);

// https://stackoverflow.com/a/1069840
const barangayCountByNameSorted: any[] = [];
for (let name in barangayCountByName) {
    barangayCountByNameSorted.push([name, barangayCountByName[name]]);
}
barangayCountByNameSorted.sort(function (a, b) {
    return b[1] - a[1];
});

console.log("[Top 10 barangay names]");
console.log(barangayCountByNameSorted.slice(0, 10));