saudi-utils 0.1.0 → 0.2.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/README.md +8 -5
- package/dist/address.d.ts +77 -0
- package/dist/address.d.ts.map +1 -1
- package/dist/address.js +81 -2
- package/dist/address.js.map +1 -1
- package/dist/banking.d.ts +33 -0
- package/dist/banking.d.ts.map +1 -1
- package/dist/banking.js +36 -1
- package/dist/banking.js.map +1 -1
- package/dist/business.d.ts +56 -0
- package/dist/business.d.ts.map +1 -1
- package/dist/business.js +56 -0
- package/dist/business.js.map +1 -1
- package/dist/combined.d.ts +23 -0
- package/dist/combined.d.ts.map +1 -0
- package/dist/combined.js +81 -0
- package/dist/combined.js.map +1 -0
- package/dist/detailed.d.ts +104 -0
- package/dist/detailed.d.ts.map +1 -0
- package/dist/detailed.js +156 -0
- package/dist/detailed.js.map +1 -0
- package/dist/identity.d.ts +62 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +62 -0
- package/dist/identity.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/telecom.d.ts +54 -2
- package/dist/telecom.d.ts.map +1 -1
- package/dist/telecom.js +74 -26
- package/dist/telecom.js.map +1 -1
- package/dist/types.d.ts +16 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/telecom.d.ts
CHANGED
|
@@ -1,9 +1,61 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ValidationResult } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Validates a Saudi mobile number in national 05... or +9665... form.
|
|
4
|
+
*
|
|
5
|
+
* Requires ASCII digits and no separators; does not verify allocation, reachability, or carrier.
|
|
6
|
+
*
|
|
7
|
+
* @param value - Unknown input; only a primitive string in the stated canonical format is accepted.
|
|
8
|
+
* @returns A result containing the unchanged string when valid, or the first applicable error code.
|
|
9
|
+
*/
|
|
2
10
|
export declare function validateMobileNumber(value: unknown): ValidationResult;
|
|
11
|
+
/**
|
|
12
|
+
* Checks the national or +966 Saudi mobile number structure.
|
|
13
|
+
*
|
|
14
|
+
* @param value - Unknown input; only a primitive string in the stated canonical format is accepted.
|
|
15
|
+
* @returns True when the input satisfies the stated offline rules; false otherwise.
|
|
16
|
+
*/
|
|
3
17
|
export declare function isMobileNumber(value: unknown): value is string;
|
|
18
|
+
/**
|
|
19
|
+
* Validates a Saudi landline in national 01... or +9661... form with a supported area code.
|
|
20
|
+
*
|
|
21
|
+
* Requires ASCII digits and no separators; does not verify allocation or reachability.
|
|
22
|
+
*
|
|
23
|
+
* @param value - Unknown input; only a primitive string in the stated canonical format is accepted.
|
|
24
|
+
* @returns A result containing the unchanged string when valid, or the first applicable error code.
|
|
25
|
+
*/
|
|
4
26
|
export declare function validateLandlineNumber(value: unknown): ValidationResult;
|
|
27
|
+
/**
|
|
28
|
+
* Checks the national or +966 Saudi landline structure and area code.
|
|
29
|
+
*
|
|
30
|
+
* @param value - Unknown input; only a primitive string in the stated canonical format is accepted.
|
|
31
|
+
* @returns True when the input satisfies the stated offline rules; false otherwise.
|
|
32
|
+
*/
|
|
5
33
|
export declare function isLandlineNumber(value: unknown): value is string;
|
|
34
|
+
/**
|
|
35
|
+
* Validates a Saudi toll-free number in 10-digit national 800... form only.
|
|
36
|
+
*
|
|
37
|
+
* International forms and 9200 numbers are not accepted; reachability is not verified.
|
|
38
|
+
*
|
|
39
|
+
* @param value - Unknown input; only a primitive string in the stated canonical format is accepted.
|
|
40
|
+
* @returns A result containing the unchanged string when valid, or the first applicable error code.
|
|
41
|
+
*/
|
|
6
42
|
export declare function validateTollFreeNumber(value: unknown): ValidationResult;
|
|
43
|
+
/**
|
|
44
|
+
* Checks the national 800... Saudi toll-free structure only.
|
|
45
|
+
*
|
|
46
|
+
* @param value - Unknown input; only a primitive string in the stated canonical format is accepted.
|
|
47
|
+
* @returns True when the input satisfies the stated offline rules; false otherwise.
|
|
48
|
+
*/
|
|
7
49
|
export declare function isTollFreeNumber(value: unknown): value is string;
|
|
8
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Normalizes a supported phone representation without validating its prefix or length.
|
|
52
|
+
*
|
|
53
|
+
* Mobile and landline accept national, +966, 966, or 00966 forms and return +966 form. Toll-free accepts national 800 form only. Whitespace, punctuation, extensions, and Unicode digits are rejected.
|
|
54
|
+
*
|
|
55
|
+
* @param value - Unknown input; only unseparated primitive ASCII strings in supported forms are accepted.
|
|
56
|
+
* @returns The canonical string candidate, even when its prefix or length is invalid; null when the representation cannot be converted.
|
|
57
|
+
*/
|
|
58
|
+
export declare function normalizePhoneNumber(value: unknown): string | null;
|
|
59
|
+
/** @internal Produces a candidate without claiming that the phone number is valid. */
|
|
60
|
+
export declare function normalizePhoneNumberInput(value: unknown): string | null;
|
|
9
61
|
//# sourceMappingURL=telecom.d.ts.map
|
package/dist/telecom.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telecom.d.ts","sourceRoot":"","sources":["../src/telecom.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"telecom.d.ts","sourceRoot":"","sources":["../src/telecom.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAiBnD;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,gBAAgB,CAuBrE;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAE9D;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,gBAAgB,CAuBvE;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAEhE;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,gBAAgB,CAoBvE;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAEhE;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAElE;AAED,sFAAsF;AACtF,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CA2BvE"}
|
package/dist/telecom.js
CHANGED
|
@@ -11,6 +11,14 @@ function validateNationalOrE164Format(value) {
|
|
|
11
11
|
function hasE164SaudiPrefix(value) {
|
|
12
12
|
return value.startsWith("+966");
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Validates a Saudi mobile number in national 05... or +9665... form.
|
|
16
|
+
*
|
|
17
|
+
* Requires ASCII digits and no separators; does not verify allocation, reachability, or carrier.
|
|
18
|
+
*
|
|
19
|
+
* @param value - Unknown input; only a primitive string in the stated canonical format is accepted.
|
|
20
|
+
* @returns A result containing the unchanged string when valid, or the first applicable error code.
|
|
21
|
+
*/
|
|
14
22
|
export function validateMobileNumber(value) {
|
|
15
23
|
const input = checkStringInput(value);
|
|
16
24
|
if (!input.valid) {
|
|
@@ -28,9 +36,23 @@ export function validateMobileNumber(value) {
|
|
|
28
36
|
}
|
|
29
37
|
return { valid: true, value: input.value };
|
|
30
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Checks the national or +966 Saudi mobile number structure.
|
|
41
|
+
*
|
|
42
|
+
* @param value - Unknown input; only a primitive string in the stated canonical format is accepted.
|
|
43
|
+
* @returns True when the input satisfies the stated offline rules; false otherwise.
|
|
44
|
+
*/
|
|
31
45
|
export function isMobileNumber(value) {
|
|
32
46
|
return validateMobileNumber(value).valid;
|
|
33
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Validates a Saudi landline in national 01... or +9661... form with a supported area code.
|
|
50
|
+
*
|
|
51
|
+
* Requires ASCII digits and no separators; does not verify allocation or reachability.
|
|
52
|
+
*
|
|
53
|
+
* @param value - Unknown input; only a primitive string in the stated canonical format is accepted.
|
|
54
|
+
* @returns A result containing the unchanged string when valid, or the first applicable error code.
|
|
55
|
+
*/
|
|
34
56
|
export function validateLandlineNumber(value) {
|
|
35
57
|
const input = checkStringInput(value);
|
|
36
58
|
if (!input.valid) {
|
|
@@ -48,9 +70,23 @@ export function validateLandlineNumber(value) {
|
|
|
48
70
|
}
|
|
49
71
|
return { valid: true, value: input.value };
|
|
50
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Checks the national or +966 Saudi landline structure and area code.
|
|
75
|
+
*
|
|
76
|
+
* @param value - Unknown input; only a primitive string in the stated canonical format is accepted.
|
|
77
|
+
* @returns True when the input satisfies the stated offline rules; false otherwise.
|
|
78
|
+
*/
|
|
51
79
|
export function isLandlineNumber(value) {
|
|
52
80
|
return validateLandlineNumber(value).valid;
|
|
53
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Validates a Saudi toll-free number in 10-digit national 800... form only.
|
|
84
|
+
*
|
|
85
|
+
* International forms and 9200 numbers are not accepted; reachability is not verified.
|
|
86
|
+
*
|
|
87
|
+
* @param value - Unknown input; only a primitive string in the stated canonical format is accepted.
|
|
88
|
+
* @returns A result containing the unchanged string when valid, or the first applicable error code.
|
|
89
|
+
*/
|
|
54
90
|
export function validateTollFreeNumber(value) {
|
|
55
91
|
const input = checkStringInput(value);
|
|
56
92
|
if (!input.valid) {
|
|
@@ -67,38 +103,50 @@ export function validateTollFreeNumber(value) {
|
|
|
67
103
|
}
|
|
68
104
|
return { valid: true, value: input.value };
|
|
69
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Checks the national 800... Saudi toll-free structure only.
|
|
108
|
+
*
|
|
109
|
+
* @param value - Unknown input; only a primitive string in the stated canonical format is accepted.
|
|
110
|
+
* @returns True when the input satisfies the stated offline rules; false otherwise.
|
|
111
|
+
*/
|
|
70
112
|
export function isTollFreeNumber(value) {
|
|
71
113
|
return validateTollFreeNumber(value).valid;
|
|
72
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Normalizes a supported phone representation without validating its prefix or length.
|
|
117
|
+
*
|
|
118
|
+
* Mobile and landline accept national, +966, 966, or 00966 forms and return +966 form. Toll-free accepts national 800 form only. Whitespace, punctuation, extensions, and Unicode digits are rejected.
|
|
119
|
+
*
|
|
120
|
+
* @param value - Unknown input; only unseparated primitive ASCII strings in supported forms are accepted.
|
|
121
|
+
* @returns The canonical string candidate, even when its prefix or length is invalid; null when the representation cannot be converted.
|
|
122
|
+
*/
|
|
73
123
|
export function normalizePhoneNumber(value) {
|
|
124
|
+
return normalizePhoneNumberInput(value);
|
|
125
|
+
}
|
|
126
|
+
/** @internal Produces a candidate without claiming that the phone number is valid. */
|
|
127
|
+
export function normalizePhoneNumberInput(value) {
|
|
74
128
|
if (typeof value !== "string") {
|
|
75
129
|
return null;
|
|
76
130
|
}
|
|
77
|
-
if (
|
|
78
|
-
return
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
return { kind: "mobile", value: canonical };
|
|
98
|
-
}
|
|
99
|
-
if (validateLandlineNumber(canonical).valid) {
|
|
100
|
-
return { kind: "landline", value: canonical };
|
|
101
|
-
}
|
|
102
|
-
return null;
|
|
131
|
+
if (value.startsWith("800")) {
|
|
132
|
+
return isAsciiDigits(value) ? value : null;
|
|
133
|
+
}
|
|
134
|
+
const national = hasE164SaudiPrefix(value)
|
|
135
|
+
? value.slice(4)
|
|
136
|
+
: value.startsWith("00966")
|
|
137
|
+
? value.slice(5)
|
|
138
|
+
: value.startsWith("966")
|
|
139
|
+
? value.slice(3)
|
|
140
|
+
: value.startsWith("0")
|
|
141
|
+
? value.slice(1)
|
|
142
|
+
: null;
|
|
143
|
+
return national !== null &&
|
|
144
|
+
national !== "" &&
|
|
145
|
+
isAsciiDigits(national) &&
|
|
146
|
+
!national.startsWith("0") &&
|
|
147
|
+
!national.startsWith("966") &&
|
|
148
|
+
!national.startsWith("800")
|
|
149
|
+
? `+966${national}`
|
|
150
|
+
: null;
|
|
103
151
|
}
|
|
104
152
|
//# sourceMappingURL=telecom.js.map
|
package/dist/telecom.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telecom.js","sourceRoot":"","sources":["../src/telecom.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAGvD,MAAM,qBAAqB,GAAG,EAAE,CAAC;AACjC,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAE7B,SAAS,4BAA4B,CAAC,KAAa;IACjD,IAAI,KAAK,CAAC,MAAM,KAAK,qBAAqB,EAAE,CAAC;QAC3C,OAAO,aAAa,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IAED,OAAO,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AAChE,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAa;IACvC,OAAO,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,KAAc;IACjD,MAAM,KAAK,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC;IAEtC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QACjB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,KAAK,qBA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CAAC,KAAK,CAAC,CAAC,CAAC;gBAChB,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC;oBACrB,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;oBAChB,CAAC,CAAC,IAAI,CAAC;IAEf,OAAO,QAAQ,KAAK,IAAI;QACtB,QAAQ,KAAK,EAAE;QACf,aAAa,CAAC,QAAQ,CAAC;QACvB,CAAC,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC;QACzB,CAAC,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC;QAC3B,CAAC,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC;QAC3B,CAAC,CAAC,OAAO,QAAQ,EAAE;QACnB,CAAC,CAAC,IAAI,CAAC;AACX,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
/** Stable reason for a failed offline validation, ordered from missing input through checksum failure. */
|
|
1
2
|
export type ValidationErrorCode = "REQUIRED" | "INVALID_TYPE" | "INVALID_LENGTH" | "INVALID_FORMAT" | "INVALID_PREFIX" | "INVALID_CHECKSUM";
|
|
3
|
+
/** A valid canonical input or a deterministic error code; validation never normalizes the input. */
|
|
2
4
|
export type ValidationResult = {
|
|
3
5
|
valid: true;
|
|
4
6
|
value: string;
|
|
@@ -6,7 +8,19 @@ export type ValidationResult = {
|
|
|
6
8
|
valid: false;
|
|
7
9
|
code: ValidationErrorCode;
|
|
8
10
|
};
|
|
11
|
+
/** A validated value or a stable error code with a short, consumer-facing explanation. */
|
|
12
|
+
export type DetailedValidationResult<T = string> = {
|
|
13
|
+
valid: true;
|
|
14
|
+
value: T;
|
|
15
|
+
} | {
|
|
16
|
+
valid: false;
|
|
17
|
+
code: ValidationErrorCode;
|
|
18
|
+
message: string;
|
|
19
|
+
normalizedValue?: string;
|
|
20
|
+
};
|
|
21
|
+
/** Documentation-only strength of evidence behind a validation rule; not returned at runtime. */
|
|
9
22
|
export type ValidationEvidence = "official-checksum" | "official-structural" | "official-structural-community-checksum" | "best-known-structural";
|
|
23
|
+
/** Validated combined phone result and its kind: E.164 for mobile/landline, national form for toll-free. */
|
|
10
24
|
export type NormalizedSaudiPhone = {
|
|
11
25
|
kind: "mobile" | "landline";
|
|
12
26
|
value: `+966${string}`;
|
|
@@ -14,6 +28,7 @@ export type NormalizedSaudiPhone = {
|
|
|
14
28
|
kind: "toll-free";
|
|
15
29
|
value: `800${string}`;
|
|
16
30
|
};
|
|
31
|
+
/** Required Saudi National Address fields; structural validation does not prove an address exists. */
|
|
17
32
|
export type NationalAddress = {
|
|
18
33
|
buildingNumber: string;
|
|
19
34
|
street: string;
|
|
@@ -22,6 +37,7 @@ export type NationalAddress = {
|
|
|
22
37
|
postalCode: string;
|
|
23
38
|
additionalNumber: string;
|
|
24
39
|
};
|
|
40
|
+
/** A structurally valid address object or the first deterministic validation error. */
|
|
25
41
|
export type NationalAddressValidationResult = {
|
|
26
42
|
valid: true;
|
|
27
43
|
value: NationalAddress;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,GAC3B,UAAU,GACV,cAAc,GACd,gBAAgB,GAChB,gBAAgB,GAChB,gBAAgB,GAChB,kBAAkB,CAAC;AAEvB,MAAM,MAAM,gBAAgB,GACxB;IACE,KAAK,EAAE,IAAI,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;CACf,GACD;IACE,KAAK,EAAE,KAAK,CAAC;IACb,IAAI,EAAE,mBAAmB,CAAC;CAC3B,CAAC;AAEN,MAAM,MAAM,kBAAkB,GAC1B,mBAAmB,GACnB,qBAAqB,GACrB,wCAAwC,GACxC,uBAAuB,CAAC;AAE5B,MAAM,MAAM,oBAAoB,GAC5B;IACE,IAAI,EAAE,QAAQ,GAAG,UAAU,CAAC;IAC5B,KAAK,EAAE,OAAO,MAAM,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