@osimatic/helpers-js 1.5.1 → 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.
@@ -1,6 +1,6 @@
1
1
 
2
2
  const libphonenumber = require('libphonenumber-js/max');
3
- const intlTelInput = require('intl-tel-input');
3
+ const intlTelInputLib = require('intl-tel-input/intlTelInputWithUtils');
4
4
  const { Country } = require('./location');
5
5
 
6
6
  class PersonName {
@@ -174,7 +174,7 @@ class TelephoneNumber {
174
174
  TelephoneNumber.localCountryCode = typeof TelephoneNumber.localCountryCode != 'undefined' ? TelephoneNumber.localCountryCode : null;
175
175
  TelephoneNumber.intlTelInputUtilsPath = typeof TelephoneNumber.intlTelInputUtilsPath != 'undefined' ? TelephoneNumber.intlTelInputUtilsPath : null;
176
176
 
177
- return intlTelInput(input[0], {
177
+ return intlTelInputLib(input[0], {
178
178
  initialCountry: null != TelephoneNumber.localCountryCode ? TelephoneNumber.localCountryCode.toLowerCase() : null, // depuis version 19.x, le code pays doit être en minuscule
179
179
  placeholderNumberType: placeholderNumberType || 'FIXED_LINE_OR_MOBILE',
180
180
  utilsScript: TelephoneNumber.intlTelInputUtilsPath
@@ -182,11 +182,11 @@ class TelephoneNumber {
182
182
  }
183
183
 
184
184
  static getIntlTelInputInstance(input) {
185
- return intlTelInput.getInstance(input[0]);
185
+ return intlTelInputLib.getInstance(input[0]);
186
186
  }
187
187
 
188
188
  static getEnteredNumberInInternationalFormat(intlTelInput) {
189
- return intlTelInput.getNumber(intlTelInput.utils.numberFormat.E164);
189
+ return intlTelInput.getNumber(intlTelInputLib.utils.numberFormat.E164);
190
190
  }
191
191
 
192
192
  static formatNumberFromIntlTelInput(intlTelInput) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.5.1",
3
+ "version": "1.5.2",
4
4
  "main": "main.js",
5
5
  "scripts": {
6
6
  "test": "jest",
@@ -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
  });