pakdatakit 1.0.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/LICENSE +21 -0
- package/README.md +173 -0
- package/dist/index.d.ts +85 -0
- package/dist/index.js +274 -0
- package/dist/index.js.map +1 -0
- package/package.json +63 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 PakDataKit Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
# PakDataKit
|
|
2
|
+
|
|
3
|
+
**PakDataKit** is a production-ready, open-source TypeScript utility library built for Pakistani developers. It provides reliable, typed, and reusable helpers for CNIC validation, phone normalization, mobile network detection, city-to-province lookup, and PKR formatting.
|
|
4
|
+
|
|
5
|
+
## Why PakDataKit?
|
|
6
|
+
|
|
7
|
+
Pakistani applications repeatedly solve the same data problems:
|
|
8
|
+
|
|
9
|
+
- Validating CNIC numbers in multiple input formats
|
|
10
|
+
- Normalizing mobile numbers between `03XX`, `3XX`, and `+92` forms
|
|
11
|
+
- Detecting mobile networks from number prefixes
|
|
12
|
+
- Mapping cities to provinces for forms and analytics
|
|
13
|
+
- Displaying amounts in PKR, Lakh, and Crore conventions
|
|
14
|
+
|
|
15
|
+
PakDataKit centralizes these utilities so you can ship faster with confidence.
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install pakdatakit
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Requires Node.js 18+ and ESM.
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { validateCNIC, getNetwork, formatLakh } from 'pakdatakit';
|
|
29
|
+
|
|
30
|
+
validateCNIC('35202-1234567-1'); // true
|
|
31
|
+
getNetwork('03001234567'); // "Jazz"
|
|
32
|
+
formatLakh(2500000); // "25 Lakh"
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## API Reference
|
|
36
|
+
|
|
37
|
+
### CNIC
|
|
38
|
+
|
|
39
|
+
#### `validateCNIC(cnic: string): boolean`
|
|
40
|
+
|
|
41
|
+
Validates a Pakistani CNIC (13 digits). Accepts plain, dashed, or spaced formats. Strips separators before validation.
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
validateCNIC('3520212345671'); // true
|
|
45
|
+
validateCNIC('35202-1234567-1'); // true
|
|
46
|
+
validateCNIC('35202-123456-1'); // false
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Phone
|
|
50
|
+
|
|
51
|
+
#### `validatePhone(phone: string): boolean`
|
|
52
|
+
|
|
53
|
+
Validates Pakistani mobile numbers in local, international, or short formats.
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
validatePhone('03001234567'); // true
|
|
57
|
+
validatePhone('+923001234567'); // true
|
|
58
|
+
validatePhone('3001234567'); // true
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
#### `formatPhone(phone: string): string`
|
|
62
|
+
|
|
63
|
+
Normalizes a valid Pakistani mobile number to `+923XXXXXXXXX`. Returns an empty string for invalid input.
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
formatPhone('03001234567'); // "+923001234567"
|
|
67
|
+
formatPhone('+92 300-123-4567'); // "+923001234567"
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Networks
|
|
71
|
+
|
|
72
|
+
#### `getNetwork(phone: string): NetworkName`
|
|
73
|
+
|
|
74
|
+
Returns the mobile network based on the number prefix: `"Jazz"`, `"Zong"`, `"Telenor"`, `"Ufone"`, or `"Unknown"`.
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
getNetwork('03001234567'); // "Jazz"
|
|
78
|
+
getNetwork('03151234567'); // "Zong"
|
|
79
|
+
getNetwork('03451234567'); // "Telenor"
|
|
80
|
+
getNetwork('03331234567'); // "Ufone"
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
> **Note:** Prefix-based detection reflects the **original issuing network**. Due to Mobile Number Portability (MNP) in Pakistan, the current carrier may differ from the prefix.
|
|
84
|
+
|
|
85
|
+
### Geography
|
|
86
|
+
|
|
87
|
+
#### `getProvince(city: string): string | null`
|
|
88
|
+
|
|
89
|
+
Returns the province for an exact city name match (case-insensitive, whitespace-tolerant).
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
getProvince('Multan'); // "Punjab"
|
|
93
|
+
getProvince(' karachi '); // "Sindh"
|
|
94
|
+
getProvince('Unknown'); // null
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
#### `searchCities(query: string): string[]`
|
|
98
|
+
|
|
99
|
+
Partial, case-insensitive city search. Returns alphabetically sorted city names.
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
searchCities('mul'); // ["Multan"]
|
|
103
|
+
searchCities('kar'); // ["Karachi"]
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Formatting
|
|
107
|
+
|
|
108
|
+
#### `formatPKR(amount: number): string`
|
|
109
|
+
|
|
110
|
+
Formats an amount as Pakistani Rupees with comma separators.
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
formatPKR(150000); // "Rs. 150,000"
|
|
114
|
+
formatPKR(0); // "Rs. 0"
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
#### `formatLakh(amount: number): string`
|
|
118
|
+
|
|
119
|
+
Formats amounts using Lakh/Crore conventions.
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
formatLakh(2500000); // "25 Lakh"
|
|
123
|
+
formatLakh(10000000); // "1 Crore"
|
|
124
|
+
formatLakh(50000); // "Rs. 50,000"
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Examples
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
import {
|
|
131
|
+
validateCNIC,
|
|
132
|
+
validatePhone,
|
|
133
|
+
formatPhone,
|
|
134
|
+
getNetwork,
|
|
135
|
+
getProvince,
|
|
136
|
+
searchCities,
|
|
137
|
+
formatPKR,
|
|
138
|
+
formatLakh,
|
|
139
|
+
} from 'pakdatakit';
|
|
140
|
+
|
|
141
|
+
// CNIC validation
|
|
142
|
+
const cnicValid = validateCNIC('35202-1234567-1');
|
|
143
|
+
|
|
144
|
+
// Phone normalization
|
|
145
|
+
const phone = formatPhone('0300 123 4567'); // "+923001234567"
|
|
146
|
+
const isValid = validatePhone(phone);
|
|
147
|
+
|
|
148
|
+
// Network lookup
|
|
149
|
+
const network = getNetwork('03001234567'); // "Jazz"
|
|
150
|
+
|
|
151
|
+
// City lookup
|
|
152
|
+
const province = getProvince('Lahore'); // "Punjab"
|
|
153
|
+
const cities = searchCities('fais'); // ["Faisalabad"]
|
|
154
|
+
|
|
155
|
+
// Currency formatting
|
|
156
|
+
const price = formatPKR(150000); // "Rs. 150,000"
|
|
157
|
+
const budget = formatLakh(2500000); // "25 Lakh"
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Development
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
npm install
|
|
164
|
+
npm test
|
|
165
|
+
npm run build
|
|
166
|
+
npm run lint
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for contribution guidelines.
|
|
170
|
+
|
|
171
|
+
## License
|
|
172
|
+
|
|
173
|
+
MIT — see [LICENSE](LICENSE).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates a Pakistani CNIC number.
|
|
3
|
+
*
|
|
4
|
+
* Accepts formats with or without dashes/spaces (e.g. `3520212345671` or `35202-1234567-1`).
|
|
5
|
+
* Strips separators before checking for exactly 13 numeric digits.
|
|
6
|
+
*
|
|
7
|
+
* @param cnic - The CNIC string to validate
|
|
8
|
+
* @returns `true` if the CNIC is valid, otherwise `false`
|
|
9
|
+
*/
|
|
10
|
+
declare function validateCNIC(cnic: string): boolean;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Validates a Pakistani mobile phone number.
|
|
14
|
+
*
|
|
15
|
+
* Accepts local (`03001234567`), international (`+923001234567`),
|
|
16
|
+
* and short (`3001234567`) formats. Ignores spaces and dashes.
|
|
17
|
+
*
|
|
18
|
+
* @param phone - The phone number string to validate
|
|
19
|
+
* @returns `true` if valid, otherwise `false`
|
|
20
|
+
*/
|
|
21
|
+
declare function validatePhone(phone: string): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Formats a Pakistani mobile number to international E.164 style (`+923001234567`).
|
|
24
|
+
*
|
|
25
|
+
* Returns an empty string when the input is not a valid Pakistani mobile number.
|
|
26
|
+
*
|
|
27
|
+
* @param phone - The phone number string to format
|
|
28
|
+
* @returns Formatted phone number or empty string if invalid
|
|
29
|
+
*/
|
|
30
|
+
declare function formatPhone(phone: string): string;
|
|
31
|
+
|
|
32
|
+
type NetworkName = 'Jazz' | 'Zong' | 'Telenor' | 'Ufone' | 'Unknown';
|
|
33
|
+
/**
|
|
34
|
+
* Detects the mobile network for a Pakistani phone number based on its prefix.
|
|
35
|
+
*
|
|
36
|
+
* Returns the original issuing network (Jazz, Zong, Telenor, or Ufone).
|
|
37
|
+
* Due to Mobile Number Portability (MNP), the current carrier may differ.
|
|
38
|
+
*
|
|
39
|
+
* @param phone - The phone number to look up
|
|
40
|
+
* @returns Network name or `"Unknown"` if the prefix is not recognized
|
|
41
|
+
*/
|
|
42
|
+
declare function getNetwork(phone: string): NetworkName;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Returns the province for a given Pakistani city name.
|
|
46
|
+
*
|
|
47
|
+
* Matching is case-insensitive and ignores inconsistent spacing.
|
|
48
|
+
* Returns `null` when no exact city match is found.
|
|
49
|
+
*
|
|
50
|
+
* @param city - The city name to look up
|
|
51
|
+
* @returns Province name or `null` if not found
|
|
52
|
+
*/
|
|
53
|
+
declare function getProvince(city: string): string | null;
|
|
54
|
+
/**
|
|
55
|
+
* Searches cities by partial, case-insensitive name match.
|
|
56
|
+
*
|
|
57
|
+
* @param query - Partial city name to search for
|
|
58
|
+
* @returns Alphabetically sorted list of matching city names
|
|
59
|
+
*/
|
|
60
|
+
declare function searchCities(query: string): string[];
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Formats a numeric amount as Pakistani Rupees with comma separators.
|
|
64
|
+
*
|
|
65
|
+
* Non-finite values and negative amounts are treated as zero.
|
|
66
|
+
*
|
|
67
|
+
* @param amount - The amount in PKR
|
|
68
|
+
* @returns Formatted string (e.g. `"Rs. 150,000"`)
|
|
69
|
+
*/
|
|
70
|
+
declare function formatPKR(amount: number): string;
|
|
71
|
+
/**
|
|
72
|
+
* Formats a numeric amount using Pakistani lakh/crore conventions.
|
|
73
|
+
*
|
|
74
|
+
* - Amounts >= 1 crore render as `"N Crore"` (e.g. `10000000` → `"1 Crore"`)
|
|
75
|
+
* - Amounts >= 1 lakh render as `"N Lakh"` (e.g. `2500000` → `"25 Lakh"`)
|
|
76
|
+
* - Smaller amounts fall back to {@link formatPKR}
|
|
77
|
+
*
|
|
78
|
+
* Non-finite values and negative amounts are treated as zero.
|
|
79
|
+
*
|
|
80
|
+
* @param amount - The amount in PKR
|
|
81
|
+
* @returns Human-readable lakh/crore string
|
|
82
|
+
*/
|
|
83
|
+
declare function formatLakh(amount: number): string;
|
|
84
|
+
|
|
85
|
+
export { type NetworkName, formatLakh, formatPKR, formatPhone, getNetwork, getProvince, searchCities, validateCNIC, validatePhone };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
// src/internal/normalize.ts
|
|
2
|
+
function stripSeparators(input) {
|
|
3
|
+
return input.replace(/[\s\-()]/g, "");
|
|
4
|
+
}
|
|
5
|
+
function normalizeWhitespace(input) {
|
|
6
|
+
return input.trim().replace(/\s+/g, " ");
|
|
7
|
+
}
|
|
8
|
+
function normalizeKey(input) {
|
|
9
|
+
return normalizeWhitespace(input).toLowerCase();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// src/cnic.ts
|
|
13
|
+
var CNIC_PATTERN = /^\d{13}$/;
|
|
14
|
+
function validateCNIC(cnic) {
|
|
15
|
+
const digits = stripSeparators(cnic);
|
|
16
|
+
if (digits.length === 0) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
return CNIC_PATTERN.test(digits);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// src/phone.ts
|
|
23
|
+
var VALID_PHONE_PATTERN = /^\+923\d{9}$/;
|
|
24
|
+
function normalizePhoneDigits(phone) {
|
|
25
|
+
let digits = stripSeparators(phone);
|
|
26
|
+
if (digits.startsWith("+")) {
|
|
27
|
+
digits = digits.slice(1);
|
|
28
|
+
}
|
|
29
|
+
if (digits.startsWith("00")) {
|
|
30
|
+
digits = digits.slice(2);
|
|
31
|
+
}
|
|
32
|
+
if (digits.startsWith("92")) {
|
|
33
|
+
digits = digits.slice(2);
|
|
34
|
+
} else if (digits.startsWith("0")) {
|
|
35
|
+
digits = digits.slice(1);
|
|
36
|
+
}
|
|
37
|
+
if (!/^\d+$/.test(digits)) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
if (digits.length !== 10 || !digits.startsWith("3")) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
return `92${digits}`;
|
|
44
|
+
}
|
|
45
|
+
function validatePhone(phone) {
|
|
46
|
+
const digits = normalizePhoneDigits(phone);
|
|
47
|
+
if (digits === null) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
return VALID_PHONE_PATTERN.test(`+${digits}`);
|
|
51
|
+
}
|
|
52
|
+
function formatPhone(phone) {
|
|
53
|
+
const digits = normalizePhoneDigits(phone);
|
|
54
|
+
if (digits === null) {
|
|
55
|
+
return "";
|
|
56
|
+
}
|
|
57
|
+
return `+${digits}`;
|
|
58
|
+
}
|
|
59
|
+
function getPhonePrefix(phone) {
|
|
60
|
+
const digits = normalizePhoneDigits(phone);
|
|
61
|
+
if (digits === null) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
const local = digits.slice(2);
|
|
65
|
+
return `0${local.slice(0, 3)}`;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// data/networks.json
|
|
69
|
+
var networks_default = [
|
|
70
|
+
{ prefix: "0300", network: "Jazz" },
|
|
71
|
+
{ prefix: "0301", network: "Jazz" },
|
|
72
|
+
{ prefix: "0302", network: "Jazz" },
|
|
73
|
+
{ prefix: "0303", network: "Jazz" },
|
|
74
|
+
{ prefix: "0304", network: "Jazz" },
|
|
75
|
+
{ prefix: "0305", network: "Jazz" },
|
|
76
|
+
{ prefix: "0306", network: "Jazz" },
|
|
77
|
+
{ prefix: "0307", network: "Jazz" },
|
|
78
|
+
{ prefix: "0308", network: "Jazz" },
|
|
79
|
+
{ prefix: "0309", network: "Jazz" },
|
|
80
|
+
{ prefix: "0320", network: "Jazz" },
|
|
81
|
+
{ prefix: "0321", network: "Jazz" },
|
|
82
|
+
{ prefix: "0322", network: "Jazz" },
|
|
83
|
+
{ prefix: "0323", network: "Jazz" },
|
|
84
|
+
{ prefix: "0324", network: "Jazz" },
|
|
85
|
+
{ prefix: "0325", network: "Jazz" },
|
|
86
|
+
{ prefix: "0326", network: "Jazz" },
|
|
87
|
+
{ prefix: "0327", network: "Jazz" },
|
|
88
|
+
{ prefix: "0328", network: "Jazz" },
|
|
89
|
+
{ prefix: "0310", network: "Zong" },
|
|
90
|
+
{ prefix: "0311", network: "Zong" },
|
|
91
|
+
{ prefix: "0312", network: "Zong" },
|
|
92
|
+
{ prefix: "0313", network: "Zong" },
|
|
93
|
+
{ prefix: "0314", network: "Zong" },
|
|
94
|
+
{ prefix: "0315", network: "Zong" },
|
|
95
|
+
{ prefix: "0316", network: "Zong" },
|
|
96
|
+
{ prefix: "0317", network: "Zong" },
|
|
97
|
+
{ prefix: "0318", network: "Zong" },
|
|
98
|
+
{ prefix: "0319", network: "Zong" },
|
|
99
|
+
{ prefix: "0370", network: "Zong" },
|
|
100
|
+
{ prefix: "0371", network: "Zong" },
|
|
101
|
+
{ prefix: "0330", network: "Ufone" },
|
|
102
|
+
{ prefix: "0331", network: "Ufone" },
|
|
103
|
+
{ prefix: "0332", network: "Ufone" },
|
|
104
|
+
{ prefix: "0333", network: "Ufone" },
|
|
105
|
+
{ prefix: "0334", network: "Ufone" },
|
|
106
|
+
{ prefix: "0335", network: "Ufone" },
|
|
107
|
+
{ prefix: "0336", network: "Ufone" },
|
|
108
|
+
{ prefix: "0337", network: "Ufone" },
|
|
109
|
+
{ prefix: "0338", network: "Ufone" },
|
|
110
|
+
{ prefix: "0339", network: "Ufone" },
|
|
111
|
+
{ prefix: "0340", network: "Telenor" },
|
|
112
|
+
{ prefix: "0341", network: "Telenor" },
|
|
113
|
+
{ prefix: "0342", network: "Telenor" },
|
|
114
|
+
{ prefix: "0343", network: "Telenor" },
|
|
115
|
+
{ prefix: "0344", network: "Telenor" },
|
|
116
|
+
{ prefix: "0345", network: "Telenor" },
|
|
117
|
+
{ prefix: "0346", network: "Telenor" },
|
|
118
|
+
{ prefix: "0347", network: "Telenor" },
|
|
119
|
+
{ prefix: "0348", network: "Telenor" },
|
|
120
|
+
{ prefix: "0349", network: "Telenor" }
|
|
121
|
+
];
|
|
122
|
+
|
|
123
|
+
// src/networks.ts
|
|
124
|
+
var PREFIX_MAP = new Map(
|
|
125
|
+
networks_default.map((entry) => [
|
|
126
|
+
entry.prefix,
|
|
127
|
+
entry.network
|
|
128
|
+
])
|
|
129
|
+
);
|
|
130
|
+
function getNetwork(phone) {
|
|
131
|
+
const prefix = getPhonePrefix(phone);
|
|
132
|
+
if (prefix === null) {
|
|
133
|
+
return "Unknown";
|
|
134
|
+
}
|
|
135
|
+
return PREFIX_MAP.get(prefix) ?? "Unknown";
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// data/cities.json
|
|
139
|
+
var cities_default = [
|
|
140
|
+
{ city: "Abbottabad", province: "Khyber Pakhtunkhwa" },
|
|
141
|
+
{ city: "Attock", province: "Punjab" },
|
|
142
|
+
{ city: "Badin", province: "Sindh" },
|
|
143
|
+
{ city: "Bahawalnagar", province: "Punjab" },
|
|
144
|
+
{ city: "Bahawalpur", province: "Punjab" },
|
|
145
|
+
{ city: "Bannu", province: "Khyber Pakhtunkhwa" },
|
|
146
|
+
{ city: "Battagram", province: "Khyber Pakhtunkhwa" },
|
|
147
|
+
{ city: "Bhakkar", province: "Punjab" },
|
|
148
|
+
{ city: "Bhalwal", province: "Punjab" },
|
|
149
|
+
{ city: "Burewala", province: "Punjab" },
|
|
150
|
+
{ city: "Chakwal", province: "Punjab" },
|
|
151
|
+
{ city: "Charsadda", province: "Khyber Pakhtunkhwa" },
|
|
152
|
+
{ city: "Chiniot", province: "Punjab" },
|
|
153
|
+
{ city: "Chitral", province: "Khyber Pakhtunkhwa" },
|
|
154
|
+
{ city: "Dadu", province: "Sindh" },
|
|
155
|
+
{ city: "Dera Ghazi Khan", province: "Punjab" },
|
|
156
|
+
{ city: "Dera Ismail Khan", province: "Khyber Pakhtunkhwa" },
|
|
157
|
+
{ city: "Faisalabad", province: "Punjab" },
|
|
158
|
+
{ city: "Gilgit", province: "Gilgit-Baltistan" },
|
|
159
|
+
{ city: "Gojra", province: "Punjab" },
|
|
160
|
+
{ city: "Gujranwala", province: "Punjab" },
|
|
161
|
+
{ city: "Gujrat", province: "Punjab" },
|
|
162
|
+
{ city: "Hafizabad", province: "Punjab" },
|
|
163
|
+
{ city: "Haripur", province: "Khyber Pakhtunkhwa" },
|
|
164
|
+
{ city: "Hub", province: "Balochistan" },
|
|
165
|
+
{ city: "Hyderabad", province: "Sindh" },
|
|
166
|
+
{ city: "Islamabad", province: "Islamabad Capital Territory" },
|
|
167
|
+
{ city: "Jacobabad", province: "Sindh" },
|
|
168
|
+
{ city: "Jamshoro", province: "Sindh" },
|
|
169
|
+
{ city: "Jhang", province: "Punjab" },
|
|
170
|
+
{ city: "Jhelum", province: "Punjab" },
|
|
171
|
+
{ city: "Karachi", province: "Sindh" },
|
|
172
|
+
{ city: "Kasur", province: "Punjab" },
|
|
173
|
+
{ city: "Khanewal", province: "Punjab" },
|
|
174
|
+
{ city: "Khanpur", province: "Punjab" },
|
|
175
|
+
{ city: "Khushab", province: "Punjab" },
|
|
176
|
+
{ city: "Khuzdar", province: "Balochistan" },
|
|
177
|
+
{ city: "Kohat", province: "Khyber Pakhtunkhwa" },
|
|
178
|
+
{ city: "Kot Addu", province: "Punjab" },
|
|
179
|
+
{ city: "Lahore", province: "Punjab" },
|
|
180
|
+
{ city: "Larkana", province: "Sindh" },
|
|
181
|
+
{ city: "Layyah", province: "Punjab" },
|
|
182
|
+
{ city: "Lodhran", province: "Punjab" },
|
|
183
|
+
{ city: "Loralai", province: "Balochistan" },
|
|
184
|
+
{ city: "Mansehra", province: "Khyber Pakhtunkhwa" },
|
|
185
|
+
{ city: "Mardan", province: "Khyber Pakhtunkhwa" },
|
|
186
|
+
{ city: "Matiari", province: "Sindh" },
|
|
187
|
+
{ city: "Mianwali", province: "Punjab" },
|
|
188
|
+
{ city: "Mingora", province: "Khyber Pakhtunkhwa" },
|
|
189
|
+
{ city: "Mirpur", province: "Azad Jammu and Kashmir" },
|
|
190
|
+
{ city: "Mirpur Khas", province: "Sindh" },
|
|
191
|
+
{ city: "Multan", province: "Punjab" },
|
|
192
|
+
{ city: "Muzaffarabad", province: "Azad Jammu and Kashmir" },
|
|
193
|
+
{ city: "Muzaffargarh", province: "Punjab" },
|
|
194
|
+
{ city: "Nawabshah", province: "Sindh" },
|
|
195
|
+
{ city: "Nowshera", province: "Khyber Pakhtunkhwa" },
|
|
196
|
+
{ city: "Okara", province: "Punjab" },
|
|
197
|
+
{ city: "Pakpattan", province: "Punjab" },
|
|
198
|
+
{ city: "Peshawar", province: "Khyber Pakhtunkhwa" },
|
|
199
|
+
{ city: "Quetta", province: "Balochistan" },
|
|
200
|
+
{ city: "Rahim Yar Khan", province: "Punjab" },
|
|
201
|
+
{ city: "Rawalpindi", province: "Punjab" },
|
|
202
|
+
{ city: "Sahiwal", province: "Punjab" },
|
|
203
|
+
{ city: "Sargodha", province: "Punjab" },
|
|
204
|
+
{ city: "Sheikhupura", province: "Punjab" },
|
|
205
|
+
{ city: "Shikarpur", province: "Sindh" },
|
|
206
|
+
{ city: "Sialkot", province: "Punjab" },
|
|
207
|
+
{ city: "Skardu", province: "Gilgit-Baltistan" },
|
|
208
|
+
{ city: "Sukkur", province: "Sindh" },
|
|
209
|
+
{ city: "Swabi", province: "Khyber Pakhtunkhwa" },
|
|
210
|
+
{ city: "Swat", province: "Khyber Pakhtunkhwa" },
|
|
211
|
+
{ city: "Talagang", province: "Punjab" },
|
|
212
|
+
{ city: "Taxila", province: "Punjab" },
|
|
213
|
+
{ city: "Thatta", province: "Sindh" },
|
|
214
|
+
{ city: "Toba Tek Singh", province: "Punjab" },
|
|
215
|
+
{ city: "Turbat", province: "Balochistan" },
|
|
216
|
+
{ city: "Umerkot", province: "Sindh" },
|
|
217
|
+
{ city: "Vehari", province: "Punjab" },
|
|
218
|
+
{ city: "Wah Cantonment", province: "Punjab" },
|
|
219
|
+
{ city: "Wazirabad", province: "Punjab" },
|
|
220
|
+
{ city: "Zhob", province: "Balochistan" }
|
|
221
|
+
];
|
|
222
|
+
|
|
223
|
+
// src/geo.ts
|
|
224
|
+
var CITIES = cities_default;
|
|
225
|
+
var CITY_LOOKUP = new Map(
|
|
226
|
+
CITIES.map((entry) => [normalizeKey(entry.city), entry.province])
|
|
227
|
+
);
|
|
228
|
+
function getProvince(city) {
|
|
229
|
+
const key = normalizeKey(city);
|
|
230
|
+
if (key.length === 0) {
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
return CITY_LOOKUP.get(key) ?? null;
|
|
234
|
+
}
|
|
235
|
+
function searchCities(query) {
|
|
236
|
+
const normalizedQuery = normalizeKey(query);
|
|
237
|
+
if (normalizedQuery.length === 0) {
|
|
238
|
+
return [];
|
|
239
|
+
}
|
|
240
|
+
const matches = CITIES.filter(
|
|
241
|
+
(entry) => normalizeKey(entry.city).includes(normalizedQuery)
|
|
242
|
+
).map((entry) => entry.city);
|
|
243
|
+
return [...new Set(matches)].sort((a, b) => a.localeCompare(b));
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// src/format.ts
|
|
247
|
+
var LAKH = 1e5;
|
|
248
|
+
var CRORE = 1e7;
|
|
249
|
+
var pkrFormatter = new Intl.NumberFormat("en-PK", {
|
|
250
|
+
maximumFractionDigits: 0
|
|
251
|
+
});
|
|
252
|
+
function formatPKR(amount) {
|
|
253
|
+
const safeAmount = Number.isFinite(amount) && amount > 0 ? amount : 0;
|
|
254
|
+
return `Rs. ${pkrFormatter.format(safeAmount)}`;
|
|
255
|
+
}
|
|
256
|
+
function formatScaled(value, unit) {
|
|
257
|
+
const rounded = Math.round(value * 100) / 100;
|
|
258
|
+
const formatted = Number.isInteger(rounded) ? String(rounded) : String(rounded);
|
|
259
|
+
return `${formatted} ${unit}`;
|
|
260
|
+
}
|
|
261
|
+
function formatLakh(amount) {
|
|
262
|
+
const safeAmount = Number.isFinite(amount) && amount > 0 ? amount : 0;
|
|
263
|
+
if (safeAmount >= CRORE) {
|
|
264
|
+
return formatScaled(safeAmount / CRORE, "Crore");
|
|
265
|
+
}
|
|
266
|
+
if (safeAmount >= LAKH) {
|
|
267
|
+
return formatScaled(safeAmount / LAKH, "Lakh");
|
|
268
|
+
}
|
|
269
|
+
return formatPKR(safeAmount);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export { formatLakh, formatPKR, formatPhone, getNetwork, getProvince, searchCities, validateCNIC, validatePhone };
|
|
273
|
+
//# sourceMappingURL=index.js.map
|
|
274
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internal/normalize.ts","../src/cnic.ts","../src/phone.ts","../data/networks.json","../src/networks.ts","../data/cities.json","../src/geo.ts","../src/format.ts"],"names":[],"mappings":";AAGO,SAAS,gBAAgB,KAAA,EAAuB;AACrD,EAAA,OAAO,KAAA,CAAM,OAAA,CAAQ,WAAA,EAAa,EAAE,CAAA;AACtC;AAKO,SAAS,oBAAoB,KAAA,EAAuB;AACzD,EAAA,OAAO,KAAA,CAAM,IAAA,EAAK,CAAE,OAAA,CAAQ,QAAQ,GAAG,CAAA;AACzC;AAKO,SAAS,aAAa,KAAA,EAAuB;AAClD,EAAA,OAAO,mBAAA,CAAoB,KAAK,CAAA,CAAE,WAAA,EAAY;AAChD;;;ACjBA,IAAM,YAAA,GAAe,UAAA;AAWd,SAAS,aAAa,IAAA,EAAuB;AAClD,EAAA,MAAM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O,GAAA;AACb,IAAM,KAAA,GAAQ,GAAA;AAEd,IAAM,YAAA,GAAe,IAAI,IAAA,CAAK,YAAA,CAAa,OAAA,EAAS;AAAA,EAClD,qBAAA,EAAuB;AACzB,CAAC,CAAA;AAUM,SAAS,UAAU,MAAA,EAAwB;AAChD,EAAA,MAAM,aAAa,MAAA,CAAO,QAAA,CAAS,MAAM,CAAA,IAAK,MAAA,GAAS,IAAI,MAAA,GAAS,CAAA;AACpE,EAAA,OAAO,CAAA,IAAA,EAAO,YAAA,CAAa,MAAA,CAAO,UAAU,CAAC,CAAA,CAAA;AAC/C;AAEA,SAAS,YAAA,CAAa,OAAe,IAAA,EAAgC;AACnE,EAAA,MAAM,OAAA,GAAU,IAAA,CAAK,KAAA,CAAM,KAAA,GAAQ,GAAG,CAAA,GAAI,GAAA;AAC1C,EAAA,MAAM,SAAA,GACJ,OAAO,SAAA,CAAU,OAAO,IAAI,MAAA,CAAO,OAAO,CAAA,GAAI,MAAA,CAAO,OAAO,CAAA;AAC9D,EAAA,OAAO,CAAA,EAAG,SAAS,CAAA,CAAA,EAAI,IAAI,CAAA,CAAA;AAC7B;AAcO,SAAS,WAAW,MAAA,EAAwB;AACjD,EAAA,MAAM,aAAa,MAAA,CAAO,QAAA,CAAS,MAAM,CAAA,IAAK,MAAA,GAAS,IAAI,MAAA,GAAS,CAAA;AAEpE,EAAA,IAAI,cAAc,KAAA,EAAO;AACvB,IAAA,OAAO,YAAA,CAAa,UAAA,GAAa,KAAA,EAAO,OAAO,CAAA;AAAA,EACjD;AAEA,EAAA,IAAI,cAAc,IAAA,EAAM;AACtB,IAAA,OAAO,YAAA,CAAa,UAAA,GAAa,IAAA,EAAM,MAAM,CAAA;AAAA,EAC/C;AAEA,EAAA,OAAO,UAAU,UAAU,CAAA;AAC7B","file":"index.js","sourcesContent":["/**\r\n * Removes spaces, dashes, and parentheses from input.\r\n */\r\nexport function stripSeparators(input: string): string {\r\n return input.replace(/[\\s\\-()]/g, '');\r\n}\r\n\r\n/**\r\n * Collapses internal whitespace and trims leading/trailing spaces.\r\n */\r\nexport function normalizeWhitespace(input: string): string {\r\n return input.trim().replace(/\\s+/g, ' ');\r\n}\r\n\r\n/**\r\n * Normalizes a lookup key: lowercase with collapsed whitespace.\r\n */\r\nexport function normalizeKey(input: string): string {\r\n return normalizeWhitespace(input).toLowerCase();\r\n}\r\n","import { stripSeparators } from './internal/normalize.js';\r\n\r\nconst CNIC_PATTERN = /^\\d{13}$/;\r\n\r\n/**\r\n * Validates a Pakistani CNIC number.\r\n *\r\n * Accepts formats with or without dashes/spaces (e.g. `3520212345671` or `35202-1234567-1`).\r\n * Strips separators before checking for exactly 13 numeric digits.\r\n *\r\n * @param cnic - The CNIC string to validate\r\n * @returns `true` if the CNIC is valid, otherwise `false`\r\n */\r\nexport function validateCNIC(cnic: string): boolean {\r\n const digits = stripSeparators(cnic);\r\n if (digits.length === 0) {\r\n return false;\r\n }\r\n return CNIC_PATTERN.test(digits);\r\n}\r\n","import { stripSeparators } from './internal/normalize.js';\r\n\r\nconst VALID_PHONE_PATTERN = /^\\+923\\d{9}$/;\r\n\r\n/**\r\n * Normalizes a phone string to digits with country code (no leading plus).\r\n * Returns `null` when the input cannot be normalized to a valid Pakistani mobile number.\r\n */\r\nexport function normalizePhoneDigits(phone: string): string | null {\r\n let digits = stripSeparators(phone);\r\n\r\n if (digits.startsWith('+')) {\r\n digits = digits.slice(1);\r\n }\r\n\r\n if (digits.startsWith('00')) {\r\n digits = digits.slice(2);\r\n }\r\n\r\n if (digits.startsWith('92')) {\r\n digits = digits.slice(2);\r\n } else if (digits.startsWith('0')) {\r\n digits = digits.slice(1);\r\n }\r\n\r\n if (!/^\\d+$/.test(digits)) {\r\n return null;\r\n }\r\n\r\n if (digits.length !== 10 || !digits.startsWith('3')) {\r\n return null;\r\n }\r\n\r\n return `92${digits}`;\r\n}\r\n\r\n/**\r\n * Validates a Pakistani mobile phone number.\r\n *\r\n * Accepts local (`03001234567`), international (`+923001234567`),\r\n * and short (`3001234567`) formats. Ignores spaces and dashes.\r\n *\r\n * @param phone - The phone number string to validate\r\n * @returns `true` if valid, otherwise `false`\r\n */\r\nexport function validatePhone(phone: string): boolean {\r\n const digits = normalizePhoneDigits(phone);\r\n if (digits === null) {\r\n return false;\r\n }\r\n return VALID_PHONE_PATTERN.test(`+${digits}`);\r\n}\r\n\r\n/**\r\n * Formats a Pakistani mobile number to international E.164 style (`+923001234567`).\r\n *\r\n * Returns an empty string when the input is not a valid Pakistani mobile number.\r\n *\r\n * @param phone - The phone number string to format\r\n * @returns Formatted phone number or empty string if invalid\r\n */\r\nexport function formatPhone(phone: string): string {\r\n const digits = normalizePhoneDigits(phone);\r\n if (digits === null) {\r\n return '';\r\n }\r\n return `+${digits}`;\r\n}\r\n\r\n/**\r\n * Returns the local Pakistani mobile prefix (`0XXX`) from a phone number.\r\n * Returns `null` when the phone cannot be normalized.\r\n */\r\nexport function getPhonePrefix(phone: string): string | null {\r\n const digits = normalizePhoneDigits(phone);\r\n if (digits === null) {\r\n return null;\r\n }\r\n const local = digits.slice(2);\r\n return `0${local.slice(0, 3)}`;\r\n}\r\n","[\r\n { \"prefix\": \"0300\", \"network\": \"Jazz\" },\r\n { \"prefix\": \"0301\", \"network\": \"Jazz\" },\r\n { \"prefix\": \"0302\", \"network\": \"Jazz\" },\r\n { \"prefix\": \"0303\", \"network\": \"Jazz\" },\r\n { \"prefix\": \"0304\", \"network\": \"Jazz\" },\r\n { \"prefix\": \"0305\", \"network\": \"Jazz\" },\r\n { \"prefix\": \"0306\", \"network\": \"Jazz\" },\r\n { \"prefix\": \"0307\", \"network\": \"Jazz\" },\r\n { \"prefix\": \"0308\", \"network\": \"Jazz\" },\r\n { \"prefix\": \"0309\", \"network\": \"Jazz\" },\r\n { \"prefix\": \"0320\", \"network\": \"Jazz\" },\r\n { \"prefix\": \"0321\", \"network\": \"Jazz\" },\r\n { \"prefix\": \"0322\", \"network\": \"Jazz\" },\r\n { \"prefix\": \"0323\", \"network\": \"Jazz\" },\r\n { \"prefix\": \"0324\", \"network\": \"Jazz\" },\r\n { \"prefix\": \"0325\", \"network\": \"Jazz\" },\r\n { \"prefix\": \"0326\", \"network\": \"Jazz\" },\r\n { \"prefix\": \"0327\", \"network\": \"Jazz\" },\r\n { \"prefix\": \"0328\", \"network\": \"Jazz\" },\r\n { \"prefix\": \"0310\", \"network\": \"Zong\" },\r\n { \"prefix\": \"0311\", \"network\": \"Zong\" },\r\n { \"prefix\": \"0312\", \"network\": \"Zong\" },\r\n { \"prefix\": \"0313\", \"network\": \"Zong\" },\r\n { \"prefix\": \"0314\", \"network\": \"Zong\" },\r\n { \"prefix\": \"0315\", \"network\": \"Zong\" },\r\n { \"prefix\": \"0316\", \"network\": \"Zong\" },\r\n { \"prefix\": \"0317\", \"network\": \"Zong\" },\r\n { \"prefix\": \"0318\", \"network\": \"Zong\" },\r\n { \"prefix\": \"0319\", \"network\": \"Zong\" },\r\n { \"prefix\": \"0370\", \"network\": \"Zong\" },\r\n { \"prefix\": \"0371\", \"network\": \"Zong\" },\r\n { \"prefix\": \"0330\", \"network\": \"Ufone\" },\r\n { \"prefix\": \"0331\", \"network\": \"Ufone\" },\r\n { \"prefix\": \"0332\", \"network\": \"Ufone\" },\r\n { \"prefix\": \"0333\", \"network\": \"Ufone\" },\r\n { \"prefix\": \"0334\", \"network\": \"Ufone\" },\r\n { \"prefix\": \"0335\", \"network\": \"Ufone\" },\r\n { \"prefix\": \"0336\", \"network\": \"Ufone\" },\r\n { \"prefix\": \"0337\", \"network\": \"Ufone\" },\r\n { \"prefix\": \"0338\", \"network\": \"Ufone\" },\r\n { \"prefix\": \"0339\", \"network\": \"Ufone\" },\r\n { \"prefix\": \"0340\", \"network\": \"Telenor\" },\r\n { \"prefix\": \"0341\", \"network\": \"Telenor\" },\r\n { \"prefix\": \"0342\", \"network\": \"Telenor\" },\r\n { \"prefix\": \"0343\", \"network\": \"Telenor\" },\r\n { \"prefix\": \"0344\", \"network\": \"Telenor\" },\r\n { \"prefix\": \"0345\", \"network\": \"Telenor\" },\r\n { \"prefix\": \"0346\", \"network\": \"Telenor\" },\r\n { \"prefix\": \"0347\", \"network\": \"Telenor\" },\r\n { \"prefix\": \"0348\", \"network\": \"Telenor\" },\r\n { \"prefix\": \"0349\", \"network\": \"Telenor\" }\r\n]\r\n","import networksData from '../data/networks.json';\r\nimport { getPhonePrefix } from './phone.js';\r\n\r\nexport type NetworkName = 'Jazz' | 'Zong' | 'Telenor' | 'Ufone' | 'Unknown';\r\n\r\ninterface NetworkEntry {\r\n prefix: string;\r\n network: NetworkName;\r\n}\r\n\r\nconst PREFIX_MAP = new Map<string, NetworkName>(\r\n (networksData as NetworkEntry[]).map((entry) => [\r\n entry.prefix,\r\n entry.network,\r\n ]),\r\n);\r\n\r\n/**\r\n * Detects the mobile network for a Pakistani phone number based on its prefix.\r\n *\r\n * Returns the original issuing network (Jazz, Zong, Telenor, or Ufone).\r\n * Due to Mobile Number Portability (MNP), the current carrier may differ.\r\n *\r\n * @param phone - The phone number to look up\r\n * @returns Network name or `\"Unknown\"` if the prefix is not recognized\r\n */\r\nexport function getNetwork(phone: string): NetworkName {\r\n const prefix = getPhonePrefix(phone);\r\n if (prefix === null) {\r\n return 'Unknown';\r\n }\r\n\r\n return PREFIX_MAP.get(prefix) ?? 'Unknown';\r\n}\r\n","[\r\n { \"city\": \"Abbottabad\", \"province\": \"Khyber Pakhtunkhwa\" },\r\n { \"city\": \"Attock\", \"province\": \"Punjab\" },\r\n { \"city\": \"Badin\", \"province\": \"Sindh\" },\r\n { \"city\": \"Bahawalnagar\", \"province\": \"Punjab\" },\r\n { \"city\": \"Bahawalpur\", \"province\": \"Punjab\" },\r\n { \"city\": \"Bannu\", \"province\": \"Khyber Pakhtunkhwa\" },\r\n { \"city\": \"Battagram\", \"province\": \"Khyber Pakhtunkhwa\" },\r\n { \"city\": \"Bhakkar\", \"province\": \"Punjab\" },\r\n { \"city\": \"Bhalwal\", \"province\": \"Punjab\" },\r\n { \"city\": \"Burewala\", \"province\": \"Punjab\" },\r\n { \"city\": \"Chakwal\", \"province\": \"Punjab\" },\r\n { \"city\": \"Charsadda\", \"province\": \"Khyber Pakhtunkhwa\" },\r\n { \"city\": \"Chiniot\", \"province\": \"Punjab\" },\r\n { \"city\": \"Chitral\", \"province\": \"Khyber Pakhtunkhwa\" },\r\n { \"city\": \"Dadu\", \"province\": \"Sindh\" },\r\n { \"city\": \"Dera Ghazi Khan\", \"province\": \"Punjab\" },\r\n { \"city\": \"Dera Ismail Khan\", \"province\": \"Khyber Pakhtunkhwa\" },\r\n { \"city\": \"Faisalabad\", \"province\": \"Punjab\" },\r\n { \"city\": \"Gilgit\", \"province\": \"Gilgit-Baltistan\" },\r\n { \"city\": \"Gojra\", \"province\": \"Punjab\" },\r\n { \"city\": \"Gujranwala\", \"province\": \"Punjab\" },\r\n { \"city\": \"Gujrat\", \"province\": \"Punjab\" },\r\n { \"city\": \"Hafizabad\", \"province\": \"Punjab\" },\r\n { \"city\": \"Haripur\", \"province\": \"Khyber Pakhtunkhwa\" },\r\n { \"city\": \"Hub\", \"province\": \"Balochistan\" },\r\n { \"city\": \"Hyderabad\", \"province\": \"Sindh\" },\r\n { \"city\": \"Islamabad\", \"province\": \"Islamabad Capital Territory\" },\r\n { \"city\": \"Jacobabad\", \"province\": \"Sindh\" },\r\n { \"city\": \"Jamshoro\", \"province\": \"Sindh\" },\r\n { \"city\": \"Jhang\", \"province\": \"Punjab\" },\r\n { \"city\": \"Jhelum\", \"province\": \"Punjab\" },\r\n { \"city\": \"Karachi\", \"province\": \"Sindh\" },\r\n { \"city\": \"Kasur\", \"province\": \"Punjab\" },\r\n { \"city\": \"Khanewal\", \"province\": \"Punjab\" },\r\n { \"city\": \"Khanpur\", \"province\": \"Punjab\" },\r\n { \"city\": \"Khushab\", \"province\": \"Punjab\" },\r\n { \"city\": \"Khuzdar\", \"province\": \"Balochistan\" },\r\n { \"city\": \"Kohat\", \"province\": \"Khyber Pakhtunkhwa\" },\r\n { \"city\": \"Kot Addu\", \"province\": \"Punjab\" },\r\n { \"city\": \"Lahore\", \"province\": \"Punjab\" },\r\n { \"city\": \"Larkana\", \"province\": \"Sindh\" },\r\n { \"city\": \"Layyah\", \"province\": \"Punjab\" },\r\n { \"city\": \"Lodhran\", \"province\": \"Punjab\" },\r\n { \"city\": \"Loralai\", \"province\": \"Balochistan\" },\r\n { \"city\": \"Mansehra\", \"province\": \"Khyber Pakhtunkhwa\" },\r\n { \"city\": \"Mardan\", \"province\": \"Khyber Pakhtunkhwa\" },\r\n { \"city\": \"Matiari\", \"province\": \"Sindh\" },\r\n { \"city\": \"Mianwali\", \"province\": \"Punjab\" },\r\n { \"city\": \"Mingora\", \"province\": \"Khyber Pakhtunkhwa\" },\r\n { \"city\": \"Mirpur\", \"province\": \"Azad Jammu and Kashmir\" },\r\n { \"city\": \"Mirpur Khas\", \"province\": \"Sindh\" },\r\n { \"city\": \"Multan\", \"province\": \"Punjab\" },\r\n { \"city\": \"Muzaffarabad\", \"province\": \"Azad Jammu and Kashmir\" },\r\n { \"city\": \"Muzaffargarh\", \"province\": \"Punjab\" },\r\n { \"city\": \"Nawabshah\", \"province\": \"Sindh\" },\r\n { \"city\": \"Nowshera\", \"province\": \"Khyber Pakhtunkhwa\" },\r\n { \"city\": \"Okara\", \"province\": \"Punjab\" },\r\n { \"city\": \"Pakpattan\", \"province\": \"Punjab\" },\r\n { \"city\": \"Peshawar\", \"province\": \"Khyber Pakhtunkhwa\" },\r\n { \"city\": \"Quetta\", \"province\": \"Balochistan\" },\r\n { \"city\": \"Rahim Yar Khan\", \"province\": \"Punjab\" },\r\n { \"city\": \"Rawalpindi\", \"province\": \"Punjab\" },\r\n { \"city\": \"Sahiwal\", \"province\": \"Punjab\" },\r\n { \"city\": \"Sargodha\", \"province\": \"Punjab\" },\r\n { \"city\": \"Sheikhupura\", \"province\": \"Punjab\" },\r\n { \"city\": \"Shikarpur\", \"province\": \"Sindh\" },\r\n { \"city\": \"Sialkot\", \"province\": \"Punjab\" },\r\n { \"city\": \"Skardu\", \"province\": \"Gilgit-Baltistan\" },\r\n { \"city\": \"Sukkur\", \"province\": \"Sindh\" },\r\n { \"city\": \"Swabi\", \"province\": \"Khyber Pakhtunkhwa\" },\r\n { \"city\": \"Swat\", \"province\": \"Khyber Pakhtunkhwa\" },\r\n { \"city\": \"Talagang\", \"province\": \"Punjab\" },\r\n { \"city\": \"Taxila\", \"province\": \"Punjab\" },\r\n { \"city\": \"Thatta\", \"province\": \"Sindh\" },\r\n { \"city\": \"Toba Tek Singh\", \"province\": \"Punjab\" },\r\n { \"city\": \"Turbat\", \"province\": \"Balochistan\" },\r\n { \"city\": \"Umerkot\", \"province\": \"Sindh\" },\r\n { \"city\": \"Vehari\", \"province\": \"Punjab\" },\r\n { \"city\": \"Wah Cantonment\", \"province\": \"Punjab\" },\r\n { \"city\": \"Wazirabad\", \"province\": \"Punjab\" },\r\n { \"city\": \"Zhob\", \"province\": \"Balochistan\" }\r\n]\r\n","import citiesData from '../data/cities.json';\r\nimport { normalizeKey } from './internal/normalize.js';\r\n\r\ninterface CityEntry {\r\n city: string;\r\n province: string;\r\n}\r\n\r\nconst CITIES = citiesData as CityEntry[];\r\n\r\nconst CITY_LOOKUP = new Map<string, string>(\r\n CITIES.map((entry) => [normalizeKey(entry.city), entry.province]),\r\n);\r\n\r\n/**\r\n * Returns the province for a given Pakistani city name.\r\n *\r\n * Matching is case-insensitive and ignores inconsistent spacing.\r\n * Returns `null` when no exact city match is found.\r\n *\r\n * @param city - The city name to look up\r\n * @returns Province name or `null` if not found\r\n */\r\nexport function getProvince(city: string): string | null {\r\n const key = normalizeKey(city);\r\n if (key.length === 0) {\r\n return null;\r\n }\r\n return CITY_LOOKUP.get(key) ?? null;\r\n}\r\n\r\n/**\r\n * Searches cities by partial, case-insensitive name match.\r\n *\r\n * @param query - Partial city name to search for\r\n * @returns Alphabetically sorted list of matching city names\r\n */\r\nexport function searchCities(query: string): string[] {\r\n const normalizedQuery = normalizeKey(query);\r\n if (normalizedQuery.length === 0) {\r\n return [];\r\n }\r\n\r\n const matches = CITIES.filter((entry) =>\r\n normalizeKey(entry.city).includes(normalizedQuery),\r\n ).map((entry) => entry.city);\r\n\r\n return [...new Set(matches)].sort((a, b) => a.localeCompare(b));\r\n}\r\n","const LAKH = 100_000;\r\nconst CRORE = 10_000_000;\r\n\r\nconst pkrFormatter = new Intl.NumberFormat('en-PK', {\r\n maximumFractionDigits: 0,\r\n});\r\n\r\n/**\r\n * Formats a numeric amount as Pakistani Rupees with comma separators.\r\n *\r\n * Non-finite values and negative amounts are treated as zero.\r\n *\r\n * @param amount - The amount in PKR\r\n * @returns Formatted string (e.g. `\"Rs. 150,000\"`)\r\n */\r\nexport function formatPKR(amount: number): string {\r\n const safeAmount = Number.isFinite(amount) && amount > 0 ? amount : 0;\r\n return `Rs. ${pkrFormatter.format(safeAmount)}`;\r\n}\r\n\r\nfunction formatScaled(value: number, unit: 'Lakh' | 'Crore'): string {\r\n const rounded = Math.round(value * 100) / 100;\r\n const formatted =\r\n Number.isInteger(rounded) ? String(rounded) : String(rounded);\r\n return `${formatted} ${unit}`;\r\n}\r\n\r\n/**\r\n * Formats a numeric amount using Pakistani lakh/crore conventions.\r\n *\r\n * - Amounts >= 1 crore render as `\"N Crore\"` (e.g. `10000000` → `\"1 Crore\"`)\r\n * - Amounts >= 1 lakh render as `\"N Lakh\"` (e.g. `2500000` → `\"25 Lakh\"`)\r\n * - Smaller amounts fall back to {@link formatPKR}\r\n *\r\n * Non-finite values and negative amounts are treated as zero.\r\n *\r\n * @param amount - The amount in PKR\r\n * @returns Human-readable lakh/crore string\r\n */\r\nexport function formatLakh(amount: number): string {\r\n const safeAmount = Number.isFinite(amount) && amount > 0 ? amount : 0;\r\n\r\n if (safeAmount >= CRORE) {\r\n return formatScaled(safeAmount / CRORE, 'Crore');\r\n }\r\n\r\n if (safeAmount >= LAKH) {\r\n return formatScaled(safeAmount / LAKH, 'Lakh');\r\n }\r\n\r\n return formatPKR(safeAmount);\r\n}\r\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "pakdatakit",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Production-ready utility toolkit for Pakistani developers — CNIC, phone, networks, geography, and formatting",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"scripts": {
|
|
19
|
+
"dev": "vitest",
|
|
20
|
+
"dev:build": "tsup --watch",
|
|
21
|
+
"build": "tsup",
|
|
22
|
+
"test": "vitest run",
|
|
23
|
+
"test:watch": "vitest",
|
|
24
|
+
"lint": "eslint src tests",
|
|
25
|
+
"format": "prettier --write .",
|
|
26
|
+
"format:check": "prettier --check .",
|
|
27
|
+
"typecheck": "tsc --noEmit",
|
|
28
|
+
"prepublishOnly": "npm run build && npm test"
|
|
29
|
+
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"pakistan",
|
|
32
|
+
"cnic",
|
|
33
|
+
"phone",
|
|
34
|
+
"mobile",
|
|
35
|
+
"network",
|
|
36
|
+
"jazz",
|
|
37
|
+
"zong",
|
|
38
|
+
"telenor",
|
|
39
|
+
"ufone",
|
|
40
|
+
"utilities",
|
|
41
|
+
"typescript"
|
|
42
|
+
],
|
|
43
|
+
"author": "",
|
|
44
|
+
"license": "MIT",
|
|
45
|
+
"repository": {
|
|
46
|
+
"type": "git",
|
|
47
|
+
"url": "https://github.com/chmuzamil/pakdatakit.git"
|
|
48
|
+
},
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": ">=18"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@eslint/js": "^9.28.0",
|
|
54
|
+
"@typescript-eslint/eslint-plugin": "^8.33.0",
|
|
55
|
+
"@typescript-eslint/parser": "^8.33.0",
|
|
56
|
+
"eslint": "^9.28.0",
|
|
57
|
+
"eslint-config-prettier": "^10.1.5",
|
|
58
|
+
"prettier": "^3.5.3",
|
|
59
|
+
"tsup": "^8.5.0",
|
|
60
|
+
"typescript": "^5.8.3",
|
|
61
|
+
"vitest": "^3.2.1"
|
|
62
|
+
}
|
|
63
|
+
}
|