@indodev/toolkit 0.0.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/LICENCE +21 -0
- package/README.md +293 -0
- package/dist/currency/index.cjs +245 -0
- package/dist/currency/index.cjs.map +1 -0
- package/dist/currency/index.d.cts +43 -0
- package/dist/currency/index.d.ts +43 -0
- package/dist/currency/index.js +239 -0
- package/dist/currency/index.js.map +1 -0
- package/dist/index.cjs +1173 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1153 -0
- package/dist/index.js.map +1 -0
- package/dist/nik/index.cjs +218 -0
- package/dist/nik/index.cjs.map +1 -0
- package/dist/nik/index.d.cts +288 -0
- package/dist/nik/index.d.ts +288 -0
- package/dist/nik/index.js +213 -0
- package/dist/nik/index.js.map +1 -0
- package/dist/phone/index.cjs +730 -0
- package/dist/phone/index.cjs.map +1 -0
- package/dist/phone/index.d.cts +472 -0
- package/dist/phone/index.d.ts +472 -0
- package/dist/phone/index.js +718 -0
- package/dist/phone/index.js.map +1 -0
- package/dist/words-Dy8iYkbv.d.cts +333 -0
- package/dist/words-Dy8iYkbv.d.ts +333 -0
- package/package.json +120 -0
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates a NIK (Nomor Induk Kependudukan) format.
|
|
3
|
+
*
|
|
4
|
+
* A valid NIK must:
|
|
5
|
+
* - Be exactly 16 digits
|
|
6
|
+
* - Have a valid province code (positions 1-2)
|
|
7
|
+
* - Have a valid date (positions 7-12)
|
|
8
|
+
* - Not be in the future
|
|
9
|
+
* - Not be before 1900
|
|
10
|
+
*
|
|
11
|
+
* For female NIKs, the day is encoded as (actual day + 40).
|
|
12
|
+
* For example, a female born on the 15th would have day = 55.
|
|
13
|
+
*
|
|
14
|
+
* @param nik - The 16-digit NIK string to validate
|
|
15
|
+
* @returns `true` if the NIK is valid, `false` otherwise
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* validateNIK('3201234567890123'); // true - valid NIK
|
|
20
|
+
* validateNIK('1234'); // false - wrong length
|
|
21
|
+
* validateNIK('9912345678901234'); // false - invalid province
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
declare function validateNIK(nik: string): boolean;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Information extracted from a valid NIK.
|
|
30
|
+
*
|
|
31
|
+
* Contains parsed data including location codes, birth date, gender,
|
|
32
|
+
* and serial number from a 16-digit NIK string.
|
|
33
|
+
*
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
interface NIKInfo {
|
|
37
|
+
/**
|
|
38
|
+
* Province information extracted from positions 1-2 of the NIK.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* { code: '32', name: 'Jawa Barat' }
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
province: {
|
|
46
|
+
/** Two-digit province code (e.g., '32') */
|
|
47
|
+
code: string;
|
|
48
|
+
/** Full province name (e.g., 'Jawa Barat') */
|
|
49
|
+
name: string;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Regency (Kabupaten/Kota) information extracted from positions 3-4 of the NIK.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* { code: '01', name: 'Kab. Bogor' }
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
regency: {
|
|
60
|
+
/** Two-digit regency code (e.g., '01') */
|
|
61
|
+
code: string;
|
|
62
|
+
/** Full regency name (e.g., 'Kab. Bogor') */
|
|
63
|
+
name: string;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* District (Kecamatan) information extracted from positions 5-6 of the NIK.
|
|
67
|
+
* May be `null` if district data is not available.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* { code: '23', name: 'Ciawi' }
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
district: {
|
|
75
|
+
/** Two-digit district code (e.g., '23') */
|
|
76
|
+
code: string;
|
|
77
|
+
/** Full district name, or `null` if data unavailable */
|
|
78
|
+
name: string | null;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Birth date extracted from positions 7-12 of the NIK.
|
|
82
|
+
* For females, the day is encoded as (actual day + 40).
|
|
83
|
+
* Returns `null` if the date is invalid.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* new Date(1989, 0, 31) // January 31, 1989
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
birthDate: Date | null;
|
|
91
|
+
/**
|
|
92
|
+
* Gender derived from the day encoding in the NIK.
|
|
93
|
+
* - 'male': day is 1-31
|
|
94
|
+
* - 'female': day is 41-71 (actual day + 40)
|
|
95
|
+
* - `null`: if unable to determine
|
|
96
|
+
*/
|
|
97
|
+
gender: 'male' | 'female' | null;
|
|
98
|
+
/**
|
|
99
|
+
* Serial number from positions 13-16 of the NIK.
|
|
100
|
+
* Uniquely identifies individuals with the same location and birth date.
|
|
101
|
+
* Returns `null` if unable to extract.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* '0123'
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
serialNumber: string | null;
|
|
109
|
+
/**
|
|
110
|
+
* Whether the NIK passed validation checks.
|
|
111
|
+
* If `false`, other fields may be `null` or contain partial data.
|
|
112
|
+
*/
|
|
113
|
+
isValid: boolean;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Options for masking a NIK to protect privacy.
|
|
117
|
+
*
|
|
118
|
+
* Controls how many characters to show at the start and end,
|
|
119
|
+
* what character to use for masking, and optional separators.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* // Default: shows first 4 and last 4 digits
|
|
124
|
+
* { start: 4, end: 4, char: '*' }
|
|
125
|
+
* // Result: '3201********0123'
|
|
126
|
+
*
|
|
127
|
+
* // With separator
|
|
128
|
+
* { start: 4, end: 4, char: '*', separator: '-' }
|
|
129
|
+
* // Result: '3201-****-****-0123'
|
|
130
|
+
* ```
|
|
131
|
+
*
|
|
132
|
+
* @public
|
|
133
|
+
*/
|
|
134
|
+
interface MaskOptions {
|
|
135
|
+
/**
|
|
136
|
+
* Number of characters to show at the start.
|
|
137
|
+
*
|
|
138
|
+
* @defaultValue 4
|
|
139
|
+
*/
|
|
140
|
+
start?: number;
|
|
141
|
+
/**
|
|
142
|
+
* Number of characters to show at the end.
|
|
143
|
+
*
|
|
144
|
+
* @defaultValue 4
|
|
145
|
+
*/
|
|
146
|
+
end?: number;
|
|
147
|
+
/**
|
|
148
|
+
* Character to use for masking hidden digits.
|
|
149
|
+
*
|
|
150
|
+
* @defaultValue '*'
|
|
151
|
+
*/
|
|
152
|
+
char?: string;
|
|
153
|
+
/**
|
|
154
|
+
* Optional separator to add between groups of digits.
|
|
155
|
+
* If provided, the NIK will be formatted with separators.
|
|
156
|
+
*
|
|
157
|
+
* @defaultValue undefined (no separator)
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```typescript
|
|
161
|
+
* '-' // Results in format: '3201-****-****-0123'
|
|
162
|
+
* ' ' // Results in format: '3201 **** **** 0123'
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
separator?: string;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Parses a NIK and extracts all embedded information.
|
|
170
|
+
*
|
|
171
|
+
* Extracts province, regency, district codes, birth date, gender,
|
|
172
|
+
* and serial number from a 16-digit NIK string.
|
|
173
|
+
*
|
|
174
|
+
* @param nik - The 16-digit NIK string to parse
|
|
175
|
+
* @returns Parsed NIK information, or `null` if the NIK format is invalid
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* Parse a valid male NIK:
|
|
179
|
+
* ```typescript
|
|
180
|
+
* const info = parseNIK('3201018901310123');
|
|
181
|
+
* console.log(info);
|
|
182
|
+
* // {
|
|
183
|
+
* // province: { code: '32', name: 'Jawa Barat' },
|
|
184
|
+
* // regency: { code: '01', name: 'Kab. Bogor' },
|
|
185
|
+
* // district: { code: '01', name: null },
|
|
186
|
+
* // birthDate: Date(1989, 0, 31), // Jan 31, 1989
|
|
187
|
+
* // gender: 'male',
|
|
188
|
+
* // serialNumber: '0123',
|
|
189
|
+
* // isValid: true
|
|
190
|
+
* // }
|
|
191
|
+
* ```
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* Parse a female NIK (day + 40):
|
|
195
|
+
* ```typescript
|
|
196
|
+
* const info = parseNIK('3201019508550123');
|
|
197
|
+
* console.log(info.gender); // 'female'
|
|
198
|
+
* console.log(info.birthDate); // Date(1995, 7, 15) - Aug 15, 1995
|
|
199
|
+
* ```
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* Invalid NIK returns null:
|
|
203
|
+
* ```typescript
|
|
204
|
+
* const info = parseNIK('invalid');
|
|
205
|
+
* console.log(info); // null
|
|
206
|
+
* ```
|
|
207
|
+
*
|
|
208
|
+
* @public
|
|
209
|
+
*/
|
|
210
|
+
declare function parseNIK(nik: string): NIKInfo | null;
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Formats a NIK with separators for better readability.
|
|
214
|
+
*
|
|
215
|
+
* Groups the NIK into logical segments: province, regency, district,
|
|
216
|
+
* year, month, day, and serial number.
|
|
217
|
+
*
|
|
218
|
+
* @param nik - The 16-digit NIK string to format
|
|
219
|
+
* @param separator - Character to use as separator
|
|
220
|
+
* @returns Formatted NIK string, or original string if invalid format
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* Default separator (dash):
|
|
224
|
+
* ```typescript
|
|
225
|
+
* formatNIK('3201234567890123');
|
|
226
|
+
* // '32-01-23-45-67-89-0123'
|
|
227
|
+
* ```
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* Custom separator:
|
|
231
|
+
* ```typescript
|
|
232
|
+
* formatNIK('3201234567890123', ' ');
|
|
233
|
+
* // '32 01 23 45 67 89 0123'
|
|
234
|
+
* ```
|
|
235
|
+
*
|
|
236
|
+
* @example
|
|
237
|
+
* Invalid NIK returns as-is:
|
|
238
|
+
* ```typescript
|
|
239
|
+
* formatNIK('1234');
|
|
240
|
+
* // '1234'
|
|
241
|
+
* ```
|
|
242
|
+
*
|
|
243
|
+
* @public
|
|
244
|
+
*/
|
|
245
|
+
declare function formatNIK(nik: string, separator?: string): string;
|
|
246
|
+
/**
|
|
247
|
+
* Masks a NIK to protect privacy while keeping partial visibility.
|
|
248
|
+
*
|
|
249
|
+
* By default, shows the first 4 and last 4 digits, masking the middle 8.
|
|
250
|
+
* Optionally formats the masked NIK with separators.
|
|
251
|
+
*
|
|
252
|
+
* @param nik - The 16-digit NIK string to mask
|
|
253
|
+
* @param options - Masking configuration options
|
|
254
|
+
* @returns Masked NIK string, or original string if invalid format
|
|
255
|
+
*
|
|
256
|
+
* @example
|
|
257
|
+
* Default masking (first 4, last 4):
|
|
258
|
+
* ```typescript
|
|
259
|
+
* maskNIK('3201234567890123');
|
|
260
|
+
* // '3201********0123'
|
|
261
|
+
* ```
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* Custom mask character:
|
|
265
|
+
* ```typescript
|
|
266
|
+
* maskNIK('3201234567890123', { char: 'X' });
|
|
267
|
+
* // '3201XXXXXXXX0123'
|
|
268
|
+
* ```
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* With separator:
|
|
272
|
+
* ```typescript
|
|
273
|
+
* maskNIK('3201234567890123', { separator: '-' });
|
|
274
|
+
* // '32-01-**-**-**-**-0123'
|
|
275
|
+
* ```
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* Custom start and end:
|
|
279
|
+
* ```typescript
|
|
280
|
+
* maskNIK('3201234567890123', { start: 6, end: 4 });
|
|
281
|
+
* // '320123******0123'
|
|
282
|
+
* ```
|
|
283
|
+
*
|
|
284
|
+
* @public
|
|
285
|
+
*/
|
|
286
|
+
declare function maskNIK(nik: string, options?: MaskOptions): string;
|
|
287
|
+
|
|
288
|
+
export { type MaskOptions, type NIKInfo, formatNIK, maskNIK, parseNIK, validateNIK };
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates a NIK (Nomor Induk Kependudukan) format.
|
|
3
|
+
*
|
|
4
|
+
* A valid NIK must:
|
|
5
|
+
* - Be exactly 16 digits
|
|
6
|
+
* - Have a valid province code (positions 1-2)
|
|
7
|
+
* - Have a valid date (positions 7-12)
|
|
8
|
+
* - Not be in the future
|
|
9
|
+
* - Not be before 1900
|
|
10
|
+
*
|
|
11
|
+
* For female NIKs, the day is encoded as (actual day + 40).
|
|
12
|
+
* For example, a female born on the 15th would have day = 55.
|
|
13
|
+
*
|
|
14
|
+
* @param nik - The 16-digit NIK string to validate
|
|
15
|
+
* @returns `true` if the NIK is valid, `false` otherwise
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* validateNIK('3201234567890123'); // true - valid NIK
|
|
20
|
+
* validateNIK('1234'); // false - wrong length
|
|
21
|
+
* validateNIK('9912345678901234'); // false - invalid province
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
declare function validateNIK(nik: string): boolean;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Information extracted from a valid NIK.
|
|
30
|
+
*
|
|
31
|
+
* Contains parsed data including location codes, birth date, gender,
|
|
32
|
+
* and serial number from a 16-digit NIK string.
|
|
33
|
+
*
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
interface NIKInfo {
|
|
37
|
+
/**
|
|
38
|
+
* Province information extracted from positions 1-2 of the NIK.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* { code: '32', name: 'Jawa Barat' }
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
province: {
|
|
46
|
+
/** Two-digit province code (e.g., '32') */
|
|
47
|
+
code: string;
|
|
48
|
+
/** Full province name (e.g., 'Jawa Barat') */
|
|
49
|
+
name: string;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Regency (Kabupaten/Kota) information extracted from positions 3-4 of the NIK.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* { code: '01', name: 'Kab. Bogor' }
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
regency: {
|
|
60
|
+
/** Two-digit regency code (e.g., '01') */
|
|
61
|
+
code: string;
|
|
62
|
+
/** Full regency name (e.g., 'Kab. Bogor') */
|
|
63
|
+
name: string;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* District (Kecamatan) information extracted from positions 5-6 of the NIK.
|
|
67
|
+
* May be `null` if district data is not available.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* { code: '23', name: 'Ciawi' }
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
district: {
|
|
75
|
+
/** Two-digit district code (e.g., '23') */
|
|
76
|
+
code: string;
|
|
77
|
+
/** Full district name, or `null` if data unavailable */
|
|
78
|
+
name: string | null;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Birth date extracted from positions 7-12 of the NIK.
|
|
82
|
+
* For females, the day is encoded as (actual day + 40).
|
|
83
|
+
* Returns `null` if the date is invalid.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* new Date(1989, 0, 31) // January 31, 1989
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
birthDate: Date | null;
|
|
91
|
+
/**
|
|
92
|
+
* Gender derived from the day encoding in the NIK.
|
|
93
|
+
* - 'male': day is 1-31
|
|
94
|
+
* - 'female': day is 41-71 (actual day + 40)
|
|
95
|
+
* - `null`: if unable to determine
|
|
96
|
+
*/
|
|
97
|
+
gender: 'male' | 'female' | null;
|
|
98
|
+
/**
|
|
99
|
+
* Serial number from positions 13-16 of the NIK.
|
|
100
|
+
* Uniquely identifies individuals with the same location and birth date.
|
|
101
|
+
* Returns `null` if unable to extract.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* '0123'
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
serialNumber: string | null;
|
|
109
|
+
/**
|
|
110
|
+
* Whether the NIK passed validation checks.
|
|
111
|
+
* If `false`, other fields may be `null` or contain partial data.
|
|
112
|
+
*/
|
|
113
|
+
isValid: boolean;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Options for masking a NIK to protect privacy.
|
|
117
|
+
*
|
|
118
|
+
* Controls how many characters to show at the start and end,
|
|
119
|
+
* what character to use for masking, and optional separators.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* // Default: shows first 4 and last 4 digits
|
|
124
|
+
* { start: 4, end: 4, char: '*' }
|
|
125
|
+
* // Result: '3201********0123'
|
|
126
|
+
*
|
|
127
|
+
* // With separator
|
|
128
|
+
* { start: 4, end: 4, char: '*', separator: '-' }
|
|
129
|
+
* // Result: '3201-****-****-0123'
|
|
130
|
+
* ```
|
|
131
|
+
*
|
|
132
|
+
* @public
|
|
133
|
+
*/
|
|
134
|
+
interface MaskOptions {
|
|
135
|
+
/**
|
|
136
|
+
* Number of characters to show at the start.
|
|
137
|
+
*
|
|
138
|
+
* @defaultValue 4
|
|
139
|
+
*/
|
|
140
|
+
start?: number;
|
|
141
|
+
/**
|
|
142
|
+
* Number of characters to show at the end.
|
|
143
|
+
*
|
|
144
|
+
* @defaultValue 4
|
|
145
|
+
*/
|
|
146
|
+
end?: number;
|
|
147
|
+
/**
|
|
148
|
+
* Character to use for masking hidden digits.
|
|
149
|
+
*
|
|
150
|
+
* @defaultValue '*'
|
|
151
|
+
*/
|
|
152
|
+
char?: string;
|
|
153
|
+
/**
|
|
154
|
+
* Optional separator to add between groups of digits.
|
|
155
|
+
* If provided, the NIK will be formatted with separators.
|
|
156
|
+
*
|
|
157
|
+
* @defaultValue undefined (no separator)
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```typescript
|
|
161
|
+
* '-' // Results in format: '3201-****-****-0123'
|
|
162
|
+
* ' ' // Results in format: '3201 **** **** 0123'
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
separator?: string;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Parses a NIK and extracts all embedded information.
|
|
170
|
+
*
|
|
171
|
+
* Extracts province, regency, district codes, birth date, gender,
|
|
172
|
+
* and serial number from a 16-digit NIK string.
|
|
173
|
+
*
|
|
174
|
+
* @param nik - The 16-digit NIK string to parse
|
|
175
|
+
* @returns Parsed NIK information, or `null` if the NIK format is invalid
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* Parse a valid male NIK:
|
|
179
|
+
* ```typescript
|
|
180
|
+
* const info = parseNIK('3201018901310123');
|
|
181
|
+
* console.log(info);
|
|
182
|
+
* // {
|
|
183
|
+
* // province: { code: '32', name: 'Jawa Barat' },
|
|
184
|
+
* // regency: { code: '01', name: 'Kab. Bogor' },
|
|
185
|
+
* // district: { code: '01', name: null },
|
|
186
|
+
* // birthDate: Date(1989, 0, 31), // Jan 31, 1989
|
|
187
|
+
* // gender: 'male',
|
|
188
|
+
* // serialNumber: '0123',
|
|
189
|
+
* // isValid: true
|
|
190
|
+
* // }
|
|
191
|
+
* ```
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* Parse a female NIK (day + 40):
|
|
195
|
+
* ```typescript
|
|
196
|
+
* const info = parseNIK('3201019508550123');
|
|
197
|
+
* console.log(info.gender); // 'female'
|
|
198
|
+
* console.log(info.birthDate); // Date(1995, 7, 15) - Aug 15, 1995
|
|
199
|
+
* ```
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* Invalid NIK returns null:
|
|
203
|
+
* ```typescript
|
|
204
|
+
* const info = parseNIK('invalid');
|
|
205
|
+
* console.log(info); // null
|
|
206
|
+
* ```
|
|
207
|
+
*
|
|
208
|
+
* @public
|
|
209
|
+
*/
|
|
210
|
+
declare function parseNIK(nik: string): NIKInfo | null;
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Formats a NIK with separators for better readability.
|
|
214
|
+
*
|
|
215
|
+
* Groups the NIK into logical segments: province, regency, district,
|
|
216
|
+
* year, month, day, and serial number.
|
|
217
|
+
*
|
|
218
|
+
* @param nik - The 16-digit NIK string to format
|
|
219
|
+
* @param separator - Character to use as separator
|
|
220
|
+
* @returns Formatted NIK string, or original string if invalid format
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* Default separator (dash):
|
|
224
|
+
* ```typescript
|
|
225
|
+
* formatNIK('3201234567890123');
|
|
226
|
+
* // '32-01-23-45-67-89-0123'
|
|
227
|
+
* ```
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* Custom separator:
|
|
231
|
+
* ```typescript
|
|
232
|
+
* formatNIK('3201234567890123', ' ');
|
|
233
|
+
* // '32 01 23 45 67 89 0123'
|
|
234
|
+
* ```
|
|
235
|
+
*
|
|
236
|
+
* @example
|
|
237
|
+
* Invalid NIK returns as-is:
|
|
238
|
+
* ```typescript
|
|
239
|
+
* formatNIK('1234');
|
|
240
|
+
* // '1234'
|
|
241
|
+
* ```
|
|
242
|
+
*
|
|
243
|
+
* @public
|
|
244
|
+
*/
|
|
245
|
+
declare function formatNIK(nik: string, separator?: string): string;
|
|
246
|
+
/**
|
|
247
|
+
* Masks a NIK to protect privacy while keeping partial visibility.
|
|
248
|
+
*
|
|
249
|
+
* By default, shows the first 4 and last 4 digits, masking the middle 8.
|
|
250
|
+
* Optionally formats the masked NIK with separators.
|
|
251
|
+
*
|
|
252
|
+
* @param nik - The 16-digit NIK string to mask
|
|
253
|
+
* @param options - Masking configuration options
|
|
254
|
+
* @returns Masked NIK string, or original string if invalid format
|
|
255
|
+
*
|
|
256
|
+
* @example
|
|
257
|
+
* Default masking (first 4, last 4):
|
|
258
|
+
* ```typescript
|
|
259
|
+
* maskNIK('3201234567890123');
|
|
260
|
+
* // '3201********0123'
|
|
261
|
+
* ```
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* Custom mask character:
|
|
265
|
+
* ```typescript
|
|
266
|
+
* maskNIK('3201234567890123', { char: 'X' });
|
|
267
|
+
* // '3201XXXXXXXX0123'
|
|
268
|
+
* ```
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* With separator:
|
|
272
|
+
* ```typescript
|
|
273
|
+
* maskNIK('3201234567890123', { separator: '-' });
|
|
274
|
+
* // '32-01-**-**-**-**-0123'
|
|
275
|
+
* ```
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* Custom start and end:
|
|
279
|
+
* ```typescript
|
|
280
|
+
* maskNIK('3201234567890123', { start: 6, end: 4 });
|
|
281
|
+
* // '320123******0123'
|
|
282
|
+
* ```
|
|
283
|
+
*
|
|
284
|
+
* @public
|
|
285
|
+
*/
|
|
286
|
+
declare function maskNIK(nik: string, options?: MaskOptions): string;
|
|
287
|
+
|
|
288
|
+
export { type MaskOptions, type NIKInfo, formatNIK, maskNIK, parseNIK, validateNIK };
|