monkey-style-guide-v2 0.0.66 → 0.0.67
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.
|
@@ -16,8 +16,9 @@ import { HttpClient } from '@angular/common/http';
|
|
|
16
16
|
import { format, parseISO, addYears, subYears, subMonths, addMonths, getMonth, getYear, startOfWeek, startOfMonth, endOfWeek, endOfMonth, isSameMonth, isBefore, isAfter, isToday, addDays, isWithinInterval, subDays } from 'date-fns';
|
|
17
17
|
import { coerceBooleanProperty } from '@angular/cdk/coercion';
|
|
18
18
|
import { getSupportedInputTypes } from '@angular/cdk/platform';
|
|
19
|
-
import parsePhoneNumberFromString, { getCountries, getCountryCallingCode, getExampleNumber, AsYouType
|
|
19
|
+
import parsePhoneNumberFromString, { getCountries, getCountryCallingCode, getExampleNumber, AsYouType } from 'libphonenumber-js';
|
|
20
20
|
import examples from 'libphonenumber-js/examples.mobile.json';
|
|
21
|
+
import { isValidPhoneNumber } from 'libphonenumber-js/max';
|
|
21
22
|
import { hasModifierKey } from '@angular/cdk/keycodes';
|
|
22
23
|
|
|
23
24
|
const counters = {};
|
|
@@ -5649,7 +5650,7 @@ class MonkeyInputPhoneComponent {
|
|
|
5649
5650
|
getCountryByCallingCode(code) {
|
|
5650
5651
|
const cleanCode = code.replace('+', '');
|
|
5651
5652
|
return (getCountries().find((country) => {
|
|
5652
|
-
return
|
|
5653
|
+
return country === cleanCode;
|
|
5653
5654
|
}) || null);
|
|
5654
5655
|
}
|
|
5655
5656
|
isoToFlagEmoji(isoCode) {
|
|
@@ -5671,18 +5672,21 @@ class MonkeyInputPhoneComponent {
|
|
|
5671
5672
|
return this.selectedCallingCode;
|
|
5672
5673
|
}
|
|
5673
5674
|
performValue(value) {
|
|
5674
|
-
|
|
5675
|
+
const countryCode = `+${getCountryCallingCode(this.selectedCallingCode)}`;
|
|
5676
|
+
this._value = `${countryCode}${value}`;
|
|
5675
5677
|
this._onChange(this._value);
|
|
5676
5678
|
this._onTouched(this._value);
|
|
5677
5679
|
}
|
|
5678
5680
|
validateValue() {
|
|
5679
5681
|
const { phoneValid } = this;
|
|
5680
5682
|
if (!phoneValid) {
|
|
5681
|
-
const countryCode = this.
|
|
5683
|
+
const countryCode = this.selectedCallingCode;
|
|
5682
5684
|
const example = getExampleNumber(countryCode, examples);
|
|
5685
|
+
const formatter = new AsYouType(countryCode);
|
|
5686
|
+
const phoneAllowed = formatter.input(example.nationalNumber);
|
|
5683
5687
|
this.ngControl?.control?.setErrors({
|
|
5684
5688
|
phone: true,
|
|
5685
|
-
phoneAllowed
|
|
5689
|
+
phoneAllowed
|
|
5686
5690
|
});
|
|
5687
5691
|
}
|
|
5688
5692
|
}
|
|
@@ -5698,18 +5702,19 @@ class MonkeyInputPhoneComponent {
|
|
|
5698
5702
|
if (isCountryChanged && detectedCallingCode) {
|
|
5699
5703
|
this.selectedCallingCode = detectedCallingCode;
|
|
5700
5704
|
}
|
|
5701
|
-
const countryCode =
|
|
5705
|
+
const countryCode = `+${getCountryCallingCode(this.selectedCallingCode)}`;
|
|
5702
5706
|
if (!countryCode) {
|
|
5703
5707
|
this.phoneFormatted = value;
|
|
5704
5708
|
this.phoneValid = false;
|
|
5705
5709
|
this.validateValue();
|
|
5706
5710
|
return;
|
|
5707
5711
|
}
|
|
5708
|
-
|
|
5709
|
-
|
|
5712
|
+
let nationalPart = value.replace(this.selectedCallingCode, '').replace(/[^\d+]/g, '');
|
|
5713
|
+
nationalPart = nationalPart.replace(countryCode, '');
|
|
5714
|
+
const formatter = new AsYouType(this.selectedCallingCode);
|
|
5710
5715
|
this.phoneFormatted = formatter.input(nationalPart);
|
|
5711
5716
|
this.performValue(nationalPart);
|
|
5712
|
-
this.phoneValid = isValidPhoneNumber(nationalPart,
|
|
5717
|
+
this.phoneValid = isValidPhoneNumber(nationalPart, this.selectedCallingCode);
|
|
5713
5718
|
this.validateValue();
|
|
5714
5719
|
}
|
|
5715
5720
|
ngAfterContentInit() { }
|