feat: mask date of birth

This commit is contained in:
Michael Zetterberg
2024-08-27 10:55:46 +02:00
parent 68aa6e565d
commit ce3248562b
3 changed files with 19 additions and 3 deletions
+10 -2
View File
@@ -1,7 +1,11 @@
function maskAll(str: string) {
return "*".repeat(str.length)
}
function maskAllButFirstChar(str: string) {
const first = str[0]
const rest = str.substring(1)
const restMasked = "*".repeat(rest.length)
const restMasked = maskAll(rest)
return `${first}${restMasked}`
}
@@ -9,7 +13,7 @@ function maskAllButFirstChar(str: string) {
function maskAllButLastTwoChar(str: string) {
const lastTwo = str.slice(-2)
const rest = str.substring(0, str.length - 2)
const restMasked = "*".repeat(rest.length)
const restMasked = maskAll(rest)
return `${restMasked}${lastTwo}`
}
@@ -42,3 +46,7 @@ export function phone(str: string) {
export function text(str: string) {
return maskAllButFirstChar(str)
}
export function all(str: string) {
return maskAll(str)
}