@ghifari29/id-kit 0.2.0 → 0.3.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 +15 -0
- package/dist/chunk-RR7TOTVK.js +75 -0
- package/dist/index.cjs +73 -0
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +14 -4
- package/dist/mask.cjs +111 -0
- package/dist/mask.d.cts +45 -0
- package/dist/mask.d.ts +45 -0
- package/dist/mask.js +13 -0
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -18,6 +18,7 @@ npm i @ghifari29/id-kit
|
|
|
18
18
|
import { terbilang, rupiah } from "@ghifari29/id-kit/format";
|
|
19
19
|
import { normalizePhone, isValidPhone } from "@ghifari29/id-kit/phone";
|
|
20
20
|
import { parseNIK, isValidNIK } from "@ghifari29/id-kit/nik";
|
|
21
|
+
import { mask, maskNIK, maskPhone, maskAccount } from "@ghifari29/id-kit/mask";
|
|
21
22
|
|
|
22
23
|
terbilang(1250000);
|
|
23
24
|
// "satu juta dua ratus lima puluh ribu rupiah"
|
|
@@ -36,6 +37,18 @@ isValidNIK("3171011505900001");
|
|
|
36
37
|
|
|
37
38
|
parseNIK("3201025505900002");
|
|
38
39
|
// { valid: true, provinsiKode: "32", provinsi: "Jawa Barat", kabKotaKode: "01", kecamatanKode: "02", tanggalLahir: "1990-05-15", gender: "P", urutan: "0002" }
|
|
40
|
+
|
|
41
|
+
mask("rahasia", { visibleStart: 1, visibleEnd: 1 });
|
|
42
|
+
// "r*****a"
|
|
43
|
+
|
|
44
|
+
maskNIK("3171 0115 0590 0001");
|
|
45
|
+
// "3171********0001"
|
|
46
|
+
|
|
47
|
+
maskPhone("0812-3456-789");
|
|
48
|
+
// "+628******789"
|
|
49
|
+
|
|
50
|
+
maskAccount("123-456-7890");
|
|
51
|
+
// "******7890"
|
|
39
52
|
```
|
|
40
53
|
|
|
41
54
|
## Fitur
|
|
@@ -43,6 +56,7 @@ parseNIK("3201025505900002");
|
|
|
43
56
|
- [x] `terbilang`, `rupiah`
|
|
44
57
|
- [x] `normalizePhone`, `isValidPhone`
|
|
45
58
|
- [x] `parseNIK`, `isValidNIK` (validasi NIK)
|
|
59
|
+
- [x] `mask`, `maskNIK`, `maskPhone`, `maskAccount` (masking data pribadi)
|
|
46
60
|
- [ ] Deteksi operator seluler
|
|
47
61
|
- [ ] Validasi NPWP dan nomor rekening
|
|
48
62
|
- [ ] Libur nasional dan cuti bersama
|
|
@@ -53,6 +67,7 @@ parseNIK("3201025505900002");
|
|
|
53
67
|
- `terbilang` hanya mendukung bilangan bulat.
|
|
54
68
|
- `normalizePhone` hanya mengecek pola umum nomor seluler, belum memastikan awalan operator.
|
|
55
69
|
- `parseNIK` dan `isValidNIK` hanya memvalidasi format struktur NIK (bukan bukti keaslian atau keterdaftaran di Dukcapil). Kode kabupaten/kota dan kecamatan tidak divalidasi, dan penentuan abad tahun 2 digit (`YY`) bersifat heuristik terhadap tahun berjalan (UTC).
|
|
70
|
+
- Modul `mask` (`mask`, `maskNIK`, `maskPhone`, `maskAccount`) hanya untuk **TAMPILAN** UI, bukan enkripsi atau anonimisasi. Jangan menyimpan data asli di log hanya karena sudah ada fungsi masking. Hanya `mask()` yang menjamin panjang hasil (dalam Unicode code point) sama dengan panjang input.
|
|
56
71
|
|
|
57
72
|
## Berkontribusi
|
|
58
73
|
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import {
|
|
2
|
+
normalizePhone
|
|
3
|
+
} from "./chunk-GH7ECGI2.js";
|
|
4
|
+
|
|
5
|
+
// src/mask/mask.ts
|
|
6
|
+
function assertString(input) {
|
|
7
|
+
if (typeof input !== "string") {
|
|
8
|
+
throw new TypeError("Input harus berupa string");
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function validateVisibleCount(value, name) {
|
|
12
|
+
if (!Number.isInteger(value) || value < 0) {
|
|
13
|
+
throw new RangeError(`${name} harus berupa bilangan bulat non-negatif`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function validateMaskChar(maskChar) {
|
|
17
|
+
if (typeof maskChar !== "string") {
|
|
18
|
+
throw new TypeError("maskChar harus berupa string");
|
|
19
|
+
}
|
|
20
|
+
if (Array.from(maskChar).length !== 1) {
|
|
21
|
+
throw new RangeError("maskChar harus tepat satu karakter Unicode");
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function fullMask(input, maskChar = "*") {
|
|
25
|
+
return maskChar.repeat(Array.from(input).length);
|
|
26
|
+
}
|
|
27
|
+
function mask(input, options = {}) {
|
|
28
|
+
assertString(input);
|
|
29
|
+
const { visibleStart = 0, visibleEnd = 0, maskChar = "*" } = options;
|
|
30
|
+
validateVisibleCount(visibleStart, "visibleStart");
|
|
31
|
+
validateVisibleCount(visibleEnd, "visibleEnd");
|
|
32
|
+
validateMaskChar(maskChar);
|
|
33
|
+
const chars = Array.from(input);
|
|
34
|
+
if (chars.length === 0) {
|
|
35
|
+
return "";
|
|
36
|
+
}
|
|
37
|
+
if (chars.length <= visibleStart + visibleEnd) {
|
|
38
|
+
return maskChar.repeat(chars.length);
|
|
39
|
+
}
|
|
40
|
+
const start = chars.slice(0, visibleStart).join("");
|
|
41
|
+
const end = visibleEnd > 0 ? chars.slice(-visibleEnd).join("") : "";
|
|
42
|
+
const middle = maskChar.repeat(chars.length - visibleStart - visibleEnd);
|
|
43
|
+
return start + middle + end;
|
|
44
|
+
}
|
|
45
|
+
function maskNIK(input) {
|
|
46
|
+
assertString(input);
|
|
47
|
+
const cleaned = input.replace(/\s+/g, "");
|
|
48
|
+
if (!/^\d{16}$/.test(cleaned)) {
|
|
49
|
+
return fullMask(input);
|
|
50
|
+
}
|
|
51
|
+
return mask(cleaned, { visibleStart: 4, visibleEnd: 4 });
|
|
52
|
+
}
|
|
53
|
+
function maskPhone(input) {
|
|
54
|
+
assertString(input);
|
|
55
|
+
const normalized = normalizePhone(input);
|
|
56
|
+
if (!normalized) {
|
|
57
|
+
return fullMask(input);
|
|
58
|
+
}
|
|
59
|
+
return mask(normalized, { visibleStart: 4, visibleEnd: 3 });
|
|
60
|
+
}
|
|
61
|
+
function maskAccount(input) {
|
|
62
|
+
assertString(input);
|
|
63
|
+
const cleaned = input.replace(/[\s-]+/g, "");
|
|
64
|
+
if (cleaned.length < 8 || !/^\d+$/.test(cleaned)) {
|
|
65
|
+
return fullMask(input);
|
|
66
|
+
}
|
|
67
|
+
return mask(cleaned, { visibleStart: 0, visibleEnd: 4 });
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export {
|
|
71
|
+
mask,
|
|
72
|
+
maskNIK,
|
|
73
|
+
maskPhone,
|
|
74
|
+
maskAccount
|
|
75
|
+
};
|
package/dist/index.cjs
CHANGED
|
@@ -22,6 +22,10 @@ var src_exports = {};
|
|
|
22
22
|
__export(src_exports, {
|
|
23
23
|
isValidNIK: () => isValidNIK,
|
|
24
24
|
isValidPhone: () => isValidPhone,
|
|
25
|
+
mask: () => mask,
|
|
26
|
+
maskAccount: () => maskAccount,
|
|
27
|
+
maskNIK: () => maskNIK,
|
|
28
|
+
maskPhone: () => maskPhone,
|
|
25
29
|
normalizePhone: () => normalizePhone,
|
|
26
30
|
parseNIK: () => parseNIK,
|
|
27
31
|
rupiah: () => rupiah,
|
|
@@ -195,10 +199,79 @@ function parseNIK(input) {
|
|
|
195
199
|
function isValidNIK(input) {
|
|
196
200
|
return parseNIK(input).valid;
|
|
197
201
|
}
|
|
202
|
+
|
|
203
|
+
// src/mask/mask.ts
|
|
204
|
+
function assertString(input) {
|
|
205
|
+
if (typeof input !== "string") {
|
|
206
|
+
throw new TypeError("Input harus berupa string");
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
function validateVisibleCount(value, name) {
|
|
210
|
+
if (!Number.isInteger(value) || value < 0) {
|
|
211
|
+
throw new RangeError(`${name} harus berupa bilangan bulat non-negatif`);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
function validateMaskChar(maskChar) {
|
|
215
|
+
if (typeof maskChar !== "string") {
|
|
216
|
+
throw new TypeError("maskChar harus berupa string");
|
|
217
|
+
}
|
|
218
|
+
if (Array.from(maskChar).length !== 1) {
|
|
219
|
+
throw new RangeError("maskChar harus tepat satu karakter Unicode");
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
function fullMask(input, maskChar = "*") {
|
|
223
|
+
return maskChar.repeat(Array.from(input).length);
|
|
224
|
+
}
|
|
225
|
+
function mask(input, options = {}) {
|
|
226
|
+
assertString(input);
|
|
227
|
+
const { visibleStart = 0, visibleEnd = 0, maskChar = "*" } = options;
|
|
228
|
+
validateVisibleCount(visibleStart, "visibleStart");
|
|
229
|
+
validateVisibleCount(visibleEnd, "visibleEnd");
|
|
230
|
+
validateMaskChar(maskChar);
|
|
231
|
+
const chars = Array.from(input);
|
|
232
|
+
if (chars.length === 0) {
|
|
233
|
+
return "";
|
|
234
|
+
}
|
|
235
|
+
if (chars.length <= visibleStart + visibleEnd) {
|
|
236
|
+
return maskChar.repeat(chars.length);
|
|
237
|
+
}
|
|
238
|
+
const start = chars.slice(0, visibleStart).join("");
|
|
239
|
+
const end = visibleEnd > 0 ? chars.slice(-visibleEnd).join("") : "";
|
|
240
|
+
const middle = maskChar.repeat(chars.length - visibleStart - visibleEnd);
|
|
241
|
+
return start + middle + end;
|
|
242
|
+
}
|
|
243
|
+
function maskNIK(input) {
|
|
244
|
+
assertString(input);
|
|
245
|
+
const cleaned = input.replace(/\s+/g, "");
|
|
246
|
+
if (!/^\d{16}$/.test(cleaned)) {
|
|
247
|
+
return fullMask(input);
|
|
248
|
+
}
|
|
249
|
+
return mask(cleaned, { visibleStart: 4, visibleEnd: 4 });
|
|
250
|
+
}
|
|
251
|
+
function maskPhone(input) {
|
|
252
|
+
assertString(input);
|
|
253
|
+
const normalized = normalizePhone(input);
|
|
254
|
+
if (!normalized) {
|
|
255
|
+
return fullMask(input);
|
|
256
|
+
}
|
|
257
|
+
return mask(normalized, { visibleStart: 4, visibleEnd: 3 });
|
|
258
|
+
}
|
|
259
|
+
function maskAccount(input) {
|
|
260
|
+
assertString(input);
|
|
261
|
+
const cleaned = input.replace(/[\s-]+/g, "");
|
|
262
|
+
if (cleaned.length < 8 || !/^\d+$/.test(cleaned)) {
|
|
263
|
+
return fullMask(input);
|
|
264
|
+
}
|
|
265
|
+
return mask(cleaned, { visibleStart: 0, visibleEnd: 4 });
|
|
266
|
+
}
|
|
198
267
|
// Annotate the CommonJS export names for ESM import in node:
|
|
199
268
|
0 && (module.exports = {
|
|
200
269
|
isValidNIK,
|
|
201
270
|
isValidPhone,
|
|
271
|
+
mask,
|
|
272
|
+
maskAccount,
|
|
273
|
+
maskNIK,
|
|
274
|
+
maskPhone,
|
|
202
275
|
normalizePhone,
|
|
203
276
|
parseNIK,
|
|
204
277
|
rupiah,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { rupiah, terbilang } from './format.cjs';
|
|
2
2
|
export { isValidPhone, normalizePhone } from './phone.cjs';
|
|
3
3
|
export { NIKGender, NIKInvalidReason, ParseNIKResult, isValidNIK, parseNIK } from './nik.cjs';
|
|
4
|
+
export { MaskOptions, mask, maskAccount, maskNIK, maskPhone } from './mask.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { rupiah, terbilang } from './format.js';
|
|
2
2
|
export { isValidPhone, normalizePhone } from './phone.js';
|
|
3
3
|
export { NIKGender, NIKInvalidReason, ParseNIKResult, isValidNIK, parseNIK } from './nik.js';
|
|
4
|
+
export { MaskOptions, mask, maskAccount, maskNIK, maskPhone } from './mask.js';
|
package/dist/index.js
CHANGED
|
@@ -2,17 +2,27 @@ import {
|
|
|
2
2
|
rupiah,
|
|
3
3
|
terbilang
|
|
4
4
|
} from "./chunk-3347TRCX.js";
|
|
5
|
-
import {
|
|
6
|
-
isValidPhone,
|
|
7
|
-
normalizePhone
|
|
8
|
-
} from "./chunk-GH7ECGI2.js";
|
|
9
5
|
import {
|
|
10
6
|
isValidNIK,
|
|
11
7
|
parseNIK
|
|
12
8
|
} from "./chunk-ZIB7HJMG.js";
|
|
9
|
+
import {
|
|
10
|
+
mask,
|
|
11
|
+
maskAccount,
|
|
12
|
+
maskNIK,
|
|
13
|
+
maskPhone
|
|
14
|
+
} from "./chunk-RR7TOTVK.js";
|
|
15
|
+
import {
|
|
16
|
+
isValidPhone,
|
|
17
|
+
normalizePhone
|
|
18
|
+
} from "./chunk-GH7ECGI2.js";
|
|
13
19
|
export {
|
|
14
20
|
isValidNIK,
|
|
15
21
|
isValidPhone,
|
|
22
|
+
mask,
|
|
23
|
+
maskAccount,
|
|
24
|
+
maskNIK,
|
|
25
|
+
maskPhone,
|
|
16
26
|
normalizePhone,
|
|
17
27
|
parseNIK,
|
|
18
28
|
rupiah,
|
package/dist/mask.cjs
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/mask/index.ts
|
|
21
|
+
var mask_exports = {};
|
|
22
|
+
__export(mask_exports, {
|
|
23
|
+
mask: () => mask,
|
|
24
|
+
maskAccount: () => maskAccount,
|
|
25
|
+
maskNIK: () => maskNIK,
|
|
26
|
+
maskPhone: () => maskPhone
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(mask_exports);
|
|
29
|
+
|
|
30
|
+
// src/phone/index.ts
|
|
31
|
+
function normalizePhone(input) {
|
|
32
|
+
let d = input.replace(/[^\d+]/g, "");
|
|
33
|
+
if (d.startsWith("+62")) d = d.slice(3);
|
|
34
|
+
else if (d.startsWith("62")) d = d.slice(2);
|
|
35
|
+
else if (d.startsWith("0")) d = d.slice(1);
|
|
36
|
+
else return null;
|
|
37
|
+
if (!/^8\d{8,11}$/.test(d)) return null;
|
|
38
|
+
return "+62" + d;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// src/mask/mask.ts
|
|
42
|
+
function assertString(input) {
|
|
43
|
+
if (typeof input !== "string") {
|
|
44
|
+
throw new TypeError("Input harus berupa string");
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function validateVisibleCount(value, name) {
|
|
48
|
+
if (!Number.isInteger(value) || value < 0) {
|
|
49
|
+
throw new RangeError(`${name} harus berupa bilangan bulat non-negatif`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function validateMaskChar(maskChar) {
|
|
53
|
+
if (typeof maskChar !== "string") {
|
|
54
|
+
throw new TypeError("maskChar harus berupa string");
|
|
55
|
+
}
|
|
56
|
+
if (Array.from(maskChar).length !== 1) {
|
|
57
|
+
throw new RangeError("maskChar harus tepat satu karakter Unicode");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function fullMask(input, maskChar = "*") {
|
|
61
|
+
return maskChar.repeat(Array.from(input).length);
|
|
62
|
+
}
|
|
63
|
+
function mask(input, options = {}) {
|
|
64
|
+
assertString(input);
|
|
65
|
+
const { visibleStart = 0, visibleEnd = 0, maskChar = "*" } = options;
|
|
66
|
+
validateVisibleCount(visibleStart, "visibleStart");
|
|
67
|
+
validateVisibleCount(visibleEnd, "visibleEnd");
|
|
68
|
+
validateMaskChar(maskChar);
|
|
69
|
+
const chars = Array.from(input);
|
|
70
|
+
if (chars.length === 0) {
|
|
71
|
+
return "";
|
|
72
|
+
}
|
|
73
|
+
if (chars.length <= visibleStart + visibleEnd) {
|
|
74
|
+
return maskChar.repeat(chars.length);
|
|
75
|
+
}
|
|
76
|
+
const start = chars.slice(0, visibleStart).join("");
|
|
77
|
+
const end = visibleEnd > 0 ? chars.slice(-visibleEnd).join("") : "";
|
|
78
|
+
const middle = maskChar.repeat(chars.length - visibleStart - visibleEnd);
|
|
79
|
+
return start + middle + end;
|
|
80
|
+
}
|
|
81
|
+
function maskNIK(input) {
|
|
82
|
+
assertString(input);
|
|
83
|
+
const cleaned = input.replace(/\s+/g, "");
|
|
84
|
+
if (!/^\d{16}$/.test(cleaned)) {
|
|
85
|
+
return fullMask(input);
|
|
86
|
+
}
|
|
87
|
+
return mask(cleaned, { visibleStart: 4, visibleEnd: 4 });
|
|
88
|
+
}
|
|
89
|
+
function maskPhone(input) {
|
|
90
|
+
assertString(input);
|
|
91
|
+
const normalized = normalizePhone(input);
|
|
92
|
+
if (!normalized) {
|
|
93
|
+
return fullMask(input);
|
|
94
|
+
}
|
|
95
|
+
return mask(normalized, { visibleStart: 4, visibleEnd: 3 });
|
|
96
|
+
}
|
|
97
|
+
function maskAccount(input) {
|
|
98
|
+
assertString(input);
|
|
99
|
+
const cleaned = input.replace(/[\s-]+/g, "");
|
|
100
|
+
if (cleaned.length < 8 || !/^\d+$/.test(cleaned)) {
|
|
101
|
+
return fullMask(input);
|
|
102
|
+
}
|
|
103
|
+
return mask(cleaned, { visibleStart: 0, visibleEnd: 4 });
|
|
104
|
+
}
|
|
105
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
106
|
+
0 && (module.exports = {
|
|
107
|
+
mask,
|
|
108
|
+
maskAccount,
|
|
109
|
+
maskNIK,
|
|
110
|
+
maskPhone
|
|
111
|
+
});
|
package/dist/mask.d.cts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
interface MaskOptions {
|
|
2
|
+
/** Jumlah karakter awal yang tetap ditampilkan. Default: `0`. */
|
|
3
|
+
visibleStart?: number;
|
|
4
|
+
/** Jumlah karakter akhir yang tetap ditampilkan. Default: `0`. */
|
|
5
|
+
visibleEnd?: number;
|
|
6
|
+
/** Karakter pengganti untuk bagian yang disensor (harus tepat 1 Unicode code point). Default: `"*"`. */
|
|
7
|
+
maskChar?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Menyensor string untuk kebutuhan tampilan UI.
|
|
11
|
+
*
|
|
12
|
+
* Catatan keamanan & perilaku:
|
|
13
|
+
* - Hanya untuk tampilan, bukan enkripsi atau anonimisasi.
|
|
14
|
+
* - Jika panjang input (dalam Unicode code point) `<= visibleStart + visibleEnd`, seluruh input disensor.
|
|
15
|
+
* - Hanya `mask()` yang menjamin panjang hasil (dalam code point) sama dengan panjang input.
|
|
16
|
+
* - Panjang dihitung per code point via `Array.from`; grapheme cluster gabungan (seperti bendera atau emoji ZWJ)
|
|
17
|
+
* dihitung per code point penyusunnya.
|
|
18
|
+
*/
|
|
19
|
+
declare function mask(input: string, options?: MaskOptions): string;
|
|
20
|
+
/**
|
|
21
|
+
* Menyensor NIK 16 digit untuk tampilan UI dengan menampilkan 4 digit awal dan 4 digit akhir.
|
|
22
|
+
*
|
|
23
|
+
* Whitespace (`\s`) dibuang sebelum pemeriksaan. Jika hasilnya bukan tepat 16 digit angka,
|
|
24
|
+
* seluruh input disensor penuh sepanjang input asli (`Array.from(input).length`) tanpa validasi Dukcapil.
|
|
25
|
+
* Hanya untuk tampilan UI, bukan enkripsi atau anonimisasi.
|
|
26
|
+
*/
|
|
27
|
+
declare function maskNIK(input: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* Menyensor nomor seluler Indonesia untuk tampilan UI dalam format `+628...` dengan 3 digit akhir terlihat.
|
|
30
|
+
*
|
|
31
|
+
* Memakai `normalizePhone` dari modul `phone`. Jika nomor tidak valid, seluruh input disensor penuh
|
|
32
|
+
* sepanjang input asli (`Array.from(input).length`) tanpa melempar error.
|
|
33
|
+
* Hanya untuk tampilan UI, bukan enkripsi atau anonimisasi.
|
|
34
|
+
*/
|
|
35
|
+
declare function maskPhone(input: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* Menyensor nomor rekening untuk tampilan UI dengan hanya menampilkan 4 digit terakhir.
|
|
38
|
+
*
|
|
39
|
+
* Spasi dan tanda hubung (`-`) dibuang terlebih dahulu. Jika mengandung karakter non-angka atau
|
|
40
|
+
* panjang setelah dibersihkan kurang dari 8 digit, seluruh input disensor penuh sepanjang input asli.
|
|
41
|
+
* Hanya untuk tampilan UI, bukan enkripsi atau anonimisasi.
|
|
42
|
+
*/
|
|
43
|
+
declare function maskAccount(input: string): string;
|
|
44
|
+
|
|
45
|
+
export { type MaskOptions, mask, maskAccount, maskNIK, maskPhone };
|
package/dist/mask.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
interface MaskOptions {
|
|
2
|
+
/** Jumlah karakter awal yang tetap ditampilkan. Default: `0`. */
|
|
3
|
+
visibleStart?: number;
|
|
4
|
+
/** Jumlah karakter akhir yang tetap ditampilkan. Default: `0`. */
|
|
5
|
+
visibleEnd?: number;
|
|
6
|
+
/** Karakter pengganti untuk bagian yang disensor (harus tepat 1 Unicode code point). Default: `"*"`. */
|
|
7
|
+
maskChar?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Menyensor string untuk kebutuhan tampilan UI.
|
|
11
|
+
*
|
|
12
|
+
* Catatan keamanan & perilaku:
|
|
13
|
+
* - Hanya untuk tampilan, bukan enkripsi atau anonimisasi.
|
|
14
|
+
* - Jika panjang input (dalam Unicode code point) `<= visibleStart + visibleEnd`, seluruh input disensor.
|
|
15
|
+
* - Hanya `mask()` yang menjamin panjang hasil (dalam code point) sama dengan panjang input.
|
|
16
|
+
* - Panjang dihitung per code point via `Array.from`; grapheme cluster gabungan (seperti bendera atau emoji ZWJ)
|
|
17
|
+
* dihitung per code point penyusunnya.
|
|
18
|
+
*/
|
|
19
|
+
declare function mask(input: string, options?: MaskOptions): string;
|
|
20
|
+
/**
|
|
21
|
+
* Menyensor NIK 16 digit untuk tampilan UI dengan menampilkan 4 digit awal dan 4 digit akhir.
|
|
22
|
+
*
|
|
23
|
+
* Whitespace (`\s`) dibuang sebelum pemeriksaan. Jika hasilnya bukan tepat 16 digit angka,
|
|
24
|
+
* seluruh input disensor penuh sepanjang input asli (`Array.from(input).length`) tanpa validasi Dukcapil.
|
|
25
|
+
* Hanya untuk tampilan UI, bukan enkripsi atau anonimisasi.
|
|
26
|
+
*/
|
|
27
|
+
declare function maskNIK(input: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* Menyensor nomor seluler Indonesia untuk tampilan UI dalam format `+628...` dengan 3 digit akhir terlihat.
|
|
30
|
+
*
|
|
31
|
+
* Memakai `normalizePhone` dari modul `phone`. Jika nomor tidak valid, seluruh input disensor penuh
|
|
32
|
+
* sepanjang input asli (`Array.from(input).length`) tanpa melempar error.
|
|
33
|
+
* Hanya untuk tampilan UI, bukan enkripsi atau anonimisasi.
|
|
34
|
+
*/
|
|
35
|
+
declare function maskPhone(input: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* Menyensor nomor rekening untuk tampilan UI dengan hanya menampilkan 4 digit terakhir.
|
|
38
|
+
*
|
|
39
|
+
* Spasi dan tanda hubung (`-`) dibuang terlebih dahulu. Jika mengandung karakter non-angka atau
|
|
40
|
+
* panjang setelah dibersihkan kurang dari 8 digit, seluruh input disensor penuh sepanjang input asli.
|
|
41
|
+
* Hanya untuk tampilan UI, bukan enkripsi atau anonimisasi.
|
|
42
|
+
*/
|
|
43
|
+
declare function maskAccount(input: string): string;
|
|
44
|
+
|
|
45
|
+
export { type MaskOptions, mask, maskAccount, maskNIK, maskPhone };
|
package/dist/mask.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ghifari29/id-kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Utilitas Indonesia: terbilang, rupiah, nomor telepon, dan lainnya",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -30,6 +30,11 @@
|
|
|
30
30
|
"types": "./dist/nik.d.ts",
|
|
31
31
|
"import": "./dist/nik.js",
|
|
32
32
|
"require": "./dist/nik.cjs"
|
|
33
|
+
},
|
|
34
|
+
"./mask": {
|
|
35
|
+
"types": "./dist/mask.d.ts",
|
|
36
|
+
"import": "./dist/mask.js",
|
|
37
|
+
"require": "./dist/mask.cjs"
|
|
33
38
|
}
|
|
34
39
|
},
|
|
35
40
|
"scripts": {
|