All Projects → fragaria → address-formatter

fragaria / address-formatter

Licence: MIT license
Universal international address formatter in Javascript

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to address-formatter

Fluent.js
JavaScript implementation of Project Fluent
Stars: ✭ 622 (+856.92%)
Mutual labels:  i18n, formatting
Address Formatting
templates to format geographic addresses
Stars: ✭ 253 (+289.23%)
Mutual labels:  i18n, formatting
AutoFormatInputWatcher
This repository contains input watcher for auto formatting digits in edit text
Stars: ✭ 15 (-76.92%)
Mutual labels:  formatting
translation
👅 Translations (symfony/translation) to Nette Framework (@nette)
Stars: ✭ 55 (-15.38%)
Mutual labels:  i18n
wlc
Weblate command line client
Stars: ✭ 22 (-66.15%)
Mutual labels:  i18n
pydantic-i18n
pydantic-i18n is an extension to support an i18n for the pydantic error messages.
Stars: ✭ 32 (-50.77%)
Mutual labels:  i18n
archived-bot
A Discord music bot serving music in over 3 million discord servers
Stars: ✭ 496 (+663.08%)
Mutual labels:  i18n
grunt-assemble-i18n
Assemble middleware for adding i18n support to projects.
Stars: ✭ 25 (-61.54%)
Mutual labels:  i18n
v-page
A simple pagination bar, including length Menu, i18n support, based on Vue2.x
Stars: ✭ 85 (+30.77%)
Mutual labels:  i18n
tr4n5l4te
Use Google Translate without an API key.
Stars: ✭ 32 (-50.77%)
Mutual labels:  i18n
intl-tel-input-rails
intl-tel-input for the Rails asset pipeline
Stars: ✭ 35 (-46.15%)
Mutual labels:  formatting
gettext-extractor
A flexible and powerful Gettext message extractor with support for JavaScript, TypeScript, JSX and HTML.
Stars: ✭ 82 (+26.15%)
Mutual labels:  i18n
vscode-uncrustify
Code format using uncrustify
Stars: ✭ 62 (-4.62%)
Mutual labels:  formatting
CHRTextFieldFormatter
Provides UITextField formatting masks. Such as phone number and credit card number formatters.
Stars: ✭ 52 (-20%)
Mutual labels:  formatting
vue-element-admin-ts
vue-element-admin 的 typescript 版本
Stars: ✭ 101 (+55.38%)
Mutual labels:  i18n
acts as localized
Localization accessor mechanism for AR models
Stars: ✭ 12 (-81.54%)
Mutual labels:  i18n
i18n
internationalize projects to Arabic
Stars: ✭ 67 (+3.08%)
Mutual labels:  i18n
Angular-Gulp-Boilerplate
Clean but full-featured AngularJS boilerplate using Gulp workflow and best practices
Stars: ✭ 30 (-53.85%)
Mutual labels:  i18n
ii18n
II18N - Go i18n library.
Stars: ✭ 20 (-69.23%)
Mutual labels:  i18n
vscode-fortran-support
Fortran language support for Visual Studio Code
Stars: ✭ 49 (-24.62%)
Mutual labels:  formatting

JS Address formatter

Coverage Status

Based on an amazing work of OpenCage Data who collected so many international formats of postal addresses, this is a Javascript implementation of that formatter.

This library can format almost anything that comes out of Open Street Maps' Nominatim API in the address field. Other compatible sources of data such as Photon might be used as well.

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, such as Avenue or Road.

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

Node

npm i @fragaria/address-formatter
const addressFormatter = require('@fragaria/address-formatter');

// Basic examples
const formatted = addressFormatter.format({
  "houseNumber": 301,
  "road": "Hamilton Avenue",
  "neighbourhood": "Crescent Park",
  "city": "Palo Alto",
  "postcode": 94303,
  "county": "Santa Clara County",
  "state": "California",
  "country": "United States of America",
  "countryCode": "US",
});
/*
301 Hamilton Avenue
Palo Alto, CA 94303
United States of America
*/
const formattedWithAppendedCountry = addressFormatter.format({
  "houseNumber": 301,
  "road": "Hamilton Avenue",
  "neighbourhood": "Crescent Park",
  "city": "Palo Alto",
  "postcode": 94303,
  "county": "Santa Clara County",
  "state": "California",
  "countryCode": "US",
}, {
  appendCountry: true
});
/*
301 Hamilton Avenue
Palo Alto, CA 94303
United States of America
*/

// You can overwrite the country code incoming from the map service
const abbreviatedUkFormat = addressFormatter.format({
  "houseNumber": 301,
  "road": "Hamilton Avenue",
  "neighbourhood": "Crescent Park",
  "city": "Palo Alto",
  "postcode": 94303,
  "county": "Santa Clara County",
  "state": "California",
  "country": "United States of America",
  "countryCode": "US",
}, {
  abbreviate: true,
  countryCode: 'UK'
});
/*
301 Hamilton Ave
Palo Alto 94303
USA
*/

// You can use a fallback to keep the library working when the country code is wrong
const fallbackCountryCode = addressFormatter.format({
  "houseNumber": 301,
  "road": "Hamilton Avenue",
  "neighbourhood": "Crescent Park",
  "city": "Palo Alto",
  "postcode": 94303,
  "county": "Santa Clara County",
  "state": "California",
  "country": "United States of America",
  "countryCode": "yu",
}, {
  abbreviate: true,
  fallbackCountryCode: 'UK'
});
/*
301 Hamilton Ave
Palo Alto 94303
USA
*/

// You can get the address as a list of lines to make your formatting easier
const formatted = addressFormatter.format({
  "houseNumber": 301,
  "road": "Hamilton Avenue",
  "neighbourhood": "Crescent Park",
  "city": "Palo Alto",
  "postcode": 94303,
  "county": "Santa Clara County",
  "state": "California",
  "country": "United States of America",
  "countryCode": "US",
}, {
  output: 'array'
});
/*
[
  '301 Hamilton Avenue',
  'Palo Alto, CA 94303',
  'United States of America'
]
*/

Direct use on webpage

<script type="text/javascript" src="https://unpkg.com/@fragaria/[email protected]"></script>
<script type="text/javascript">
  const formatted = window.addressFormatter.format({
    "houseNumber": 301,
    "road": "Hamilton Avenue",
    "neighbourhood": "Crescent Park",
    "city": "Palo Alto",
    "postcode": 94303,
    "county": "Santa Clara County",
    "state": "California",
    "country": "United States of America",
    "countryCode": "US",
  });
  /*
  301 Hamilton Avenue
  Palo Alto, CA 94303
  United States of America
  */
</script>

Development & Tests

$ git clone [email protected]: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

Making a release

$ npm version X.Y.Z
$ git push origin master && git push origin vX.Y.Z

And the CI server takes care of the rest

Help needed

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.

Acknowledgments

Grat many thanks to these implementations:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].