1.0.0 • Published 8 months ago

postcode-format v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

postcode-format

A JavaScript port of the brick/postcode PHP library for validating and formatting postcodes for all countries which have a postcode system.

Installation

npm install postcode-format

Usage

import postcodeFormat from 'postcode-format';
postcodeFormat('GB', 'SW1A2aa');  // SW1A 2AA

The first argument is the ISO 3166 country code for the country which you wish to validate/format a postcode for, and the second argument is the postcode itself.

An UnknownCountryException will be thrown for invalid/unsupported countries, and an InvalidPostcodeException exception will be thrown if the provided postcode is not valid in the chosen country.

Code generation

To save development effort, some scripts (located in scripts/) have been created to parse the source code and tests from the PHP library implementation and convert these to JavaScript, so that changes made in the PHP library can be quickly ported over. In some cases, manual code changes may be required to import more complex logic.

1.0.0

8 months ago