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

@shopify/address

Package Overview
Dependencies
Maintainers
24
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 4.2.0 to 4.2.1

20

build/cjs/AddressFormatter.js

@@ -17,3 +17,2 @@ 'use strict';

}
constructor(locale) {

@@ -23,7 +22,5 @@ this.locale = locale;

}
updateLocale(locale) {
this.locale = locale;
}
async getCountry(countryCode, {

@@ -38,5 +35,5 @@ includeHiddenZones = false

}
async getCountries({
includeHiddenZones = false
includeHiddenZones = false,
signupOnly = false
} = {}) {

@@ -47,3 +44,4 @@ const cacheKey = this.cacheKey(this.locale, includeHiddenZones);

const countries = await loader.loadCountries(this.locale, {
includeHiddenZones
includeHiddenZones,
signupOnly
});

@@ -53,3 +51,2 @@ ORDERED_COUNTRIES_CACHE.set(cacheKey, countries);

}
async getZoneName(countryCode, zoneCode) {

@@ -61,2 +58,3 @@ const country = await this.getCountry(countryCode);

}
/* Returns the address ordered in an array based based on the country code

@@ -74,4 +72,2 @@ * Eg.:

*/
async format(address) {

@@ -81,2 +77,3 @@ const country = await this.getCountry(address.country);

}
/* Returns an array that shows how to order fields based on the country code

@@ -94,4 +91,2 @@ * Eg.:

*/
async getOrderedFields(countryCode) {

@@ -101,3 +96,2 @@ const country = await this.getCountry(countryCode);

}
cacheKey(locale, includeHiddenZones) {

@@ -107,3 +101,2 @@ /* Cache list of countries per locale, both with and without hidden zones included */

}
loadCountryFromCache(countryCode, includeHiddenZones) {

@@ -116,5 +109,4 @@ const cachedCountries = ORDERED_COUNTRIES_CACHE.get(this.cacheKey(this.locale, includeHiddenZones));

}
}
exports["default"] = AddressFormatter;

@@ -10,2 +10,3 @@ 'use strict';

const DEFAULT_SHOW_LAYOUT = '{lastName} {firstName}_{company}_{address1} {address2}_{city} {province} {zip}_{country}_{phone}';
/**

@@ -20,3 +21,2 @@ * When it's time to render any address, use this function so that it's properly

*/
function formatAddress(address, country) {

@@ -26,2 +26,3 @@ const layout = country.formatting.show || DEFAULT_SHOW_LAYOUT;

}
/**

@@ -43,3 +44,2 @@ * In an edit form, this function can be used to properly order all the input

*/
function buildOrderedFields(country) {

@@ -49,7 +49,5 @@ const format = country ? country.formatting.edit : DEFAULT_FORM_LAYOUT;

const result = lineTemplate.match(utilities.FIELD_REGEXP);
if (!result) {
return [];
}
return result.map(field => utilities.FIELDS_MAPPING[field]);

@@ -56,0 +54,0 @@ });

@@ -6,4 +6,4 @@ 'use strict';

