Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@shopify/address

Package Overview
Dependencies
Maintainers
10
Versions
128
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@shopify/address - npm Package Compare versions

Comparing version 2.1.0 to 2.2.0

13

CHANGELOG.md

@@ -11,2 +11,12 @@ # Changelog

## 2.2.0 - 2018-10-01
- Replaced `SupportedLocale` type by string. Default to english, if locale does not exist. ([#](https://github.com/Shopify/quilt/pull/xxx))
## 2.1.0 - 2018-09-28
- Created `SupportedLocale` type ([#311](https://github.com/Shopify/quilt/pull/311))
- Created `SupportedCountry` type ([#311](https://github.com/Shopify/quilt/pull/311))
- `AddressFormatter` now accepts `SupportedLocale` as locale instead of `string` ([#311](https://github.com/Shopify/quilt/pull/311))
## 2.0.0 - 2018-09-19

@@ -21,4 +31,1 @@

- Changed `format` key to `formatting` in Country type ([#274](https://github.com/Shopify/quilt/pull/274))
- Created `SupportedLocale` type ([#311](https://github.com/Shopify/quilt/pull/311))
- Created `SupportedCountry` type ([#311](https://github.com/Shopify/quilt/pull/311))
- `AddressFormatter` now accepts `SupportedLocale` as locale instead of `string` ([#311](https://github.com/Shopify/quilt/pull/311))

@@ -1,6 +0,6 @@

import { Address, FieldName, Country, SupportedLocale, SupportedCountry } from './types';
import { Address, FieldName, Country, SupportedCountry } from './types';
export default class AddressFormatter {
private locale;
constructor(locale: SupportedLocale);
updateLocale(locale: SupportedLocale): void;
constructor(locale: string);
updateLocale(locale: string): void;
getCountry(countryCode: SupportedCountry): Promise<Country>;

@@ -7,0 +7,0 @@ getCountries(): Promise<Country[]>;

@@ -1,3 +0,3 @@

import { Country, SupportedCountry, SupportedLocale } from './types';
export declare function loadCountries(locale: SupportedLocale): Promise<Country[]>;
export declare function loadCountry(locale: SupportedLocale, countryCode: SupportedCountry): Promise<Country>;
import { Country, SupportedCountry } from './types';
export declare function loadCountries(locale: string): Promise<Country[]>;
export declare function loadCountry(locale: string, countryCode: SupportedCountry): Promise<Country>;

@@ -142,5 +142,23 @@ "use strict";

}(Error));
var DEFAULT_LOCALE = 'EN';
var SUPPORTED_LOCALES = [
'DA',
'DE',
'EN',
'ES',
'FR',
'IT',
'JA',
'NL',
'PT',
'PT_BR',
];
function toSupportedLocale(locale) {
var supportedLocale = locale.replace(/-/, '_').toUpperCase();
return supportedLocale;
if (SUPPORTED_LOCALES.includes(supportedLocale)) {
return supportedLocale;
}
else {
return DEFAULT_LOCALE;
}
}

@@ -68,3 +68,2 @@ export declare enum FieldName {

}
export declare type SupportedLocale = 'da' | 'de' | 'en' | 'es' | 'fr' | 'it' | 'ja' | 'nl' | 'pt' | 'pt-BR';
export declare type SupportedCountry = 'AD' | 'AE' | 'AF' | 'AG' | 'AI' | 'AL' | 'AM' | 'AN' | 'AO' | 'AR' | 'AT' | 'AU' | 'AW' | 'AX' | 'AZ' | 'BA' | 'BB' | 'BD' | 'BE' | 'BF' | 'BG' | 'BH' | 'BI' | 'BJ' | 'BL' | 'BM' | 'BN' | 'BO' | 'BQ' | 'BR' | 'BS' | 'BT' | 'BV' | 'BW' | 'BY' | 'BZ' | 'CA' | 'CC' | 'CD' | 'CF' | 'CG' | 'CH' | 'CI' | 'CK' | 'CL' | 'CM' | 'CN' | 'CO' | 'CR' | 'CU' | 'CV' | 'CW' | 'CX' | 'CY' | 'CZ' | 'DE' | 'DJ' | 'DK' | 'DM' | 'DO' | 'DZ' | 'EC' | 'EE' | 'EG' | 'EH' | 'ER' | 'ES' | 'ET' | 'FI' | 'FJ' | 'FK' | 'FO' | 'FR' | 'GA' | 'GB' | 'GD' | 'GE' | 'GF' | 'GG' | 'GH' | 'GI' | 'GL' | 'GM' | 'GN' | 'GP' | 'GQ' | 'GR' | 'GS' | 'GT' | 'GW' | 'GY' | 'HK' | 'HM' | 'HN' | 'HR' | 'HT' | 'HU' | 'ID' | 'IE' | 'IL' | 'IM' | 'IN' | 'IO' | 'IQ' | 'IR' | 'IS' | 'IT' | 'JE' | 'JM' | 'JO' | 'JP' | 'KE' | 'KG' | 'KH' | 'KI' | 'KM' | 'KN' | 'KP' | 'KR' | 'KW' | 'KY' | 'KZ' | 'LA' | 'LB' | 'LC' | 'LI' | 'LK' | 'LR' | 'LS' | 'LT' | 'LU' | 'LV' | 'LY' | 'MA' | 'MC' | 'MD' | 'ME' | 'MF' | 'MG' | 'MK' | 'ML' | 'MM' | 'MN' | 'MO' | 'MQ' | 'MR' | 'MS' | 'MT' | 'MU' | 'MV' | 'MW' | 'MX' | 'MY' | 'MZ' | 'NA' | 'NC' | 'NE' | 'NF' | 'NG' | 'NI' | 'NL' | 'NO' | 'NP' | 'NR' | 'NU' | 'NZ' | 'OM' | 'PA' | 'PE' | 'PF' | 'PG' | 'PH' | 'PK' | 'PL' | 'PM' | 'PN' | 'PS' | 'PT' | 'PY' | 'QA' | 'RE' | 'RO' | 'RS' | 'RU' | 'RW' | 'SA' | 'SB' | 'SC' | 'SD' | 'SE' | 'SG' | 'SH' | 'SI' | 'SJ' | 'SK' | 'SL' | 'SM' | 'SN' | 'SO' | 'SR' | 'SS' | 'ST' | 'SV' | 'SX' | 'SY' | 'SZ' | 'TC' | 'TD' | 'TF' | 'TG' | 'TH' | 'TJ' | 'TK' | 'TL' | 'TM' | 'TN' | 'TO' | 'TR' | 'TT' | 'TV' | 'TW' | 'TZ' | 'UA' | 'UG' | 'UM' | 'US' | 'UY' | 'UZ' | 'VA' | 'VC' | 'VE' | 'VG' | 'VN' | 'VU' | 'WF' | 'WS' | 'XK' | 'YE' | 'YT' | 'ZA' | 'ZM' | 'ZW';
{
"name": "@shopify/address",
"version": "2.1.0",
"version": "2.2.0",
"license": "MIT",

@@ -26,3 +26,3 @@ "description": "Address utilities for formatting addresses.",

"devDependencies": {
"@shopify/jest-dom-mocks": "^2.0.9",
"@shopify/jest-dom-mocks": "^2.1.0",
"typescript": "~3.0.1"

@@ -29,0 +29,0 @@ },

@@ -19,7 +19,7 @@ # `@shopify/address`

#### `constructor(private locale: SupportedLocale)`
#### `constructor(private locale: string)`
Instantiate the AddressFormatter by passing it a locale.
#### `updateLocale(locale: SupportedLocale)`
#### `updateLocale(locale: string)`

@@ -26,0 +26,0 @@ Update the locale of the formatter. Following requests will be in the given locale.

@@ -1,8 +0,2 @@

import {
Address,
FieldName,
Country,
SupportedLocale,
SupportedCountry,
} from './types';
import {Address, FieldName, Country, SupportedCountry} from './types';
import {renderLineTemplate, FIELDS_MAPPING} from './utilities';

@@ -29,3 +23,3 @@ import {loadCountry, loadCountries} from './loader';

export default class AddressFormatter {
constructor(private locale: SupportedLocale) {
constructor(private locale: string) {
this.locale = locale;

@@ -35,3 +29,3 @@ COUNTRIES_CACHE[this.locale] = {};

updateLocale(locale: SupportedLocale) {
updateLocale(locale: string) {
this.locale = locale;

@@ -38,0 +32,0 @@ COUNTRIES_CACHE[this.locale] = {};

@@ -7,3 +7,2 @@ import {

SupportedCountry,
SupportedLocale,
} from './types';

@@ -23,5 +22,3 @@ import query from './graphqlQuery';

export async function loadCountries(
locale: SupportedLocale,
): Promise<Country[]> {
export async function loadCountries(locale: string): Promise<Country[]> {
const response = await fetch(GRAPHQL_ENDPOINT, {

@@ -49,3 +46,3 @@ method: 'POST',

export async function loadCountry(
locale: SupportedLocale,
locale: string,
countryCode: SupportedCountry,

@@ -80,6 +77,24 @@ ): Promise<Country> {

function toSupportedLocale(locale: SupportedLocale) {
const DEFAULT_LOCALE = 'EN';
const SUPPORTED_LOCALES = [
'DA',
'DE',
'EN',
'ES',
'FR',
'IT',
'JA',
'NL',
'PT',
'PT_BR',
];
function toSupportedLocale(locale: string) {
const supportedLocale = locale.replace(/-/, '_').toUpperCase();
return supportedLocale;
if (SUPPORTED_LOCALES.includes(supportedLocale)) {
return supportedLocale;
} else {
return DEFAULT_LOCALE;
}
}
import {fetch} from '@shopify/jest-dom-mocks';
import {Address, FieldName, SupportedLocale} from '../types';
import {Address, FieldName} from '../types';
import AddressFormatter from '..';

@@ -144,5 +144,5 @@ import {

it('should not call the API again for the countries if the locale is the same.', async () => {
mockAPICall('countries', countriesEn, 'YY');
mockAPICall('countries', countriesEn, 'PT_BR');
// Bypass the cache by using a non existant locale
const addressFormatter = new AddressFormatter('yy' as SupportedLocale);
const addressFormatter = new AddressFormatter('pt-br');
await addressFormatter.getCountries();

@@ -155,8 +155,8 @@ await addressFormatter.getCountries();

it('should call the API again for the countries if the locale has been updated.', async () => {
mockAPICall('countries', countriesEn, 'ZZ');
mockAPICall('countries', countriesJa, 'XX');
mockAPICall('countries', countriesEn, 'NL');
mockAPICall('countries', countriesJa, 'IT');
const addressFormatter = new AddressFormatter('zz' as SupportedLocale);
const addressFormatter = new AddressFormatter('nl');
await addressFormatter.getCountries();
addressFormatter.updateLocale('xx' as SupportedLocale);
addressFormatter.updateLocale('it');
await addressFormatter.getCountries();

@@ -282,5 +282,5 @@

it('replaces - with _ and returns the locale in uppercase', async () => {
mockAPICall('country', countryJpJa, 'PT_BR');
mockAPICall('country', countryJpJa, 'DE');
const addressFormatter = new AddressFormatter('pt-br' as SupportedLocale);
const addressFormatter = new AddressFormatter('de');
const result = await addressFormatter.getCountry('JP');

@@ -290,2 +290,11 @@

});
it('Returns default locale if locale is not supported', async () => {
mockAPICall('country', countryJpEn, 'EN');
const addressFormatter = new AddressFormatter('xx');
const result = await addressFormatter.getCountry('JP');
expect(result).toEqual(countryJpEn.data.country);
});
});

@@ -81,14 +81,2 @@ export enum FieldName {

export type SupportedLocale =
| 'da'
| 'de'
| 'en'
| 'es'
| 'fr'
| 'it'
| 'ja'
| 'nl'
| 'pt'
| 'pt-BR';
export type SupportedCountry =

@@ -95,0 +83,0 @@ | 'AD'

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc