@indodev/toolkit 0.4.0 → 0.4.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.
- package/README.md +19 -3
- package/dist/index.cjs +66 -49
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +66 -49
- package/dist/index.js.map +1 -1
- package/dist/parse-BDfy3aQw.d.cts +542 -0
- package/dist/parse-BDfy3aQw.d.ts +542 -0
- package/dist/phone/index.cjs +82 -49
- package/dist/phone/index.cjs.map +1 -1
- package/dist/phone/index.d.cts +38 -485
- package/dist/phone/index.d.ts +38 -485
- package/dist/phone/index.js +80 -50
- package/dist/phone/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { NIKInfo, MaskOptions as NIKMaskOptions, formatBirthDate, formatNIK, getAge, isValidForBirthDate, isValidForGender, maskNIK, parseNIK, validateNIK } from './nik/index.cjs';
|
|
2
|
-
export { PhoneFormat, PhoneInfo,
|
|
2
|
+
export { P as PhoneFormat, l as PhoneInfo, M as PhoneMaskOptions, d as cleanPhoneNumber, f as formatPhoneNumber, h as generateSmsLink, j as generateTelLink, e as generateWALink, g as getOperator, a as isLandlineNumber, i as isMobileNumber, k as isProvider, m as maskPhoneNumber, p as parsePhoneNumber, c as toE164, t as toInternational, b as toNational, v as validatePhoneNumber } from './parse-BDfy3aQw.cjs';
|
|
3
3
|
export { NPWPInfo, MaskOptions as NPWPMaskOptions, formatNPWP, maskNPWP, parseNPWP, validateNPWP } from './npwp/index.cjs';
|
|
4
4
|
export { f as formatPlate, g as getRegionFromPlate, v as validatePlate } from './utils-DDVlOusI.cjs';
|
|
5
5
|
export { V as VINOptions, a as VINValidationResult, v as validateVIN } from './types-i5e6R0AS.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { NIKInfo, MaskOptions as NIKMaskOptions, formatBirthDate, formatNIK, getAge, isValidForBirthDate, isValidForGender, maskNIK, parseNIK, validateNIK } from './nik/index.js';
|
|
2
|
-
export { PhoneFormat, PhoneInfo,
|
|
2
|
+
export { P as PhoneFormat, l as PhoneInfo, M as PhoneMaskOptions, d as cleanPhoneNumber, f as formatPhoneNumber, h as generateSmsLink, j as generateTelLink, e as generateWALink, g as getOperator, a as isLandlineNumber, i as isMobileNumber, k as isProvider, m as maskPhoneNumber, p as parsePhoneNumber, c as toE164, t as toInternational, b as toNational, v as validatePhoneNumber } from './parse-BDfy3aQw.js';
|
|
3
3
|
export { NPWPInfo, MaskOptions as NPWPMaskOptions, formatNPWP, maskNPWP, parseNPWP, validateNPWP } from './npwp/index.js';
|
|
4
4
|
export { f as formatPlate, g as getRegionFromPlate, v as validatePlate } from './utils-DDVlOusI.js';
|
|
5
5
|
export { V as VINOptions, a as VINValidationResult, v as validateVIN } from './types-i5e6R0AS.js';
|
package/dist/index.js
CHANGED
|
@@ -715,7 +715,7 @@ function isMobileNumber(phone) {
|
|
|
715
715
|
let normalized;
|
|
716
716
|
if (cleaned.startsWith("+62")) {
|
|
717
717
|
normalized = "0" + cleaned.substring(3);
|
|
718
|
-
} else if (cleaned.startsWith("62")) {
|
|
718
|
+
} else if (cleaned.startsWith("62") && !cleaned.startsWith("620")) {
|
|
719
719
|
normalized = "0" + cleaned.substring(2);
|
|
720
720
|
} else {
|
|
721
721
|
normalized = cleaned;
|
|
@@ -729,19 +729,70 @@ function isLandlineNumber(phone) {
|
|
|
729
729
|
return !isMobileNumber(phone);
|
|
730
730
|
}
|
|
731
731
|
|
|
732
|
+
// src/phone/utils.ts
|
|
733
|
+
function normalizePhoneNumber(phone) {
|
|
734
|
+
if (!phone || typeof phone !== "string") {
|
|
735
|
+
return "";
|
|
736
|
+
}
|
|
737
|
+
if (phone.startsWith("+62")) {
|
|
738
|
+
return "0" + phone.substring(3);
|
|
739
|
+
}
|
|
740
|
+
if (phone.startsWith("62") && !phone.startsWith("620")) {
|
|
741
|
+
return "0" + phone.substring(2);
|
|
742
|
+
}
|
|
743
|
+
if (phone.startsWith("0")) {
|
|
744
|
+
return phone;
|
|
745
|
+
}
|
|
746
|
+
return "";
|
|
747
|
+
}
|
|
748
|
+
function normalizeToNational(phone) {
|
|
749
|
+
if (phone.startsWith("+62")) {
|
|
750
|
+
return "0" + phone.substring(3);
|
|
751
|
+
}
|
|
752
|
+
if (phone.startsWith("62") && !phone.startsWith("620")) {
|
|
753
|
+
return "0" + phone.substring(2);
|
|
754
|
+
}
|
|
755
|
+
if (phone.startsWith("0")) {
|
|
756
|
+
return phone;
|
|
757
|
+
}
|
|
758
|
+
return "";
|
|
759
|
+
}
|
|
760
|
+
function getLandlineRegion(phone) {
|
|
761
|
+
if (!phone || typeof phone !== "string") {
|
|
762
|
+
return null;
|
|
763
|
+
}
|
|
764
|
+
const cleaned = phone.replace(/[^\d+]/g, "");
|
|
765
|
+
const normalized = normalizeToNational(cleaned);
|
|
766
|
+
if (!normalized || !normalized.startsWith("0")) {
|
|
767
|
+
return null;
|
|
768
|
+
}
|
|
769
|
+
if (normalized.startsWith("08")) {
|
|
770
|
+
return null;
|
|
771
|
+
}
|
|
772
|
+
const areaCode4 = normalized.substring(0, 4);
|
|
773
|
+
if (AREA_CODES[areaCode4]) {
|
|
774
|
+
return AREA_CODES[areaCode4];
|
|
775
|
+
}
|
|
776
|
+
const areaCode3 = normalized.substring(0, 3);
|
|
777
|
+
if (AREA_CODES[areaCode3]) {
|
|
778
|
+
return AREA_CODES[areaCode3];
|
|
779
|
+
}
|
|
780
|
+
const areaCode2 = normalized.substring(0, 2);
|
|
781
|
+
if (AREA_CODES[areaCode2]) {
|
|
782
|
+
return AREA_CODES[areaCode2];
|
|
783
|
+
}
|
|
784
|
+
return null;
|
|
785
|
+
}
|
|
786
|
+
|
|
732
787
|
// src/phone/format.ts
|
|
733
788
|
function formatPhoneNumber(phone, format = "national") {
|
|
734
789
|
if (!validatePhoneNumber(phone)) {
|
|
735
790
|
return phone;
|
|
736
791
|
}
|
|
737
792
|
const cleaned = cleanPhoneNumber(phone);
|
|
738
|
-
|
|
739
|
-
if (
|
|
740
|
-
|
|
741
|
-
} else if (cleaned.startsWith("62") && !cleaned.startsWith("620")) {
|
|
742
|
-
normalized = "0" + cleaned.substring(2);
|
|
743
|
-
} else {
|
|
744
|
-
normalized = cleaned;
|
|
793
|
+
const normalized = normalizePhoneNumber(cleaned);
|
|
794
|
+
if (!normalized) {
|
|
795
|
+
return phone;
|
|
745
796
|
}
|
|
746
797
|
switch (format) {
|
|
747
798
|
case "international":
|
|
@@ -760,7 +811,7 @@ function toInternational(phone) {
|
|
|
760
811
|
if (!cleaned) {
|
|
761
812
|
return phone;
|
|
762
813
|
}
|
|
763
|
-
const normalized =
|
|
814
|
+
const normalized = normalizePhoneNumber(cleaned);
|
|
764
815
|
if (!normalized) {
|
|
765
816
|
return phone;
|
|
766
817
|
}
|
|
@@ -786,7 +837,7 @@ function toNational(phone) {
|
|
|
786
837
|
if (!cleaned) {
|
|
787
838
|
return phone;
|
|
788
839
|
}
|
|
789
|
-
const normalized =
|
|
840
|
+
const normalized = normalizePhoneNumber(cleaned);
|
|
790
841
|
if (!normalized) {
|
|
791
842
|
return phone;
|
|
792
843
|
}
|
|
@@ -811,7 +862,7 @@ function toE164(phone) {
|
|
|
811
862
|
if (!cleaned) {
|
|
812
863
|
return phone;
|
|
813
864
|
}
|
|
814
|
-
const normalized =
|
|
865
|
+
const normalized = normalizePhoneNumber(cleaned);
|
|
815
866
|
if (!normalized) {
|
|
816
867
|
return phone;
|
|
817
868
|
}
|
|
@@ -823,16 +874,6 @@ function cleanPhoneNumber(phone) {
|
|
|
823
874
|
}
|
|
824
875
|
return phone.replace(/[^\d+]/g, "");
|
|
825
876
|
}
|
|
826
|
-
function normalizeToNational(phone) {
|
|
827
|
-
if (phone.startsWith("+62")) {
|
|
828
|
-
return "0" + phone.substring(3);
|
|
829
|
-
} else if (phone.startsWith("62") && !phone.startsWith("620")) {
|
|
830
|
-
return "0" + phone.substring(2);
|
|
831
|
-
} else if (phone.startsWith("0")) {
|
|
832
|
-
return phone;
|
|
833
|
-
}
|
|
834
|
-
return "";
|
|
835
|
-
}
|
|
836
877
|
function getAreaCodeLength(normalized) {
|
|
837
878
|
const fourDigitCode = normalized.substring(0, 5);
|
|
838
879
|
if (AREA_CODES[fourDigitCode]) {
|
|
@@ -858,7 +899,7 @@ function maskPhoneNumber(phone, options = {}) {
|
|
|
858
899
|
if (isInternational) {
|
|
859
900
|
toMask = cleaned;
|
|
860
901
|
} else {
|
|
861
|
-
const normalized =
|
|
902
|
+
const normalized = normalizePhoneNumber(cleaned);
|
|
862
903
|
toMask = normalized || cleaned;
|
|
863
904
|
}
|
|
864
905
|
if (toMask.length < 4) {
|
|
@@ -927,7 +968,7 @@ function parsePhoneNumber(phone) {
|
|
|
927
968
|
return null;
|
|
928
969
|
}
|
|
929
970
|
const cleaned = cleanPhoneNumber(phone);
|
|
930
|
-
const normalized =
|
|
971
|
+
const normalized = normalizePhoneNumber(cleaned);
|
|
931
972
|
if (!normalized) {
|
|
932
973
|
return null;
|
|
933
974
|
}
|
|
@@ -940,7 +981,7 @@ function parsePhoneNumber(phone) {
|
|
|
940
981
|
if (isMobile) {
|
|
941
982
|
operator = getOperator(normalized);
|
|
942
983
|
} else {
|
|
943
|
-
region =
|
|
984
|
+
region = getLandlineRegion(normalized);
|
|
944
985
|
}
|
|
945
986
|
return {
|
|
946
987
|
countryCode,
|
|
@@ -962,7 +1003,7 @@ function getOperator(phone) {
|
|
|
962
1003
|
return null;
|
|
963
1004
|
}
|
|
964
1005
|
const cleaned = cleanPhoneNumber(phone);
|
|
965
|
-
const normalized =
|
|
1006
|
+
const normalized = normalizePhoneNumber(cleaned);
|
|
966
1007
|
if (!normalized || normalized.length < 4) {
|
|
967
1008
|
return null;
|
|
968
1009
|
}
|
|
@@ -976,30 +1017,6 @@ function isProvider(phone, providerName) {
|
|
|
976
1017
|
}
|
|
977
1018
|
return operator.toLowerCase() === providerName.toLowerCase();
|
|
978
1019
|
}
|
|
979
|
-
function getRegion(phone) {
|
|
980
|
-
if (!phone.startsWith("0")) {
|
|
981
|
-
return null;
|
|
982
|
-
}
|
|
983
|
-
const areaCode4 = phone.substring(0, 4);
|
|
984
|
-
if (AREA_CODES[areaCode4]) {
|
|
985
|
-
return AREA_CODES[areaCode4];
|
|
986
|
-
}
|
|
987
|
-
const areaCode3 = phone.substring(0, 3);
|
|
988
|
-
if (AREA_CODES[areaCode3]) {
|
|
989
|
-
return AREA_CODES[areaCode3];
|
|
990
|
-
}
|
|
991
|
-
return null;
|
|
992
|
-
}
|
|
993
|
-
function normalizeToNational2(phone) {
|
|
994
|
-
if (phone.startsWith("+62")) {
|
|
995
|
-
return "0" + phone.substring(3);
|
|
996
|
-
} else if (phone.startsWith("62")) {
|
|
997
|
-
return "0" + phone.substring(2);
|
|
998
|
-
} else if (phone.startsWith("0")) {
|
|
999
|
-
return phone;
|
|
1000
|
-
}
|
|
1001
|
-
return "";
|
|
1002
|
-
}
|
|
1003
1020
|
|
|
1004
1021
|
// src/npwp/validate.ts
|
|
1005
1022
|
function validateNPWP(npwp) {
|