Git Product home page Git Product logo

z1p's Introduction

Zip Codes Validation and Parse ๐Ÿ“ฌ

Build Status

The module that can be used for search places via zip code and other geolocation properties.

Usage

Install package:

npm i z1p

Then you need to add countries you wish to search in. For example the USA.

npm i @zip/us

Then you can use it like this:

const z1p = require("z1p");

// Get places by zip code.
z1p(["US"]).raw(v => v.zip_code == "59330");

// Same as above
z1p(["us"]).findBy("zip_code", "59330"));

// Same as above but memorized
z1p(["Us"], {memorize: true}).findBy("zip_code", "59330"));

//Result
/*
[ { accuracy: '1',
    community: null,
    community_code: null,
    country_code: 'US',
    latitude: '47.1008',
    longitude: '-104.7287',
    place: 'Glendive',
    province: 'Dawson',
    province_code: '021',
    state: 'Montana',
    state_code: 'MT',
    zip_code: '59330' } ]
*/

API

z1p(codes, options)

  • codes {Array of Strings} Country codes to search in. By default equals all available.
  • options {Object}
    • memorize {Boolean} default: false this options for memorization at methods

.raw(compare)

  • compare {Function} function to find.
    returns: {Array of Places}

.findBy(key, value)

  • key {String} key in object strucuture (zip_code, accuracy, etc.)

  • value {String} value to find.

    returns: {Array of Places}

Note: This method could be memorized. Every result will be saved to memory so the only first call will be slow.

Place object looks like this:

{
  accuracy: '1', // Accuracy of place
  community: 'community', // Community name
  community_code: 'community_code', // Community code
  country_code: 'country_code', // Country code
  latitude: '1', // Latitude
  longitude: '-1', // Longitude
  place: 'place', // Place
  province: 'province', // Province
  province_code: '021', // Province code
  state: 'state', // State
  state_code: 'state_code', // State code
  zip_code: '1' // Zip code
}

Example:

  { accuracy: '1',
    community: null,
    community_code: null,
    country_code: 'US',
    latitude: '47.1008',
    longitude: '-104.7287',
    place: 'Glendive',
    province: 'Dawson',
    province_code: '021',
    state: 'Montana',
    state_code: 'MT',
    zip_code: '59330' }

Countries

TODO:

  1. Add wrappers to raw.
  2. Improve performance.

GeoData provided by geonames.org

z1p's People

Contributors

malyuchok avatar stepanvanzuriak avatar vzhufk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.