JS Address formatter
It can automatically detect the country's
formatting customs, but allows you to pick a specific country
format. Furthermore, it allows you to abbreviate the common names,
The formatting specification for the whole world is part of the distribution package, there is currently no plan to prepare smaller builds with limited area coverage.
Installation & Usage
npm i @fragaria/address-formatter
const addressFormatter = ;// Basic examplesconst formatted = addressFormatter;/*301 Hamilton AvenuePalo Alto, CA 94303United States of America*/const formattedWithAppendedCountry = addressFormatter;/*301 Hamilton AvenuePalo Alto, CA 94303United States of America*/// You can overwrite the country code incoming from the map serviceconst abbreviatedUkFormat = addressFormatter;/*301 Hamilton AvePalo Alto 94303USA*/// You can use a fallback to keep the library working when the country code is wrongconst fallbackCountryCode = addressFormatter;/*301 Hamilton AvePalo Alto 94303USA*/// You can get the address as a list of lines to make your formatting easierconst formatted = addressFormatter;/*['301 Hamilton Avenue','Palo Alto, CA 94303','United States of America']*/
Direct use on webpage
Development & Tests
$ git clone email@example.com:fragaria/address-formatter.git$ cd address-formatter# Install the proper NodeJS$ nvm install# Download the /OpenCageData/address-formatting/ spec$ npm run pull-submodules# Install dependencies$ npm install# Generate JS-friendly spec$ npm run prepare-templates# Run the tests$ npm test
All pull requests are definitely welcome. If an address is badly formatted, submit PRs directly to the original repository with a minimal localized test-case.
Grat many thanks to these implementations: