@osimatic/helpers-js 1.5.0 → 1.5.2
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/contact_details.js +4 -3
- package/open_street_map.js +2 -0
- package/package.json +1 -1
- package/tests/contact_details.test.js +31 -0
package/contact_details.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
const libphonenumber = require('libphonenumber-js/max');
|
|
3
|
+
const intlTelInputLib = require('intl-tel-input/intlTelInputWithUtils');
|
|
3
4
|
const { Country } = require('./location');
|
|
4
5
|
|
|
5
6
|
class PersonName {
|
|
@@ -173,7 +174,7 @@ class TelephoneNumber {
|
|
|
173
174
|
TelephoneNumber.localCountryCode = typeof TelephoneNumber.localCountryCode != 'undefined' ? TelephoneNumber.localCountryCode : null;
|
|
174
175
|
TelephoneNumber.intlTelInputUtilsPath = typeof TelephoneNumber.intlTelInputUtilsPath != 'undefined' ? TelephoneNumber.intlTelInputUtilsPath : null;
|
|
175
176
|
|
|
176
|
-
return
|
|
177
|
+
return intlTelInputLib(input[0], {
|
|
177
178
|
initialCountry: null != TelephoneNumber.localCountryCode ? TelephoneNumber.localCountryCode.toLowerCase() : null, // depuis version 19.x, le code pays doit être en minuscule
|
|
178
179
|
placeholderNumberType: placeholderNumberType || 'FIXED_LINE_OR_MOBILE',
|
|
179
180
|
utilsScript: TelephoneNumber.intlTelInputUtilsPath
|
|
@@ -181,11 +182,11 @@ class TelephoneNumber {
|
|
|
181
182
|
}
|
|
182
183
|
|
|
183
184
|
static getIntlTelInputInstance(input) {
|
|
184
|
-
return
|
|
185
|
+
return intlTelInputLib.getInstance(input[0]);
|
|
185
186
|
}
|
|
186
187
|
|
|
187
188
|
static getEnteredNumberInInternationalFormat(intlTelInput) {
|
|
188
|
-
return intlTelInput.getNumber(
|
|
189
|
+
return intlTelInput.getNumber(intlTelInputLib.utils.numberFormat.E164);
|
|
189
190
|
}
|
|
190
191
|
|
|
191
192
|
static formatNumberFromIntlTelInput(intlTelInput) {
|
package/open_street_map.js
CHANGED
package/package.json
CHANGED
|
@@ -342,4 +342,35 @@ describe('TelephoneNumber', () => {
|
|
|
342
342
|
expect(result).toContain('06 12 34 56 78');
|
|
343
343
|
});
|
|
344
344
|
});
|
|
345
|
+
|
|
346
|
+
describe('getEnteredNumberInInternationalFormat', () => {
|
|
347
|
+
test('should return number in E164 format', () => {
|
|
348
|
+
const iti = { getNumber: jest.fn(() => '+33612345678') };
|
|
349
|
+
const result = TelephoneNumber.getEnteredNumberInInternationalFormat(iti);
|
|
350
|
+
expect(result).toBe('+33612345678');
|
|
351
|
+
});
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
describe('formatNumberFromIntlTelInput', () => {
|
|
355
|
+
test('should return number as-is when it starts with +', () => {
|
|
356
|
+
const iti = { getNumber: jest.fn(() => '+33612345678') };
|
|
357
|
+
const result = TelephoneNumber.formatNumberFromIntlTelInput(iti);
|
|
358
|
+
expect(result).toBe('+33612345678');
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
test('should prepend + and dial code when number has no +', () => {
|
|
362
|
+
const iti = {
|
|
363
|
+
getNumber: jest.fn(() => '0612345678'),
|
|
364
|
+
getSelectedCountryData: jest.fn(() => ({ dialCode: '33' })),
|
|
365
|
+
};
|
|
366
|
+
const result = TelephoneNumber.formatNumberFromIntlTelInput(iti);
|
|
367
|
+
expect(result).toBe('+330612345678');
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
test('should return empty string when number is empty', () => {
|
|
371
|
+
const iti = { getNumber: jest.fn(() => '') };
|
|
372
|
+
const result = TelephoneNumber.formatNumberFromIntlTelInput(iti);
|
|
373
|
+
expect(result).toBe('');
|
|
374
|
+
});
|
|
375
|
+
});
|
|
345
376
|
});
|