Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including @creadi/swiss-zipcodes with all npm packages installed. Try it out:

var swissZipcodes = require("@creadi/swiss-zipcodes")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

@creadi/swiss-zipcodes v1.0.1

Swiss zip codes

GitHub issues npm Build Status

swiss-zipcodes

Purpose

Search and validate swiss zip codes

Usage

npm i --save swiss-zipcodes
# or
npm install https://github.com/creadi/swiss-zipcodes

and

import { search, validate, cityFromZip } from 'swiss-zipcodes'

search()

Search by any combination of:

  • zip (number)
  • canton (string)
  • commune (string)
search({ zip: 4054 })

returns

[
  {
    zip: 4054,
    canton: 'BS',
    commune: 'Basel'
  }
]

validate()

Validate zip code as number or string

validate(4054)

// or

validate('4054')

returns true

cityFromZip()

Get an array of commune names from a zip code ( number or string)

cityFromZip(4052)

// or

cityFromZip('4052')

returns

[
  'Basel',
  'Münchenstein'
]

Data

Data from Federal Statistics https://www.bfs.admin.ch/bfs/fr/home/bases-statistiques/repertoire-officiel-communes-suisse/tableau-correspondance-regbl.assetdetail.2861277.html

Direct link to excel sheet https://www.bfs.admin.ch/bfsstatic/dam/assets/2861277/master

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free