Git Product home page Git Product logo

swedish-zipcode's Introduction

Swedish Zipcode

This package provides validation for Swedish zip codes (or postal codes) based on the provided CSV. The CSV was generated at 2019-01-19 by traversing the Bring API described below between 10000 and 99999.

HTTPS fallback

Since there're constantly changes in zip codes in Sweden a lot of them are missing in the CSV submodule. This package supports the possibiity to fallback to an HTTPS API from Bring.

If you call Store() on the ZipCodes type you can store all newly found zip codes in the existing CSV file for faster and offline execution in the future.

Multiple results

A few zip codes are listed as multiple matches which means they're shared between multiple locations. Instead of choosing one of them none is chosen so to see which these are you can use grep ',$' sweden-zipcode.csv.

Example

set ex (grep  ',$' sweden-zipcode.csv | string sub --length 5 | head -1); \
    curl -sL \
    "https://api.bring.com/shippingguide/api/postalCode.json?clientUrl=ex&country=SE&pnr=$ex" \
    | jq .multipleMatches

[
  "Södertälje",
  "Enhörna"
]

Examples

// One time validation
sz.Valid("12010") // true
sz.Valid(12010)   // true

// Multiple validations - create a cache
httpFallback := true
zc := sz.NewZipCodes(httpFallback)
zc.ClientURL("https://my.url.se")

zc.Valid("12010") // true
zc.Valid(12010)   // true
zc.Valid(99999)   // false

zc.Store()        // Updates the CSV file with new zip codes.

swedish-zipcode's People

Contributors

bombsimon avatar sieuwerts avatar

Watchers

 avatar  avatar

Forkers

sieuwerts

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.