@vtex/country-forms 1.37.0 → 1.39.0
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/CHANGELOG.md +19 -1
- package/README.md +4 -2
- package/dist/JAM-3WAN6YNT.js +59 -0
- package/dist/JAM-3WAN6YNT.js.map +1 -0
- package/dist/JAM-JPWVRY4N.mjs +57 -0
- package/dist/JAM-JPWVRY4N.mjs.map +1 -0
- package/dist/JAM-UV4LHDIP.js +83 -0
- package/dist/JAM-UV4LHDIP.js.map +1 -0
- package/dist/JAM-WHWZBTS4.mjs +81 -0
- package/dist/JAM-WHWZBTS4.mjs.map +1 -0
- package/dist/KOR-AVV72OSB.js +85 -0
- package/dist/KOR-AVV72OSB.js.map +1 -0
- package/dist/KOR-HKYWPG7R.js +71 -0
- package/dist/KOR-HKYWPG7R.js.map +1 -0
- package/dist/KOR-NFAZQ3XP.mjs +83 -0
- package/dist/KOR-NFAZQ3XP.mjs.map +1 -0
- package/dist/KOR-SA7U5SVU.mjs +69 -0
- package/dist/KOR-SA7U5SVU.mjs.map +1 -0
- package/dist/{ar-SA-SIAKC2NM.mjs → ar-SA-D6LZNTM6.mjs} +11 -3
- package/dist/ar-SA-D6LZNTM6.mjs.map +1 -0
- package/dist/{ar-SA-KEFQDNRY.js → ar-SA-Q2IRKMIT.js} +11 -3
- package/dist/ar-SA-Q2IRKMIT.js.map +1 -0
- package/dist/{bg-BG-QJJ2EICE.mjs → bg-BG-HHMTVL2W.mjs} +11 -3
- package/dist/bg-BG-HHMTVL2W.mjs.map +1 -0
- package/dist/{bg-BG-KJOSTENJ.js → bg-BG-N5ZAKKH3.js} +11 -3
- package/dist/bg-BG-N5ZAKKH3.js.map +1 -0
- package/dist/{ca-ES-BLI4ZY52.mjs → ca-ES-B27U6AKI.mjs} +11 -3
- package/dist/ca-ES-B27U6AKI.mjs.map +1 -0
- package/dist/{ca-ES-6RJHO7CW.js → ca-ES-MQN2HJII.js} +11 -3
- package/dist/ca-ES-MQN2HJII.js.map +1 -0
- package/dist/chunk-2WAA326W.mjs +362 -0
- package/dist/chunk-2WAA326W.mjs.map +1 -0
- package/dist/chunk-3QXYV573.mjs +93 -0
- package/dist/chunk-3QXYV573.mjs.map +1 -0
- package/dist/chunk-OEVXHJ5D.js +99 -0
- package/dist/chunk-OEVXHJ5D.js.map +1 -0
- package/dist/chunk-SJKTVAYS.js +72 -0
- package/dist/chunk-SJKTVAYS.js.map +1 -0
- package/dist/chunk-WUEM7DJF.mjs +68 -0
- package/dist/chunk-WUEM7DJF.mjs.map +1 -0
- package/dist/chunk-XFNF6NWH.js +365 -0
- package/dist/chunk-XFNF6NWH.js.map +1 -0
- package/dist/{cs-CZ-NAGOSFSX.mjs → cs-CZ-K6WX7AZG.mjs} +11 -3
- package/dist/cs-CZ-K6WX7AZG.mjs.map +1 -0
- package/dist/{cs-CZ-EYNAD3SB.js → cs-CZ-UNWVQ5D5.js} +11 -3
- package/dist/cs-CZ-UNWVQ5D5.js.map +1 -0
- package/dist/{da-DK-XH2GXFBP.js → da-DK-GX2NTHHA.js} +11 -3
- package/dist/da-DK-GX2NTHHA.js.map +1 -0
- package/dist/{da-DK-34MEUQ6Q.mjs → da-DK-XWZ7VHFB.mjs} +11 -3
- package/dist/da-DK-XWZ7VHFB.mjs.map +1 -0
- package/dist/{de-DE-5V7MNEAO.js → de-DE-BO67HHNW.js} +11 -3
- package/dist/de-DE-BO67HHNW.js.map +1 -0
- package/dist/{de-DE-4OPYYEOU.mjs → de-DE-RWD23GSP.mjs} +11 -3
- package/dist/de-DE-RWD23GSP.mjs.map +1 -0
- package/dist/{el-GR-6XYOVQKI.mjs → el-GR-6DMFZEYV.mjs} +11 -3
- package/dist/el-GR-6DMFZEYV.mjs.map +1 -0
- package/dist/{el-GR-VU2SDIPX.js → el-GR-RFT24UXL.js} +11 -3
- package/dist/el-GR-RFT24UXL.js.map +1 -0
- package/dist/{en-US-X6JS4YBI.mjs → en-US-3CAXT5KG.mjs} +11 -3
- package/dist/en-US-3CAXT5KG.mjs.map +1 -0
- package/dist/{en-US-WG6KKICO.js → en-US-HSKAWNST.js} +11 -3
- package/dist/en-US-HSKAWNST.js.map +1 -0
- package/dist/{es-MX-IQMAFFCN.mjs → es-MX-IVGVND53.mjs} +11 -3
- package/dist/es-MX-IVGVND53.mjs.map +1 -0
- package/dist/{es-MX-7JBED3HS.js → es-MX-PTVX2KLV.js} +11 -3
- package/dist/es-MX-PTVX2KLV.js.map +1 -0
- package/dist/{fi-FI-TQLP2T7Q.mjs → fi-FI-MYOCUZXN.mjs} +11 -3
- package/dist/fi-FI-MYOCUZXN.mjs.map +1 -0
- package/dist/{fi-FI-GTYYU5Z5.js → fi-FI-PZ4EK3MS.js} +11 -3
- package/dist/fi-FI-PZ4EK3MS.js.map +1 -0
- package/dist/{fr-FR-AN2WCBEN.mjs → fr-FR-F5SQAPXT.mjs} +11 -3
- package/dist/fr-FR-F5SQAPXT.mjs.map +1 -0
- package/dist/{fr-FR-FOPEL7NF.js → fr-FR-ZRI26A5X.js} +11 -3
- package/dist/fr-FR-ZRI26A5X.js.map +1 -0
- package/dist/{hu-HU-45RKLNLP.mjs → hu-HU-G2LJ7EVD.mjs} +11 -3
- package/dist/hu-HU-G2LJ7EVD.mjs.map +1 -0
- package/dist/{hu-HU-YIOFTHOC.js → hu-HU-TVO4WG52.js} +11 -3
- package/dist/hu-HU-TVO4WG52.js.map +1 -0
- package/dist/{id-ID-MOIPXPAZ.js → id-ID-ELUOJBLY.js} +11 -3
- package/dist/id-ID-ELUOJBLY.js.map +1 -0
- package/dist/{id-ID-FLY6TBNK.mjs → id-ID-YBPJJ72C.mjs} +11 -3
- package/dist/id-ID-YBPJJ72C.mjs.map +1 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +97 -60
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +97 -60
- package/dist/index.mjs.map +1 -1
- package/dist/{it-IT-LT6OAAUK.js → it-IT-2YIXQNVM.js} +11 -3
- package/dist/it-IT-2YIXQNVM.js.map +1 -0
- package/dist/{it-IT-U7MCPA7I.mjs → it-IT-BIKXUFAN.mjs} +11 -3
- package/dist/it-IT-BIKXUFAN.mjs.map +1 -0
- package/dist/{ja-JP-4F53IGYM.mjs → ja-JP-56WU2TJX.mjs} +11 -3
- package/dist/ja-JP-56WU2TJX.mjs.map +1 -0
- package/dist/{ja-JP-7RPFO3L5.js → ja-JP-DGYQGFYF.js} +11 -3
- package/dist/ja-JP-DGYQGFYF.js.map +1 -0
- package/dist/jam-4ADNRZUH.mjs +16 -0
- package/dist/jam-4ADNRZUH.mjs.map +1 -0
- package/dist/jam-KTJSK4BQ.js +19 -0
- package/dist/jam-KTJSK4BQ.js.map +1 -0
- package/dist/jam-LJAFZW5G.mjs +27 -0
- package/dist/jam-LJAFZW5G.mjs.map +1 -0
- package/dist/jam-W3CXYVA4.js +30 -0
- package/dist/jam-W3CXYVA4.js.map +1 -0
- package/dist/jam-parishes-NIPLZ6LK.js +17 -0
- package/dist/jam-parishes-NIPLZ6LK.js.map +1 -0
- package/dist/jam-parishes-ZPW2VXVE.mjs +4 -0
- package/dist/jam-parishes-ZPW2VXVE.mjs.map +1 -0
- package/dist/{ko-KR-FUSGOUK3.js → ko-KR-CC6LXBPY.js} +11 -3
- package/dist/ko-KR-CC6LXBPY.js.map +1 -0
- package/dist/{ko-KR-JSUDIE4X.mjs → ko-KR-JHA35NGG.mjs} +11 -3
- package/dist/ko-KR-JHA35NGG.mjs.map +1 -0
- package/dist/kor-45SF3WRJ.mjs +16 -0
- package/dist/kor-45SF3WRJ.mjs.map +1 -0
- package/dist/kor-D5PV3R2X.js +19 -0
- package/dist/kor-D5PV3R2X.js.map +1 -0
- package/dist/kor-DMLT3O6E.js +29 -0
- package/dist/kor-DMLT3O6E.js.map +1 -0
- package/dist/kor-RWVBSLYK.mjs +26 -0
- package/dist/kor-RWVBSLYK.mjs.map +1 -0
- package/dist/{nb-NO-M7KPQZF7.mjs → nb-NO-AWMEVGRN.mjs} +11 -3
- package/dist/nb-NO-AWMEVGRN.mjs.map +1 -0
- package/dist/{nb-NO-OQ5QJW3A.js → nb-NO-QC4AQIL5.js} +11 -3
- package/dist/nb-NO-QC4AQIL5.js.map +1 -0
- package/dist/{nl-NL-J2MYZB4R.js → nl-NL-QOUGYLLO.js} +11 -3
- package/dist/nl-NL-QOUGYLLO.js.map +1 -0
- package/dist/{nl-NL-RMCZOMG7.mjs → nl-NL-W2MDW3FU.mjs} +11 -3
- package/dist/nl-NL-W2MDW3FU.mjs.map +1 -0
- package/dist/{pl-PL-H7J2LNNM.mjs → pl-PL-CSACSNQU.mjs} +11 -3
- package/dist/pl-PL-CSACSNQU.mjs.map +1 -0
- package/dist/{pl-PL-FWKCORH2.js → pl-PL-OCFM5ZWW.js} +11 -3
- package/dist/pl-PL-OCFM5ZWW.js.map +1 -0
- package/dist/{pt-BR-BJI34STM.mjs → pt-BR-6HSAFARC.mjs} +11 -3
- package/dist/pt-BR-6HSAFARC.mjs.map +1 -0
- package/dist/{pt-BR-X7AATZM7.js → pt-BR-PMGF55FE.js} +11 -3
- package/dist/pt-BR-PMGF55FE.js.map +1 -0
- package/dist/{pt-PT-IWDVXQUL.mjs → pt-PT-IJ7FRKDI.mjs} +11 -3
- package/dist/pt-PT-IJ7FRKDI.mjs.map +1 -0
- package/dist/{pt-PT-LB5QRWTF.js → pt-PT-OX45OTGX.js} +11 -3
- package/dist/pt-PT-OX45OTGX.js.map +1 -0
- package/dist/{ro-RO-Y2BKFKBW.js → ro-RO-4GSBAIN7.js} +11 -3
- package/dist/ro-RO-4GSBAIN7.js.map +1 -0
- package/dist/{ro-RO-HTULQTIO.mjs → ro-RO-DWURBTJW.mjs} +11 -3
- package/dist/ro-RO-DWURBTJW.mjs.map +1 -0
- package/dist/{ru-RU-GOKLU5AO.mjs → ru-RU-OR5QV433.mjs} +11 -3
- package/dist/ru-RU-OR5QV433.mjs.map +1 -0
- package/dist/{ru-RU-3MGSOVBK.js → ru-RU-VCT77JFK.js} +11 -3
- package/dist/ru-RU-VCT77JFK.js.map +1 -0
- package/dist/{sk-SK-WAFRGJT2.js → sk-SK-ASARP7XS.js} +11 -3
- package/dist/sk-SK-ASARP7XS.js.map +1 -0
- package/dist/{sk-SK-SQEJ2AA6.mjs → sk-SK-GPOXDXEY.mjs} +11 -3
- package/dist/sk-SK-GPOXDXEY.mjs.map +1 -0
- package/dist/{sl-SI-GVPLMZUV.js → sl-SI-QZYFL4ZL.js} +11 -3
- package/dist/sl-SI-QZYFL4ZL.js.map +1 -0
- package/dist/{sl-SI-OU4LJPPU.mjs → sl-SI-SAEAMBFD.mjs} +11 -3
- package/dist/sl-SI-SAEAMBFD.mjs.map +1 -0
- package/dist/{sv-SE-3EUUM37P.mjs → sv-SE-FVTLNXSM.mjs} +11 -3
- package/dist/sv-SE-FVTLNXSM.mjs.map +1 -0
- package/dist/{sv-SE-OXEZ7EB7.js → sv-SE-K2JAKBUB.js} +11 -3
- package/dist/sv-SE-K2JAKBUB.js.map +1 -0
- package/dist/{th-TH-TGWGACM3.js → th-TH-CW357JIJ.js} +11 -3
- package/dist/th-TH-CW357JIJ.js.map +1 -0
- package/dist/{th-TH-X65AHMAW.mjs → th-TH-N3BAAI6Q.mjs} +11 -3
- package/dist/th-TH-N3BAAI6Q.mjs.map +1 -0
- package/dist/{uk-UA-HRZXNCIC.js → uk-UA-JNKABMTQ.js} +11 -3
- package/dist/uk-UA-JNKABMTQ.js.map +1 -0
- package/dist/{uk-UA-F5U6P4YQ.mjs → uk-UA-UCL2CSTG.mjs} +11 -3
- package/dist/uk-UA-UCL2CSTG.mjs.map +1 -0
- package/package.json +1 -1
- package/dist/ar-SA-KEFQDNRY.js.map +0 -1
- package/dist/ar-SA-SIAKC2NM.mjs.map +0 -1
- package/dist/bg-BG-KJOSTENJ.js.map +0 -1
- package/dist/bg-BG-QJJ2EICE.mjs.map +0 -1
- package/dist/ca-ES-6RJHO7CW.js.map +0 -1
- package/dist/ca-ES-BLI4ZY52.mjs.map +0 -1
- package/dist/cs-CZ-EYNAD3SB.js.map +0 -1
- package/dist/cs-CZ-NAGOSFSX.mjs.map +0 -1
- package/dist/da-DK-34MEUQ6Q.mjs.map +0 -1
- package/dist/da-DK-XH2GXFBP.js.map +0 -1
- package/dist/de-DE-4OPYYEOU.mjs.map +0 -1
- package/dist/de-DE-5V7MNEAO.js.map +0 -1
- package/dist/el-GR-6XYOVQKI.mjs.map +0 -1
- package/dist/el-GR-VU2SDIPX.js.map +0 -1
- package/dist/en-US-WG6KKICO.js.map +0 -1
- package/dist/en-US-X6JS4YBI.mjs.map +0 -1
- package/dist/es-MX-7JBED3HS.js.map +0 -1
- package/dist/es-MX-IQMAFFCN.mjs.map +0 -1
- package/dist/fi-FI-GTYYU5Z5.js.map +0 -1
- package/dist/fi-FI-TQLP2T7Q.mjs.map +0 -1
- package/dist/fr-FR-AN2WCBEN.mjs.map +0 -1
- package/dist/fr-FR-FOPEL7NF.js.map +0 -1
- package/dist/hu-HU-45RKLNLP.mjs.map +0 -1
- package/dist/hu-HU-YIOFTHOC.js.map +0 -1
- package/dist/id-ID-FLY6TBNK.mjs.map +0 -1
- package/dist/id-ID-MOIPXPAZ.js.map +0 -1
- package/dist/it-IT-LT6OAAUK.js.map +0 -1
- package/dist/it-IT-U7MCPA7I.mjs.map +0 -1
- package/dist/ja-JP-4F53IGYM.mjs.map +0 -1
- package/dist/ja-JP-7RPFO3L5.js.map +0 -1
- package/dist/ko-KR-FUSGOUK3.js.map +0 -1
- package/dist/ko-KR-JSUDIE4X.mjs.map +0 -1
- package/dist/nb-NO-M7KPQZF7.mjs.map +0 -1
- package/dist/nb-NO-OQ5QJW3A.js.map +0 -1
- package/dist/nl-NL-J2MYZB4R.js.map +0 -1
- package/dist/nl-NL-RMCZOMG7.mjs.map +0 -1
- package/dist/pl-PL-FWKCORH2.js.map +0 -1
- package/dist/pl-PL-H7J2LNNM.mjs.map +0 -1
- package/dist/pt-BR-BJI34STM.mjs.map +0 -1
- package/dist/pt-BR-X7AATZM7.js.map +0 -1
- package/dist/pt-PT-IWDVXQUL.mjs.map +0 -1
- package/dist/pt-PT-LB5QRWTF.js.map +0 -1
- package/dist/ro-RO-HTULQTIO.mjs.map +0 -1
- package/dist/ro-RO-Y2BKFKBW.js.map +0 -1
- package/dist/ru-RU-3MGSOVBK.js.map +0 -1
- package/dist/ru-RU-GOKLU5AO.mjs.map +0 -1
- package/dist/sk-SK-SQEJ2AA6.mjs.map +0 -1
- package/dist/sk-SK-WAFRGJT2.js.map +0 -1
- package/dist/sl-SI-GVPLMZUV.js.map +0 -1
- package/dist/sl-SI-OU4LJPPU.mjs.map +0 -1
- package/dist/sv-SE-3EUUM37P.mjs.map +0 -1
- package/dist/sv-SE-OXEZ7EB7.js.map +0 -1
- package/dist/th-TH-TGWGACM3.js.map +0 -1
- package/dist/th-TH-X65AHMAW.mjs.map +0 -1
- package/dist/uk-UA-F5U6P4YQ.mjs.map +0 -1
- package/dist/uk-UA-HRZXNCIC.js.map +0 -1
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/rules/kor-phone.ts
|
|
4
|
+
var CC = "82";
|
|
5
|
+
var NATIONAL = /^(?:(?:2|3[1-3]|4[1-4]|5[1-5]|6[1-4])[1-9]\d{6,7}|1[016-9]\d{7,8}|70\d{8})$/;
|
|
6
|
+
var SEPARATORS = "\\u2010-\\u2015\\u2212\\u00B7\\u2022\\u2024\\u2027\\u2219\\u22C5\\u30FB";
|
|
7
|
+
var UNSUPPORTED = new RegExp(`[^\\d\\s+()\\-./\\p{Cf}${SEPARATORS}]`, "u");
|
|
8
|
+
function normalize(input) {
|
|
9
|
+
return input.normalize("NFKC");
|
|
10
|
+
}
|
|
11
|
+
function expandsOnNormalize(input) {
|
|
12
|
+
for (const ch of input) {
|
|
13
|
+
if (ch.charCodeAt(0) < 128) continue;
|
|
14
|
+
if ([...ch.normalize("NFKC")].length > 1) return true;
|
|
15
|
+
}
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
function hasPlusPrefix(value) {
|
|
19
|
+
return /^[^\d]*\+/.test(value);
|
|
20
|
+
}
|
|
21
|
+
function isCcPrefix(digits) {
|
|
22
|
+
if (digits.length === 0) return false;
|
|
23
|
+
return digits.startsWith(CC) || CC.startsWith(digits);
|
|
24
|
+
}
|
|
25
|
+
function splitIntl(value) {
|
|
26
|
+
let digits = value.replace(/\D/g, "");
|
|
27
|
+
const hadPlus = hasPlusPrefix(value);
|
|
28
|
+
let hadIntl00 = false;
|
|
29
|
+
if (digits.startsWith("00")) {
|
|
30
|
+
digits = digits.slice(2);
|
|
31
|
+
hadIntl00 = true;
|
|
32
|
+
}
|
|
33
|
+
return { hadPlus, explicit: hadPlus || hadIntl00, afterIntl: digits };
|
|
34
|
+
}
|
|
35
|
+
function dropTrunk(digits) {
|
|
36
|
+
return digits.startsWith("0") ? digits.slice(1) : digits;
|
|
37
|
+
}
|
|
38
|
+
function isNationalPhoneKOR(digits) {
|
|
39
|
+
return NATIONAL.test(digits);
|
|
40
|
+
}
|
|
41
|
+
function hasInvalidCharsKOR(input) {
|
|
42
|
+
return expandsOnNormalize(input) || UNSUPPORTED.test(normalize(input));
|
|
43
|
+
}
|
|
44
|
+
function unformatPhoneKOR(input) {
|
|
45
|
+
const { explicit, afterIntl } = splitIntl(normalize(input));
|
|
46
|
+
if (afterIntl.startsWith(CC)) {
|
|
47
|
+
const rest = afterIntl.slice(CC.length);
|
|
48
|
+
if (explicit) return dropTrunk(rest);
|
|
49
|
+
const national = dropTrunk(rest);
|
|
50
|
+
if (isNationalPhoneKOR(national)) return national;
|
|
51
|
+
return afterIntl;
|
|
52
|
+
}
|
|
53
|
+
if (!explicit && afterIntl.startsWith("0") && isNationalPhoneKOR(afterIntl.slice(1))) {
|
|
54
|
+
return afterIntl.slice(1);
|
|
55
|
+
}
|
|
56
|
+
return afterIntl;
|
|
57
|
+
}
|
|
58
|
+
function isForeignIntlKOR(input) {
|
|
59
|
+
const { explicit, afterIntl } = splitIntl(normalize(input));
|
|
60
|
+
if (!explicit) return false;
|
|
61
|
+
if (afterIntl.length === 0) return false;
|
|
62
|
+
return !isCcPrefix(afterIntl);
|
|
63
|
+
}
|
|
64
|
+
function formatNational(nsn) {
|
|
65
|
+
const ndcLength = nsn.startsWith("2") ? 1 : 2;
|
|
66
|
+
const ndc = nsn.slice(0, ndcLength);
|
|
67
|
+
const subscriber = nsn.slice(ndcLength);
|
|
68
|
+
const split = subscriber.length === 7 ? 3 : 4;
|
|
69
|
+
return `0${ndc} ${subscriber.slice(0, split)} ${subscriber.slice(split)}`;
|
|
70
|
+
}
|
|
71
|
+
function formatPhoneKOR(input) {
|
|
72
|
+
if (hasInvalidCharsKOR(input)) return input;
|
|
73
|
+
const value = normalize(input);
|
|
74
|
+
const { hadPlus, explicit, afterIntl } = splitIntl(value);
|
|
75
|
+
const rawDigits = value.replace(/\D/g, "");
|
|
76
|
+
if (explicit) {
|
|
77
|
+
const echo = hadPlus ? `+${rawDigits}` : rawDigits;
|
|
78
|
+
if (afterIntl.length > 0 && !isCcPrefix(afterIntl)) return echo;
|
|
79
|
+
if (afterIntl.length < CC.length) return echo;
|
|
80
|
+
const rest = afterIntl.slice(CC.length);
|
|
81
|
+
if (rest === "") return hadPlus ? "+82" : "0082";
|
|
82
|
+
if (rest === "0") return hadPlus ? "+82 0" : "0082 0";
|
|
83
|
+
const phone2 = unformatPhoneKOR(value);
|
|
84
|
+
if (isNationalPhoneKOR(phone2)) return formatNational(phone2);
|
|
85
|
+
if (/^[80]/.test(dropTrunk(rest))) return input;
|
|
86
|
+
return phone2;
|
|
87
|
+
}
|
|
88
|
+
const phone = unformatPhoneKOR(value);
|
|
89
|
+
if (isNationalPhoneKOR(phone)) return formatNational(phone);
|
|
90
|
+
return phone;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
exports.formatPhoneKOR = formatPhoneKOR;
|
|
94
|
+
exports.hasInvalidCharsKOR = hasInvalidCharsKOR;
|
|
95
|
+
exports.isForeignIntlKOR = isForeignIntlKOR;
|
|
96
|
+
exports.isNationalPhoneKOR = isNationalPhoneKOR;
|
|
97
|
+
exports.unformatPhoneKOR = unformatPhoneKOR;
|
|
98
|
+
//# sourceMappingURL=chunk-OEVXHJ5D.js.map
|
|
99
|
+
//# sourceMappingURL=chunk-OEVXHJ5D.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/rules/kor-phone.ts"],"names":["phone"],"mappings":";;;AAwDA,IAAM,EAAA,GAAK,IAAA;AAMX,IAAM,QAAA,GAAW,6EAAA;AASjB,IAAM,UAAA,GAAa,yEAAA;AAOnB,IAAM,cAAc,IAAI,MAAA,CAAO,CAAA,uBAAA,EAA0B,UAAU,KAAK,GAAG,CAAA;AAE3E,SAAS,UAAU,KAAA,EAAuB;AACxC,EAAA,OAAO,KAAA,CAAM,UAAU,MAAM,CAAA;AAC/B;AAOA,SAAS,mBAAmB,KAAA,EAAwB;AAClD,EAAA,KAAA,MAAW,MAAM,KAAA,EAAO;AACtB,IAAA,IAAI,EAAA,CAAG,UAAA,CAAW,CAAC,CAAA,GAAI,GAAA,EAAK;AAC5B,IAAA,IAAI,CAAC,GAAG,EAAA,CAAG,SAAA,CAAU,MAAM,CAAC,CAAA,CAAE,MAAA,GAAS,CAAA,EAAG,OAAO,IAAA;AAAA,EACnD;AACA,EAAA,OAAO,KAAA;AACT;AASA,SAAS,cAAc,KAAA,EAAwB;AAC7C,EAAA,OAAO,WAAA,CAAY,KAAK,KAAK,CAAA;AAC/B;AAEA,SAAS,WAAW,MAAA,EAAyB;AAC3C,EAAA,IAAI,MAAA,CAAO,MAAA,KAAW,CAAA,EAAG,OAAO,KAAA;AAChC,EAAA,OAAO,OAAO,UAAA,CAAW,EAAE,CAAA,IAAK,EAAA,CAAG,WAAW,MAAM,CAAA;AACtD;AASA,SAAS,UAAU,KAAA,EAA0B;AAC3C,EAAA,IAAI,MAA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,EAAU,GAAI,UAAU,KAAK,CAAA;AACxD,EAAA,MAAM,SAAA,GAAY,KAAA,CAAM,OAAA,CAAQ,KAAA,EAAO,EAAE,CAAA;AAEzC,EAAA,IAAI,QAAA,EAAU;AACZ,IAAA,MAAM,IAAA,GAAO,OAAA,GAAU,CAAA,CAAA,EAAI,SAAS,CAAA,CAAA,GAAK,SAAA;AACzC,IAAA,IAAI,UAAU,MAAA,GAAS,CAAA,IAAK,CAAC,UAAA,CAAW,SAAS,GAAG,OAAO,IAAA;AAC3D,IAAA,IAAI,SAAA,CAAU,MAAA,GAAS,EAAA,CAAG,MAAA,EAAQ,OAAO,IAAA;AAEzC,IAAA,MAAM,IAAA,GAAO,SAAA,CAAU,KAAA,CAAM,EAAA,CAAG,MAAM,CAAA;AACtC,IAAA,IAAI,IAAA,KAAS,EAAA,EAAI,OAAO,OAAA,GAAU,KAAA,GAAQ,MAAA;AAC1C,IAAA,IAAI,IAAA,KAAS,GAAA,EAAK,OAAO,OAAA,GAAU,OAAA,GAAU,QAAA;AAE7C,IAAA,MAAMA,MAAAA,GAAQ,iBAAiB,KAAK,CAAA;AACpC,IAAA,IAAI,kBAAA,CAAmBA,MAAK,CAAA,EAAG,OAAO,eAAeA,MAAK,CAAA;AAC1D,IAAA,IAAI,QAAQ,IAAA,CAAK,SAAA,CAAU,IAAI,CAAC,GAAG,OAAO,KAAA;AAC1C,IAAA,OAAOA,MAAAA;AAAA,EACT;AAEA,EAAA,MAAM,KAAA,GAAQ,iBAAiB,KAAK,CAAA;AACpC,EAAA,IAAI,kBAAA,CAAmB,KAAK,CAAA,EAAG,OAAO,eAAe,KAAK,CAAA;AAC1D,EAAA,OAAO,KAAA;AACT","file":"chunk-OEVXHJ5D.js","sourcesContent":["/**\n * Pure South Korean phone helpers. No `register*` side effects — the validator\n * and the mask both import this module so digit normalization stays one\n * implementation.\n *\n * Mirrors `front.phone` `KOR.coffee` (country code `82`, optional trunk `0`,\n * `nationalDestinationCode` list, `splitNumber` as 3 + 4 / 4 + 4). International\n * prefix `00`.\n *\n * `front.phone` is both looser and stricter than the real numbering plan.\n * `Phone.validate` only tests `^(?:\\+?82)?0\\d{5,9}$`: `0000000000` and\n * `039 3323333` pass, while any 11-digit number fails (every `010 1234 5678`\n * mobile and `031 1234 5678`). `getPhoneInternational` has no length limit\n * (the spec accepts `+82 02 3222222222222`), and its NDC list holds only the\n * 17 geographic area codes, so it has no mobile (`010`, `011`, `016`–`019`) or\n * `070` numbers at all. This module keeps the 17 area codes and the\n * 7- or 8-digit subscriber that `splitNumber` handles, and adds what the legacy\n * module is missing and what real users type:\n *\n * - Seoul `2`, and `31`–`33`, `41`–`44`, `51`–`55`, `61`–`64`, followed by a\n * 7- or 8-digit subscriber number that does not start with `0`.\n * - Mobile `10`, `11`, `16`–`19` + 7 or 8 digits (`010 1234 5678` and the\n * older `010 123 4567` / `011 123 4567`). The subscriber may start with `0`,\n * as in libphonenumber's KR mobile ranges, which are plan-level ranges, not\n * allocations.\n * - Internet telephony `70` + 8 digits (libphonenumber's `70\\d{8}`).\n *\n * A national significant number (NSN) never starts with `0` (that is the\n * trunk prefix) and never with `8`. Because of that, `82` can never be the\n * start of a national number, so a bare `82…` is always read as the country\n * code once what follows it (after one optional trunk `0`) is a valid NSN.\n * With an explicit `+` / `00` prefix `82` is always removed, once.\n *\n * Display follows `splitNumber` with the trunk `0` glued to the area code:\n * `02 1234 5678`, `031 123 4567`, `010 1234 5678`. Toll-free `080`, premium\n * `060`, personal `050`, and `15xx` service numbers are not subscriber numbers\n * and are rejected.\n *\n * Input is read the same way by the mask and the validator:\n *\n * - NFKC turns full-width digits, `+`, `(`, `-` and the ideographic space into\n * ASCII, so a Korean or Japanese IME in full-width mode works. A character\n * that NFKC expands to several (`㈜`, `⑩`, `…`) is rejected, so a visible\n * character never becomes more digits than it shows.\n * - Ignored: whitespace, invisible format marks (RTL mark, zero-width space,\n * BOM) and typographic separators (non-breaking hyphen, en/em dash, minus\n * sign, middle dot, bullet).\n * - Rejected: letters and any other character (digits of other scripts such as\n * `٥`, Hangul, `➕`, `x`, `!`). `front.phone` strips letters, and `\\D` would\n * drop the rest, so a typo would silently become another number. The\n * validator rejects them and the mask returns the input unchanged.\n * - A `+` before the first digit is the international prefix even after `(`,\n * `-` or an invisible mark (`(+1) 1 234 5678` is foreign). A `+` after the\n * first digit is ignored.\n */\n\nconst CC = '82'\n\n/**\n * Seoul / area codes (`front.phone` list, without the trunk `0`), mobile, and\n * `70` numbers. The first subscriber digit of a fixed line is `1`–`9`.\n */\nconst NATIONAL = /^(?:(?:2|3[1-3]|4[1-4]|5[1-5]|6[1-4])[1-9]\\d{6,7}|1[016-9]\\d{7,8}|70\\d{8})$/\n\n/**\n * Typographic separators that `\\D` has always discarded, so a number pasted\n * with them keeps working: hyphens and dashes U+2010–U+2015 (including the\n * non-breaking hyphen, en and em dash), minus sign U+2212, middle dot U+00B7,\n * bullet, the one-dot leader U+2024, hyphenation point U+2027, bullet operator\n * U+2219, dot operator U+22C5, and katakana middle dot U+30FB.\n */\nconst SEPARATORS = '\\\\u2010-\\\\u2015\\\\u2212\\\\u00B7\\\\u2022\\\\u2024\\\\u2027\\\\u2219\\\\u22C5\\\\u30FB'\n\n/**\n * A character other than an ASCII digit, whitespace, the separators\n * `front.phone` strips (`+ ( ) - . /`), an invisible format mark, or a\n * typographic separator. Applied after NFKC.\n */\nconst UNSUPPORTED = new RegExp(`[^\\\\d\\\\s+()\\\\-./\\\\p{Cf}${SEPARATORS}]`, 'u')\n\nfunction normalize(input: string): string {\n return input.normalize('NFKC')\n}\n\n/**\n * True when NFKC turns a single character into several (`㈜` → `(주)`, `⑩` →\n * `10`, `…` → `...`): the result would show more characters than the field\n * does.\n */\nfunction expandsOnNormalize(input: string): boolean {\n for (const ch of input) {\n if (ch.charCodeAt(0) < 128) continue\n if ([...ch.normalize('NFKC')].length > 1) return true\n }\n return false\n}\n\n/**\n * True when a `+` comes before the first digit, with any characters in front\n * of it: spaces, parentheses (`(+1) 1 234 5678`), hyphens, or invisible marks\n * such as the RTL mark U+200F. Anchoring on the start of the string would miss\n * those and read a foreign prefix as a national number. A `+` after the first\n * digit is noise and is ignored, by the mask and the validator alike.\n */\nfunction hasPlusPrefix(value: string): boolean {\n return /^[^\\d]*\\+/.test(value)\n}\n\nfunction isCcPrefix(digits: string): boolean {\n if (digits.length === 0) return false\n return digits.startsWith(CC) || CC.startsWith(digits)\n}\n\ninterface IntlSplit {\n hadPlus: boolean\n explicit: boolean\n afterIntl: string\n}\n\n/** `value` must already be normalized (see `normalize`). */\nfunction splitIntl(value: string): IntlSplit {\n let digits = value.replace(/\\D/g, '')\n const hadPlus = hasPlusPrefix(value)\n let hadIntl00 = false\n if (digits.startsWith('00')) {\n digits = digits.slice(2)\n hadIntl00 = true\n }\n return { hadPlus, explicit: hadPlus || hadIntl00, afterIntl: digits }\n}\n\nfunction dropTrunk(digits: string): string {\n return digits.startsWith('0') ? digits.slice(1) : digits\n}\n\n/**\n * True for a national significant number (no trunk `0`, no `+82`): a Seoul or\n * regional fixed line, a mobile, or a `70` number, with an accepted length.\n */\nexport function isNationalPhoneKOR(digits: string): boolean {\n return NATIONAL.test(digits)\n}\n\n/**\n * True when the value has a character this module cannot read: a letter, a\n * character whose NFKC form is longer than itself (`㈜`, `⑩`), or any other\n * character that is not an ASCII digit, whitespace, one of `+ ( ) - . /`, an\n * invisible format mark, or a typographic separator (after NFKC, so full-width\n * digits and punctuation are fine). Letters pass through `front.phone`\n * unnoticed (it strips `[A-z]`), but are rejected here.\n */\nexport function hasInvalidCharsKOR(input: string): boolean {\n return expandsOnNormalize(input) || UNSUPPORTED.test(normalize(input))\n}\n\n/**\n * Strips non-digits, an international `00` prefix, country code `82`, and one\n * trunk `0`.\n *\n * - With an explicit `+` or `00` prefix, always remove `82` and then one trunk\n * `0` (a trunk is never part of an NSN).\n * - Without a prefix, remove `82` only when the rest (after one optional trunk\n * `0`) is a valid national number.\n * - Without a country code, a leading `0` is removed only when the rest is a\n * valid national number, so a typed `0` stays on screen.\n * - A second `82` is never stripped.\n */\nexport function unformatPhoneKOR(input: string): string {\n const { explicit, afterIntl } = splitIntl(normalize(input))\n\n if (afterIntl.startsWith(CC)) {\n const rest = afterIntl.slice(CC.length)\n if (explicit) return dropTrunk(rest)\n const national = dropTrunk(rest)\n if (isNationalPhoneKOR(national)) return national\n return afterIntl\n }\n\n if (!explicit && afterIntl.startsWith('0') && isNationalPhoneKOR(afterIntl.slice(1))) {\n return afterIntl.slice(1)\n }\n\n return afterIntl\n}\n\n/**\n * True when an explicit `+` / `00` prefix is a country code other than `82`.\n * A still-incomplete prefix of `82` (`+`, `+8`, `008`) is not foreign yet.\n * Japan `+81`, China `+86`, and Vietnam `+84` are foreign.\n */\nexport function isForeignIntlKOR(input: string): boolean {\n const { explicit, afterIntl } = splitIntl(normalize(input))\n if (!explicit) return false\n if (afterIntl.length === 0) return false\n return !isCcPrefix(afterIntl)\n}\n\n/** Seoul has a 1-digit area code, every other NDC has 2 digits. */\nfunction formatNational(nsn: string): string {\n const ndcLength = nsn.startsWith('2') ? 1 : 2\n const ndc = nsn.slice(0, ndcLength)\n const subscriber = nsn.slice(ndcLength)\n const split = subscriber.length === 7 ? 3 : 4\n return `0${ndc} ${subscriber.slice(0, split)} ${subscriber.slice(split)}`\n}\n\n/**\n * Formats a raw South Korean phone string for national display.\n *\n * - Complete valid number → `\"02 1234 5678\"`, `\"031 123 4567\"`,\n * `\"010 1234 5678\"` (trunk `0` glued to the area code).\n * - Incomplete national input stays ungrouped. A typed trunk `0` is kept; a\n * trunk `0` is only shown once the number is complete.\n * - Preserves `+` / `00` / `+82` / `0082` / `+82 0` until country code `82` is\n * stripped, and keeps a foreign `+` / `00` prefix on screen.\n * - When a stripped `+82` / `0082` leaves a remainder that is not a national\n * number and starts with `8` or `0` (`+82 82 10…`, `+82 00…`), the original\n * input stays on screen: showing only the remainder would let the next\n * keystroke read it as a bare `82` or a trunk and turn it into a different\n * valid number.\n * - Does not truncate overflow into a shorter valid-looking number.\n * - A value with letters or other unreadable characters (`hasInvalidCharsKOR`)\n * is returned unchanged: the validator rejects it, and dropping those\n * characters would turn it into a valid number.\n * - A `+` before the first digit counts as the international prefix even\n * after `(`, `-` or an invisible mark: `(+1) 1 234 5678` keeps its foreign\n * prefix. Full-width digits and `+` are converted to ASCII.\n */\nexport function formatPhoneKOR(input: string): string {\n if (hasInvalidCharsKOR(input)) return input\n const value = normalize(input)\n const { hadPlus, explicit, afterIntl } = splitIntl(value)\n const rawDigits = value.replace(/\\D/g, '')\n\n if (explicit) {\n const echo = hadPlus ? `+${rawDigits}` : rawDigits\n if (afterIntl.length > 0 && !isCcPrefix(afterIntl)) return echo\n if (afterIntl.length < CC.length) return echo\n\n const rest = afterIntl.slice(CC.length)\n if (rest === '') return hadPlus ? '+82' : '0082'\n if (rest === '0') return hadPlus ? '+82 0' : '0082 0'\n\n const phone = unformatPhoneKOR(value)\n if (isNationalPhoneKOR(phone)) return formatNational(phone)\n if (/^[80]/.test(dropTrunk(rest))) return input\n return phone\n }\n\n const phone = unformatPhoneKOR(value)\n if (isNationalPhoneKOR(phone)) return formatNational(phone)\n return phone\n}\n"]}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/rules/jam-phone.ts
|
|
4
|
+
var CC = "1";
|
|
5
|
+
var AREA_CODES = ["658", "876"];
|
|
6
|
+
function hasJamAreaCode(digits) {
|
|
7
|
+
return AREA_CODES.some((code) => digits.startsWith(code));
|
|
8
|
+
}
|
|
9
|
+
function normalizeJAM(value) {
|
|
10
|
+
let digits = value.replace(/\D/g, "");
|
|
11
|
+
const hadPlus = /^\s*\+/.test(value);
|
|
12
|
+
let hadIntl00 = false;
|
|
13
|
+
if (digits.startsWith("00")) {
|
|
14
|
+
digits = digits.slice(2);
|
|
15
|
+
hadIntl00 = true;
|
|
16
|
+
}
|
|
17
|
+
const explicitIntl = hadPlus || hadIntl00;
|
|
18
|
+
if (digits.startsWith(CC) && (explicitIntl || digits.length > 10)) {
|
|
19
|
+
return { phone: digits.slice(1), stripped: true };
|
|
20
|
+
}
|
|
21
|
+
return { phone: digits, stripped: false };
|
|
22
|
+
}
|
|
23
|
+
function unformatPhoneJAM(value) {
|
|
24
|
+
return normalizeJAM(value).phone;
|
|
25
|
+
}
|
|
26
|
+
function hasDoubleCountryCodeJAM(value) {
|
|
27
|
+
const { phone, stripped } = normalizeJAM(value);
|
|
28
|
+
return stripped && phone.startsWith(CC);
|
|
29
|
+
}
|
|
30
|
+
function isForeignIntlJAM(value) {
|
|
31
|
+
let digits = value.replace(/\D/g, "");
|
|
32
|
+
const hadPlus = /^\s*\+/.test(value);
|
|
33
|
+
let hadIntl00 = false;
|
|
34
|
+
if (digits.startsWith("00")) {
|
|
35
|
+
digits = digits.slice(2);
|
|
36
|
+
hadIntl00 = true;
|
|
37
|
+
}
|
|
38
|
+
if (!hadPlus && !hadIntl00) return false;
|
|
39
|
+
if (digits.length < 1) return false;
|
|
40
|
+
return !digits.startsWith(CC) && !CC.startsWith(digits);
|
|
41
|
+
}
|
|
42
|
+
function formatPhoneJAM(value) {
|
|
43
|
+
if (hasDoubleCountryCodeJAM(value)) return value;
|
|
44
|
+
const keepPlus = /^\s*\+/.test(value);
|
|
45
|
+
const rawDigits = value.replace(/\D/g, "");
|
|
46
|
+
const phone = unformatPhoneJAM(value);
|
|
47
|
+
const after00 = rawDigits.startsWith("00") ? rawDigits.slice(2) : null;
|
|
48
|
+
if (keepPlus && rawDigits.length >= 1 && !rawDigits.startsWith(CC)) {
|
|
49
|
+
return `+${rawDigits}`;
|
|
50
|
+
}
|
|
51
|
+
if (after00 !== null && after00.length >= 1 && !after00.startsWith(CC)) {
|
|
52
|
+
return rawDigits;
|
|
53
|
+
}
|
|
54
|
+
if (keepPlus) {
|
|
55
|
+
if (rawDigits.length === 0) return "+";
|
|
56
|
+
if (rawDigits === CC && phone.length === 0) return "+1";
|
|
57
|
+
}
|
|
58
|
+
if (after00 !== null) {
|
|
59
|
+
if (after00.length === 0) return "00";
|
|
60
|
+
if (after00 === CC && phone.length === 0) return "001";
|
|
61
|
+
}
|
|
62
|
+
if (phone.length === 10 && hasJamAreaCode(phone)) {
|
|
63
|
+
return `(${phone.slice(0, 3)}) ${phone.slice(3, 6)} ${phone.slice(6)}`;
|
|
64
|
+
}
|
|
65
|
+
return phone;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
exports.formatPhoneJAM = formatPhoneJAM;
|
|
69
|
+
exports.isForeignIntlJAM = isForeignIntlJAM;
|
|
70
|
+
exports.unformatPhoneJAM = unformatPhoneJAM;
|
|
71
|
+
//# sourceMappingURL=chunk-SJKTVAYS.js.map
|
|
72
|
+
//# sourceMappingURL=chunk-SJKTVAYS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/rules/jam-phone.ts"],"names":[],"mappings":";;;AAkBA,IAAM,EAAA,GAAK,GAAA;AACX,IAAM,UAAA,GAAa,CAAC,KAAA,EAAO,KAAK,CAAA;AAEhC,SAAS,eAAe,MAAA,EAAyB;AAC/C,EAAA,OAAO,WAAW,IAAA,CAAK,CAAC,SAAS,MAAA,CAAO,UAAA,CAAW,IAAI,CAAC,CAAA;AAC1D;AAOA,SAAS,aAAa,KAAA,EAAqD;AACzE,EAAA,IAAI,MAAA,GAAS,KAAA,CAAM,OAAA,CAAQ,KAAA,EAAO,EAAE,CAAA;AACpC,EAAA,MAAM,OAAA,GAAU,QAAA,CAAS,IAAA,CAAK,KAAK,CAAA;AACnC,EAAA,IAAI,SAAA,GAAY,KAAA;AAChB,EAAA,IAAI,MAAA,CAAO,UAAA,CAAW,IAAI,CAAA,EAAG;AAC3B,IAAA,MAAA,GAAS,MAAA,CAAO,MAAM,CAAC,CAAA;AACvB,IAAA,SAAA,GAAY,IAAA;AAAA,EACd;AACA,EAAA,MAAM,eAAe,OAAA,IAAW,SAAA;AAEhC,EAAA,IAAI,OAAO,UAAA,CAAW,EAAE,MAAM,YAAA,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CAAM,CAAC,CAAC,CAAA,CAAA;AAAA,EACtE;AAEA,EAAA,OAAO,KAAA;AACT","file":"chunk-SJKTVAYS.js","sourcesContent":["/**\n * Pure Jamaica phone helpers. No `register*` side effects — the validator and\n * the mask both import this module so digit normalization stays one\n * implementation.\n *\n * National number is an area code `658` or `876` plus 7 subscriber digits\n * (both are North American Numbering Plan codes assigned to Jamaica). Country\n * code is `1`. Display grouping is the NANP national format, `(876) 927 1234`.\n * `front.phone` has no Jamaican module, and its `NANP.coffee` rejects both area\n * codes. This helper does not check the exchange: `validatePhoneJAM` rejects a\n * central office starting with `0` or `1`.\n *\n * A leading `1` is the country / trunk code, never part of a JAM national\n * number (the area codes are `658` and `876`). It is stripped immediately\n * after an explicit `+` or `00`, and without a prefix only past 10 digits,\n * so a half-typed trunk `1` is not deleted.\n */\n\nconst CC = '1'\nconst AREA_CODES = ['658', '876'] as const\n\nfunction hasJamAreaCode(digits: string): boolean {\n return AREA_CODES.some((code) => digits.startsWith(code))\n}\n\n/**\n * Strips non-digits and an international `00` prefix, then removes country\n * code `1` when it is unambiguous. `stripped` tells the caller whether a\n * leading `1` was removed.\n */\nfunction normalizeJAM(value: string): { phone: string; stripped: boolean } {\n let digits = value.replace(/\\D/g, '')\n const hadPlus = /^\\s*\\+/.test(value)\n let hadIntl00 = false\n if (digits.startsWith('00')) {\n digits = digits.slice(2)\n hadIntl00 = true\n }\n const explicitIntl = hadPlus || hadIntl00\n\n if (digits.startsWith(CC) && (explicitIntl || digits.length > 10)) {\n return { phone: digits.slice(1), stripped: true }\n }\n\n return { phone: digits, stripped: false }\n}\n\n/**\n * Strips non-digits, an international `00` prefix, and country code `1`.\n *\n * - With an explicit `+` or `00` prefix, always remove a leading `1`.\n * - Without a prefix, remove a leading `1` only when the digit string is\n * longer than 10. A complete national number is 10 digits and does not\n * start with `1`, so 11 digits are unambiguously trunk / country + NANP.\n * - Only one `1` is removed.\n */\nexport function unformatPhoneJAM(value: string): string {\n return normalizeJAM(value).phone\n}\n\n/**\n * True when a country code `1` was stripped and another `1` still leads the\n * rest (`+1 1 876…`, `0011 876…`, bare `11876…`). No Jamaican national number\n * starts with `1`, so the validator rejects these. The mask uses this to keep\n * the input as typed instead of showing the leftover `1`, which the validator\n * would then read as a trunk `1` and accept.\n */\nfunction hasDoubleCountryCodeJAM(value: string): boolean {\n const { phone, stripped } = normalizeJAM(value)\n return stripped && phone.startsWith(CC)\n}\n\n/**\n * True when an explicit `+` / `00` prefix is a country code other than `1`.\n * A still-incomplete prefix of `1` (`+`, `001`) is not foreign yet.\n */\nexport function isForeignIntlJAM(value: string): boolean {\n let digits = value.replace(/\\D/g, '')\n const hadPlus = /^\\s*\\+/.test(value)\n let hadIntl00 = false\n if (digits.startsWith('00')) {\n digits = digits.slice(2)\n hadIntl00 = true\n }\n if (!hadPlus && !hadIntl00) return false\n if (digits.length < 1) return false\n return !digits.startsWith(CC) && !CC.startsWith(digits)\n}\n\n/**\n * Formats a raw Jamaican phone string for national display.\n *\n * - Complete `658` / `876` + 7 digits → `\"(876) 927 1234\"`\n * (exchange is not checked)\n * - Keeps `+` / `00` / `001` on screen until country code `1` is stripped\n * - Keeps a foreign `+` / `00` prefix visible\n * - Returns the input unchanged when a second `1` follows the stripped\n * country code (`+1 1 876 927 1234`), so a rejected value is never shown as\n * an accepted one\n * - Does not format or truncate an incomplete or over-long number\n */\nexport function formatPhoneJAM(value: string): string {\n if (hasDoubleCountryCodeJAM(value)) return value\n\n const keepPlus = /^\\s*\\+/.test(value)\n const rawDigits = value.replace(/\\D/g, '')\n const phone = unformatPhoneJAM(value)\n const after00 = rawDigits.startsWith('00') ? rawDigits.slice(2) : null\n\n if (keepPlus && rawDigits.length >= 1 && !rawDigits.startsWith(CC)) {\n return `+${rawDigits}`\n }\n if (after00 !== null && after00.length >= 1 && !after00.startsWith(CC)) {\n return rawDigits\n }\n\n if (keepPlus) {\n if (rawDigits.length === 0) return '+'\n if (rawDigits === CC && phone.length === 0) return '+1'\n }\n if (after00 !== null) {\n if (after00.length === 0) return '00'\n if (after00 === CC && phone.length === 0) return '001'\n }\n\n if (phone.length === 10 && hasJamAreaCode(phone)) {\n return `(${phone.slice(0, 3)}) ${phone.slice(3, 6)} ${phone.slice(6)}`\n }\n\n return phone\n}\n"]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// src/rules/jam-phone.ts
|
|
2
|
+
var CC = "1";
|
|
3
|
+
var AREA_CODES = ["658", "876"];
|
|
4
|
+
function hasJamAreaCode(digits) {
|
|
5
|
+
return AREA_CODES.some((code) => digits.startsWith(code));
|
|
6
|
+
}
|
|
7
|
+
function normalizeJAM(value) {
|
|
8
|
+
let digits = value.replace(/\D/g, "");
|
|
9
|
+
const hadPlus = /^\s*\+/.test(value);
|
|
10
|
+
let hadIntl00 = false;
|
|
11
|
+
if (digits.startsWith("00")) {
|
|
12
|
+
digits = digits.slice(2);
|
|
13
|
+
hadIntl00 = true;
|
|
14
|
+
}
|
|
15
|
+
const explicitIntl = hadPlus || hadIntl00;
|
|
16
|
+
if (digits.startsWith(CC) && (explicitIntl || digits.length > 10)) {
|
|
17
|
+
return { phone: digits.slice(1), stripped: true };
|
|
18
|
+
}
|
|
19
|
+
return { phone: digits, stripped: false };
|
|
20
|
+
}
|
|
21
|
+
function unformatPhoneJAM(value) {
|
|
22
|
+
return normalizeJAM(value).phone;
|
|
23
|
+
}
|
|
24
|
+
function hasDoubleCountryCodeJAM(value) {
|
|
25
|
+
const { phone, stripped } = normalizeJAM(value);
|
|
26
|
+
return stripped && phone.startsWith(CC);
|
|
27
|
+
}
|
|
28
|
+
function isForeignIntlJAM(value) {
|
|
29
|
+
let digits = value.replace(/\D/g, "");
|
|
30
|
+
const hadPlus = /^\s*\+/.test(value);
|
|
31
|
+
let hadIntl00 = false;
|
|
32
|
+
if (digits.startsWith("00")) {
|
|
33
|
+
digits = digits.slice(2);
|
|
34
|
+
hadIntl00 = true;
|
|
35
|
+
}
|
|
36
|
+
if (!hadPlus && !hadIntl00) return false;
|
|
37
|
+
if (digits.length < 1) return false;
|
|
38
|
+
return !digits.startsWith(CC) && !CC.startsWith(digits);
|
|
39
|
+
}
|
|
40
|
+
function formatPhoneJAM(value) {
|
|
41
|
+
if (hasDoubleCountryCodeJAM(value)) return value;
|
|
42
|
+
const keepPlus = /^\s*\+/.test(value);
|
|
43
|
+
const rawDigits = value.replace(/\D/g, "");
|
|
44
|
+
const phone = unformatPhoneJAM(value);
|
|
45
|
+
const after00 = rawDigits.startsWith("00") ? rawDigits.slice(2) : null;
|
|
46
|
+
if (keepPlus && rawDigits.length >= 1 && !rawDigits.startsWith(CC)) {
|
|
47
|
+
return `+${rawDigits}`;
|
|
48
|
+
}
|
|
49
|
+
if (after00 !== null && after00.length >= 1 && !after00.startsWith(CC)) {
|
|
50
|
+
return rawDigits;
|
|
51
|
+
}
|
|
52
|
+
if (keepPlus) {
|
|
53
|
+
if (rawDigits.length === 0) return "+";
|
|
54
|
+
if (rawDigits === CC && phone.length === 0) return "+1";
|
|
55
|
+
}
|
|
56
|
+
if (after00 !== null) {
|
|
57
|
+
if (after00.length === 0) return "00";
|
|
58
|
+
if (after00 === CC && phone.length === 0) return "001";
|
|
59
|
+
}
|
|
60
|
+
if (phone.length === 10 && hasJamAreaCode(phone)) {
|
|
61
|
+
return `(${phone.slice(0, 3)}) ${phone.slice(3, 6)} ${phone.slice(6)}`;
|
|
62
|
+
}
|
|
63
|
+
return phone;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export { formatPhoneJAM, isForeignIntlJAM, unformatPhoneJAM };
|
|
67
|
+
//# sourceMappingURL=chunk-WUEM7DJF.mjs.map
|
|
68
|
+
//# sourceMappingURL=chunk-WUEM7DJF.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/rules/jam-phone.ts"],"names":[],"mappings":";AAkBA,IAAM,EAAA,GAAK,GAAA;AACX,IAAM,UAAA,GAAa,CAAC,KAAA,EAAO,KAAK,CAAA;AAEhC,SA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AA,KAAW,CAAA,EAAG,OAAO,GAAA;AACnC,IAAA,IAAI,SAAA,KAAc,EAAA,IAAM,KAAA,CAAM,MAAA,KAAW,GAAG,OAAO,IAAA;AAAA,EACrD;AACA,EAAA,IAAI,YAAY,IAAA,EAAM;AACpB,IAAA,IAAI,OAAA,CAAQ,MAAA,KAAW,CAAA,EAAG,OAAO,IAAA;AACjC,IAAA,IAAI,OAAA,KAAY,EAAA,IAAM,KAAA,CAAM,MAAA,KAAW,GAAG,OAAO,KAAA;AAAA,EACnD;AAEA,EAAA,IAAI,KAAA,CAAM,MAAA,KAAW,EAAA,IAAM,cAAA,CAAe,KAAK,CAAA,EAAG;AAChD,IAAA,OAAO,IAAI,KAAA,CAAM,KAAA,CAAM,CAAA,EAAG,CAAC,CAAC,CAAA,EAAA,EAAK,KAAA,CAAM,KAAA,CAAM,CAAA,EAAG,CAAC,CAAC,CAAA,CAAA,EAAI,KAAA,CAAM,KAAA,CAAM,CAAC,CAAC,CAAA,CAAA;AAAA,EACtE;AAEA,EAAA,OAAO,KAAA;AACT","file":"chunk-WUEM7DJF.mjs","sourcesContent":["/**\n * Pure Jamaica phone helpers. No `register*` side effects — the validator and\n * the mask both import this module so digit normalization stays one\n * implementation.\n *\n * National number is an area code `658` or `876` plus 7 subscriber digits\n * (both are North American Numbering Plan codes assigned to Jamaica). Country\n * code is `1`. Display grouping is the NANP national format, `(876) 927 1234`.\n * `front.phone` has no Jamaican module, and its `NANP.coffee` rejects both area\n * codes. This helper does not check the exchange: `validatePhoneJAM` rejects a\n * central office starting with `0` or `1`.\n *\n * A leading `1` is the country / trunk code, never part of a JAM national\n * number (the area codes are `658` and `876`). It is stripped immediately\n * after an explicit `+` or `00`, and without a prefix only past 10 digits,\n * so a half-typed trunk `1` is not deleted.\n */\n\nconst CC = '1'\nconst AREA_CODES = ['658', '876'] as const\n\nfunction hasJamAreaCode(digits: string): boolean {\n return AREA_CODES.some((code) => digits.startsWith(code))\n}\n\n/**\n * Strips non-digits and an international `00` prefix, then removes country\n * code `1` when it is unambiguous. `stripped` tells the caller whether a\n * leading `1` was removed.\n */\nfunction normalizeJAM(value: string): { phone: string; stripped: boolean } {\n let digits = value.replace(/\\D/g, '')\n const hadPlus = /^\\s*\\+/.test(value)\n let hadIntl00 = false\n if (digits.startsWith('00')) {\n digits = digits.slice(2)\n hadIntl00 = true\n }\n const explicitIntl = hadPlus || hadIntl00\n\n if (digits.startsWith(CC) && (explicitIntl || digits.length > 10)) {\n return { phone: digits.slice(1), stripped: true }\n }\n\n return { phone: digits, stripped: false }\n}\n\n/**\n * Strips non-digits, an international `00` prefix, and country code `1`.\n *\n * - With an explicit `+` or `00` prefix, always remove a leading `1`.\n * - Without a prefix, remove a leading `1` only when the digit string is\n * longer than 10. A complete national number is 10 digits and does not\n * start with `1`, so 11 digits are unambiguously trunk / country + NANP.\n * - Only one `1` is removed.\n */\nexport function unformatPhoneJAM(value: string): string {\n return normalizeJAM(value).phone\n}\n\n/**\n * True when a country code `1` was stripped and another `1` still leads the\n * rest (`+1 1 876…`, `0011 876…`, bare `11876…`). No Jamaican national number\n * starts with `1`, so the validator rejects these. The mask uses this to keep\n * the input as typed instead of showing the leftover `1`, which the validator\n * would then read as a trunk `1` and accept.\n */\nfunction hasDoubleCountryCodeJAM(value: string): boolean {\n const { phone, stripped } = normalizeJAM(value)\n return stripped && phone.startsWith(CC)\n}\n\n/**\n * True when an explicit `+` / `00` prefix is a country code other than `1`.\n * A still-incomplete prefix of `1` (`+`, `001`) is not foreign yet.\n */\nexport function isForeignIntlJAM(value: string): boolean {\n let digits = value.replace(/\\D/g, '')\n const hadPlus = /^\\s*\\+/.test(value)\n let hadIntl00 = false\n if (digits.startsWith('00')) {\n digits = digits.slice(2)\n hadIntl00 = true\n }\n if (!hadPlus && !hadIntl00) return false\n if (digits.length < 1) return false\n return !digits.startsWith(CC) && !CC.startsWith(digits)\n}\n\n/**\n * Formats a raw Jamaican phone string for national display.\n *\n * - Complete `658` / `876` + 7 digits → `\"(876) 927 1234\"`\n * (exchange is not checked)\n * - Keeps `+` / `00` / `001` on screen until country code `1` is stripped\n * - Keeps a foreign `+` / `00` prefix visible\n * - Returns the input unchanged when a second `1` follows the stripped\n * country code (`+1 1 876 927 1234`), so a rejected value is never shown as\n * an accepted one\n * - Does not format or truncate an incomplete or over-long number\n */\nexport function formatPhoneJAM(value: string): string {\n if (hasDoubleCountryCodeJAM(value)) return value\n\n const keepPlus = /^\\s*\\+/.test(value)\n const rawDigits = value.replace(/\\D/g, '')\n const phone = unformatPhoneJAM(value)\n const after00 = rawDigits.startsWith('00') ? rawDigits.slice(2) : null\n\n if (keepPlus && rawDigits.length >= 1 && !rawDigits.startsWith(CC)) {\n return `+${rawDigits}`\n }\n if (after00 !== null && after00.length >= 1 && !after00.startsWith(CC)) {\n return rawDigits\n }\n\n if (keepPlus) {\n if (rawDigits.length === 0) return '+'\n if (rawDigits === CC && phone.length === 0) return '+1'\n }\n if (after00 !== null) {\n if (after00.length === 0) return '00'\n if (after00 === CC && phone.length === 0) return '001'\n }\n\n if (phone.length === 10 && hasJamAreaCode(phone)) {\n return `(${phone.slice(0, 3)}) ${phone.slice(3, 6)} ${phone.slice(6)}`\n }\n\n return phone\n}\n"]}
|