@shopify/address
Address utilities for formatting addresses.
Last updated 21 days ago by shopify-dep .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @shopify/address 
SYNC missed versions from official npm registry.

@shopify/address

Build Status License: MIT npm version npm bundle size (minified + gzip)

Address utilities for loading and ordering addresses.

Installation

$ yarn add @shopify/address

API Reference

  • country field in Address is expected to be of format ISO 3166-1 alpha-2, eg. CA / FR / JP

constructor(private locale: string)

Instantiate the AddressFormatter by passing it a locale.

updateLocale(locale: string)

Update the locale of the formatter. Following requests will be in the given locale.

async .getCountry(countryCode: string): Promise<Country>

Loads and return data about a given country in the locale used for instanciation. Country and province names are localized. Province names are ordered based on the locale

async .getCountries(): Promise<Country[]>

Loads and return data about a all countries in the given locale. Countries are ordered alphabetically based on the locale. Zones are also ordered based on the locale.

async .getOrderedFields(countryCode): FieldName[][]

Returns how to order address fields.

Eg.:

[
  ['firstName', 'lastName'],
  ['company'],
  ['address1'],
  ['address2'],
  ['city'],
  ['country', 'province', 'zip'],
  ['phone'],
];

async .format(address: Address): string[]

Given an address, returns the address ordered for multiline show. Eg.

['Shopify', 'Lindenstraße 9-14', '10969 Berlin', 'Germany'];

Example Usage

Show an address:

import AddressFormatter from '@shopify/address';

const address = {
  company: 'Shopify',
  firstName: '恵子',
  lastName: '田中',
  address1: '八重洲1-5-3',
  address2: '',
  city: '目黒区',
  province: 'JP-13',
  zip: '100-8994',
  country: 'JP',
  phone: '',
};

const addressFormatter = new AddressFormatter('ja');
await addressFormatter.format(address);
/* =>
  日本
  〒100-8994東京都目黒区八重洲1-5-3
  Shopify
  田中恵子様
 */

await addressFormatter.getOrderedFields('CA');
/* =>
  [
    ['firstName', 'lastName'],
    ['company'],
    ['address1'],
    ['address2'],
    ['city'],
    ['country', 'province', 'zip'],
    ['phone']
  ]
 */

Testing

If your component uses this package and you want to test it with mock API calls you can use the following

import {fetch} from '@shopify/jest-dom-mocks';
import {mockCountryRequests} from '@shopify/address/tests';

beforeEach(mockCountryRequests);
afterEach(fetch.restore);

Note: Only FR / JA and EN are mocked.

Current Tags

  • 2.7.15                                ...           latest (21 days ago)

50 Versions

  • 2.7.15                                ...           21 days ago
  • 2.7.14                                ...           a month ago
  • 2.7.13                                ...           a month ago
  • 2.7.12                                ...           a month ago
  • 2.7.11                                ...           2 months ago
  • 2.7.10                                ...           2 months ago
  • 2.7.9                                ...           2 months ago
  • 2.7.8                                ...           2 months ago
  • 2.7.7                                ...           2 months ago
  • 2.7.6                                ...           3 months ago
  • 2.7.5                                ...           3 months ago
  • 2.7.4                                ...           3 months ago
  • 2.7.3                                ...           3 months ago
  • 2.7.2                                ...           3 months ago
  • 2.7.1                                ...           3 months ago
  • 2.7.0                                ...           4 months ago
  • 2.6.17                                ...           4 months ago
  • 2.6.16                                ...           5 months ago
  • 2.6.15                                ...           6 months ago
  • 2.6.14                                ...           7 months ago
  • 2.6.13                                ...           7 months ago
  • 2.6.12                                ...           7 months ago
  • 2.6.11                                ...           7 months ago
  • 2.6.10                                ...           8 months ago
  • 2.6.9                                ...           8 months ago
  • 2.6.8                                ...           8 months ago
  • 2.6.7                                ...           8 months ago
  • 2.6.6                                ...           8 months ago
  • 2.6.5                                ...           9 months ago
  • 2.6.4                                ...           9 months ago
  • 2.6.3                                ...           9 months ago
  • 2.6.2                                ...           9 months ago
  • 2.6.1                                ...           a year ago
  • 2.6.0                                ...           a year ago
  • 2.5.1                                ...           a year ago
  • 2.5.0                                ...           a year ago
  • 2.4.5                                ...           a year ago
  • 2.4.4                                ...           a year ago
  • 2.4.3                                ...           a year ago
  • 2.4.1                                ...           a year ago
  • 2.4.0                                ...           a year ago
  • 2.3.0                                ...           a year ago
  • 2.2.0                                ...           a year ago
  • 2.1.0                                ...           a year ago
  • 2.0.0                                ...           a year ago
  • 1.1.2                                ...           a year ago
  • 1.1.1                                ...           a year ago
  • 1.1.0                                ...           a year ago
  • 1.0.2                                ...           a year ago
  • 1.0.1                                ...           a year ago
Downloads
Today 0
This Week 50
This Month 51
Last Day 0
Last Week 0
Last Month 93
Dependencies (2)
Dev Dependencies (2)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |