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

zip-to-tz

v1.1.0

Published

Converts a zipcode to a timezone

Downloads

4,665

Readme

zip-to-tz

This is a re-implementation of DoubleDor's node-zipcode-to-timezone, but optimized for space so that you can use it in the browser with less bloat.

We utilize the same source data in zipcodes.json and generate a map of only the upperbounds. The numercially ordered zipcodes (indexes into timezone-map.json), don't produce timezone indexes that are strictly monotonically increasing (for obvious reasons), so while this isn't a perfect solution, the Gzipped size of the optimized zipcode map is 2.8% of the original Gzipped zipcode map.

Since we don't have an exhaustive list of all zipcodes, we use a binary search function to find where the zipcode lies within the map of upper bounds and return the result.

This module assumes that the zipcode is valid. The original module returned undefined for unknown or invalid zipcodes, because we don't have an exhaustive list, we'll return a timezone for potentially invalid zipcodes.

This module basically trades space for time as the lookup isn't a direct attribute read, but a binary search of the optimized zipcode map keys until we find what range the target zipcode lies in.

| | entries | size | size (gzipped) | | ----------------- | ------- | ----- | -------------- | | zipcodes map | 41962 | 672KB | 107KB | | upper bounded map | 1026 | 14KB | 3KB |

e.g. Instead of:

{
  ...
  '11111': 0,
  '11112': 0,
  ...
  '11914': 0,
  '11915': 1,
  '11916': 0,
  '11917': 1,
  '11918': 0,
  '11919': 1,
  '11920': 1,
  ...
  '13587': 1,
  '13588': 1,
  '13589': 2,
  '13590': 2,
  ...
  '15623': 2,
  '13624': 2,
  '13625': 3,
  '13626': 3,
  ...
}

We'd keep track of:

  ...
  '11914': 0,
  '11915': 1,
  '11916': 0,
  '11917': 1,
  '11918': 0,
  '13588': 1,
  '13624': 2,
  '13625': //wherever 3 ends
  ...

Installation

npm install --save zip-to-tz

Usage

var zipToTz = require( 'zip-to-tz' );

var tz = zipToTz( '94110' );
console.log( tz ); // America/Los_Angeles
import zipToTz from 'zip-to-tz'

const tz = zipToTz( '94110' );
console.log( tz ); // America/Los_Angeles

Other info

This project uses the timezone list found here:

https://sourceforge.net/projects/zip2timezone/files/