| 123456789101112131415161718192021222324252627282930313233 |
- const INVALID_TEXT_VALUES = new Set(['-', 'null', 'undefined']);
- const CERT_FIELD_KEYS = new Set([
- 'certno',
- 'personcertno',
- 'othercertno',
- 'selfcertno',
- 'querycertno',
- 'togethercertno',
- 'livewithcertno',
- 'objidcard',
- 'idcard',
- 'identitycode',
- 'sfz',
- ]);
- const normalizeSensitiveText = (value?: string | number | null) => {
- const text = String(value ?? '').trim();
- if (!text || INVALID_TEXT_VALUES.has(text.toLowerCase())) return '';
- return text;
- };
- export const isCertFieldKey = (value?: string | number | null) => {
- const text = normalizeSensitiveText(value);
- if (!text) return false;
- return CERT_FIELD_KEYS.has(text.replace(/[_-]/g, '').toLowerCase());
- };
- export const maskCertNo = (value?: string | number | null, keepStart = 4, keepEnd = 4) => {
- const text = normalizeSensitiveText(value);
- if (!text) return '-';
- if (text.length <= keepStart + keepEnd) return text;
- return `${text.slice(0, keepStart)}****${text.slice(-keepEnd)}`;
- };
|