@osimatic/helpers-js 1.5.26 → 1.5.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/location.js +3 -2
- package/package.json +1 -1
- package/tests/location.test.js +30 -0
package/location.js
CHANGED
|
@@ -329,7 +329,7 @@ class PostalAddress {
|
|
|
329
329
|
return autocomplete;
|
|
330
330
|
}
|
|
331
331
|
|
|
332
|
-
static format(addressData, separator='<br/>') {
|
|
332
|
+
static format(addressData, separator='<br/>', locale=null) {
|
|
333
333
|
function empty(value) {
|
|
334
334
|
return typeof value == 'undefined' || value == null || value === '';
|
|
335
335
|
}
|
|
@@ -365,7 +365,8 @@ class PostalAddress {
|
|
|
365
365
|
addressDataForPluging['locality'] = addressData['stateDistrict'];
|
|
366
366
|
}
|
|
367
367
|
|
|
368
|
-
|
|
368
|
+
const afLocale = locale || (addressDataForPluging['countryCode'] ? `und-${addressDataForPluging['countryCode']}` : null);
|
|
369
|
+
let af = new AddressFmt(afLocale ? {locale: afLocale} : {});
|
|
369
370
|
let formattedAddress = af.format(new Address(addressDataForPluging));
|
|
370
371
|
return formattedAddress.replace(/\n+/g, separator);
|
|
371
372
|
}
|
package/package.json
CHANGED
package/tests/location.test.js
CHANGED
|
@@ -706,5 +706,35 @@ describe('PostalAddress', () => {
|
|
|
706
706
|
expect(result).toContain('Mountain View');
|
|
707
707
|
expect(result).toContain('94043');
|
|
708
708
|
});
|
|
709
|
+
|
|
710
|
+
test('should place postalCode before locality for FR (countryCode)', () => {
|
|
711
|
+
const result = PostalAddress.format({
|
|
712
|
+
streetAddress: '10 Rue de la Paix',
|
|
713
|
+
postalCode: '75001',
|
|
714
|
+
locality: 'Paris',
|
|
715
|
+
countryCode: 'FR',
|
|
716
|
+
}, '\n');
|
|
717
|
+
expect(result.indexOf('75001')).toBeLessThan(result.indexOf('Paris'));
|
|
718
|
+
});
|
|
719
|
+
|
|
720
|
+
test('should place postalCode before locality for FR (locale parameter)', () => {
|
|
721
|
+
const result = PostalAddress.format({
|
|
722
|
+
streetAddress: '10 Rue de la Paix',
|
|
723
|
+
postalCode: '75001',
|
|
724
|
+
locality: 'Paris',
|
|
725
|
+
}, '\n', 'fr-FR');
|
|
726
|
+
expect(result.indexOf('75001')).toBeLessThan(result.indexOf('Paris'));
|
|
727
|
+
});
|
|
728
|
+
|
|
729
|
+
test('should place postalCode after locality for US', () => {
|
|
730
|
+
const result = PostalAddress.format({
|
|
731
|
+
streetAddress: '1600 Amphitheatre Pkwy',
|
|
732
|
+
postalCode: '94043',
|
|
733
|
+
locality: 'Mountain View',
|
|
734
|
+
state: 'CA',
|
|
735
|
+
countryCode: 'US',
|
|
736
|
+
}, '\n');
|
|
737
|
+
expect(result.indexOf('94043')).toBeGreaterThan(result.indexOf('Mountain View'));
|
|
738
|
+
});
|
|
709
739
|
});
|
|
710
740
|
});
|