@sprucelabs/schema 32.2.0 → 32.2.1
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.
|
@@ -31,6 +31,11 @@ const COUNTRY_FORMATS = [
|
|
|
31
31
|
},
|
|
32
32
|
];
|
|
33
33
|
const DEFAULT_COUNTRY = (_a = COUNTRY_FORMATS.find((format) => format.code === '1')) !== null && _a !== void 0 ? _a : COUNTRY_FORMATS[0];
|
|
34
|
+
const createAdHocFormat = (code) => ({
|
|
35
|
+
code,
|
|
36
|
+
groupSizes: [],
|
|
37
|
+
groupSeparator: DEFAULT_CODE_SEPARATOR,
|
|
38
|
+
});
|
|
34
39
|
export function isValidNumber(number) {
|
|
35
40
|
var _a;
|
|
36
41
|
if (LETTER_PATTERN.test(number)) {
|
|
@@ -93,6 +98,7 @@ function detectCountryFormat(input) {
|
|
|
93
98
|
if (explicitMatch) {
|
|
94
99
|
return explicitMatch;
|
|
95
100
|
}
|
|
101
|
+
return createAdHocFormat(input.digits);
|
|
96
102
|
}
|
|
97
103
|
const detected = COUNTRY_FORMATS.find((format) => format.detect ? format.detect(input) : false);
|
|
98
104
|
return detected !== null && detected !== void 0 ? detected : DEFAULT_COUNTRY;
|
|
@@ -35,6 +35,11 @@ const COUNTRY_FORMATS = [
|
|
|
35
35
|
},
|
|
36
36
|
];
|
|
37
37
|
const DEFAULT_COUNTRY = COUNTRY_FORMATS.find((format) => format.code === '1') ?? COUNTRY_FORMATS[0];
|
|
38
|
+
const createAdHocFormat = (code) => ({
|
|
39
|
+
code,
|
|
40
|
+
groupSizes: [],
|
|
41
|
+
groupSeparator: DEFAULT_CODE_SEPARATOR,
|
|
42
|
+
});
|
|
38
43
|
function isValidNumber(number) {
|
|
39
44
|
if (LETTER_PATTERN.test(number)) {
|
|
40
45
|
return false;
|
|
@@ -95,6 +100,7 @@ function detectCountryFormat(input) {
|
|
|
95
100
|
if (explicitMatch) {
|
|
96
101
|
return explicitMatch;
|
|
97
102
|
}
|
|
103
|
+
return createAdHocFormat(input.digits);
|
|
98
104
|
}
|
|
99
105
|
const detected = COUNTRY_FORMATS.find((format) => format.detect ? format.detect(input) : false);
|
|
100
106
|
return detected ?? DEFAULT_COUNTRY;
|