mask
Masks a Driving License number for PII-safe display.
DL is a Private government ID (Photo ID + address proof) — always mask before displaying in UI or logging to ensure compliance with PII handling requirements.
Masking operates on the raw input string (not normalised). This is intentional — the masker is a display utility that works character-by-character on whatever string it receives. Callers who want to mask a normalised DL should call format first: DL.mask(DL.format(value)).
Default (visibleStart=0, visibleEnd=4, maskChar='X'): Shows last 4 characters, masks the rest. "MH1220110012345" → "XXXXXXXXXXX2345" (last 4: "2345")
Edge cases (all safe — never throws):
Empty input → returns
"".visibleStart + visibleEnd >= value.length→ entire string returned unmasked (overlap rule).Non-normalised input (lowercase, hyphens, spaces) → masking applied character-by-character on the raw string. No normalisation is performed.
Return
Masked string. Never throws — display-safe by contract.
Parameters
Raw DL string to mask. No normalisation is applied.
Number of leading characters to show unmasked. Default: 0.
Number of trailing characters to show unmasked. Default: 4.
Character to replace masked positions. Default: 'X'.
Samples
println(DL.mask("MH0120230012345"))