const query = `
query countries($locale: SupportedLocale!) {
countries(locale: $locale) {
query countries($locale: SupportedLocale!, $signupOnly: Boolean) {
countries(locale: $locale, signupOnly: $signupOnly) {
name

@@ -10,0 +10,0 @@ code

@@ -9,3 +9,4 @@ 'use strict';

const loadCountries = memoizeAsync(async (locale, {
includeHiddenZones = false
includeHiddenZones = false,
signupOnly = false
} = {}) => {

@@ -20,3 +21,4 @@ const response = await fetch(addressConsts.GRAPHQL_ENDPOINT, {

locale: locale.replace(/-/, '_').toUpperCase(),
includeHiddenZones
includeHiddenZones,
signupOnly
}

@@ -26,7 +28,5 @@ })

const countries = await response.json();
if (!('data' in countries) && 'errors' in countries) {
throw new CountryLoaderError(countries);
}
return countries.data.countries;

@@ -51,7 +51,5 @@ });

const country = await response.json();
if (!('data' in country) && 'errors' in country) {
throw new CountryLoaderError(country);
}
return country.data.country;

@@ -64,5 +62,3 @@ });

}
}
function memoizeAsync(asyncFunction) {

@@ -72,7 +68,5 @@ const cache = {};

const stringifiedArgs = JSON.stringify(args);
if (!cache[stringifiedArgs]) {
cache[stringifiedArgs] = asyncFunction.apply(this, args);
}
return cache[stringifiedArgs];

@@ -79,0 +73,0 @@ };

@@ -9,3 +9,2 @@ 'use strict';

/* eslint-disable @typescript-eslint/naming-convention */
const FIELDS_MAPPING = {

@@ -28,19 +27,14 @@ '{firstName}': addressConsts.FieldName.FirstName,

*/
function renderLineTemplate(country, template, address) {
const result = template.match(FIELD_REGEXP);
let line = template;
if (!result) {
return '';
}
let lineIsEmpty = true;
result.forEach(key => {
const addressKey = key.replace('{', '').replace('}', '');
if (address[addressKey]) {
lineIsEmpty = false;
}
switch (addressKey) {

@@ -50,7 +44,5 @@ case addressConsts.FieldName.Country:

break;
case addressConsts.FieldName.Zone:
line = line.replace(`{${addressConsts.FieldName.Zone}}`, address.province ? getZone(country.zones, address.province).name : '');
break;
default:

@@ -61,3 +53,2 @@ line = line.replace(key, address[addressKey] || '');

});
if (lineIsEmpty) {

@@ -69,3 +60,2 @@ return '';

}
function getZone(zones, zoneCode) {

@@ -72,0 +62,0 @@ return zones.find(zone => zone.code === zoneCode) || {

@@ -14,4 +14,5 @@ import type { Address, FieldName, Country } from '@shopify/address-consts';

}): Promise<Country>;
getCountries({ includeHiddenZones }?: {
getCountries({ includeHiddenZones, signupOnly, }?: {
includeHiddenZones?: boolean | undefined;
signupOnly?: boolean | undefined;
}): Promise<Country[]>;

@@ -18,0 +19,0 @@ getZoneName(countryCode: string, zoneCode: string): Promise<string | undefined>;

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

declare const query = "\nquery countries($locale: SupportedLocale!) {\n countries(locale: $locale) {\n name\n code\n continent\n phoneNumberPrefix\n autocompletionField\n provinceKey\n labels {\n address1\n address2\n city\n company\n country\n firstName\n lastName\n phone\n postalCode\n zone\n }\n optionalLabels {\n address2\n }\n formatting {\n edit\n show\n }\n zones {\n name\n code\n }\n }\n}\n\nquery country($countryCode: SupportedCountry!, $locale: SupportedLocale!) {\n country(countryCode: $countryCode, locale: $locale) {\n name\n code\n continent\n phoneNumberPrefix\n autocompletionField\n provinceKey\n labels {\n address1\n address2\n city\n company\n country\n firstName\n lastName\n phone\n postalCode\n zone\n }\n optionalLabels {\n address2\n }\n formatting {\n edit\n show\n }\n zones {\n name\n code\n }\n }\n}\n";
declare const query = "\nquery countries($locale: SupportedLocale!, $signupOnly: Boolean) {\n countries(locale: $locale, signupOnly: $signupOnly) {\n name\n code\n continent\n phoneNumberPrefix\n autocompletionField\n provinceKey\n labels {\n address1\n address2\n city\n company\n country\n firstName\n lastName\n phone\n postalCode\n zone\n }\n optionalLabels {\n address2\n }\n formatting {\n edit\n show\n }\n zones {\n name\n code\n }\n }\n}\n\nquery country($countryCode: SupportedCountry!, $locale: SupportedLocale!) {\n country(countryCode: $countryCode, locale: $locale) {\n name\n code\n continent\n phoneNumberPrefix\n autocompletionField\n provinceKey\n labels {\n address1\n address2\n city\n company\n country\n firstName\n lastName\n phone\n postalCode\n zone\n }\n optionalLabels {\n address2\n }\n formatting {\n edit\n show\n }\n zones {\n name\n code\n }\n }\n}\n";
export default query;
//# sourceMappingURL=graphqlQuery.d.ts.map
import type { Country, ResponseError } from '@shopify/address-consts';
export declare const loadCountries: (locale: string, options?: {
includeHiddenZones?: boolean;
signupOnly?: boolean;
}) => Promise<Country[]>;

@@ -5,0 +6,0 @@ export declare const loadCountry: (locale: string, countryCode: string, options?: {

{
"name": "@shopify/address",
"version": "4.2.0",
"version": "4.2.1",
"license": "MIT",

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

"devDependencies": {
"@shopify/address-mocks": "^3.2.2",
"@shopify/jest-dom-mocks": "^5.0.0"
"@shopify/address-mocks": "^3.2.3",
"@shopify/jest-dom-mocks": "^5.0.1"
},

@@ -30,0 +30,0 @@ "sideEffects": false,

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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