Merged in feat/mask-dob (pull request #516)

feat: mask date of birth
This commit is contained in:
Michael Zetterberg
2024-08-27 10:19:42 +00:00
3 changed files with 19 additions and 3 deletions

View File

@@ -331,6 +331,9 @@ export const userQueryRouter = router({
user.address.zipCode = verifiedData.data.address?.zipCode
? maskValue.text(verifiedData.data.address.zipCode)
: ""
user.dateOfBirth = maskValue.all(user.dateOfBirth)
user.email = maskValue.email(user.email)
user.phoneNumber = user.phoneNumber

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)
}

View File

@@ -1,6 +1,6 @@
import { describe, expect, test } from "@jest/globals"
import { email, phone, text } from "./maskValue"
import { all, email, phone, text } from "./maskValue"
describe("Mask value", () => {
test("masks e-mails properly", () => {
@@ -19,4 +19,9 @@ describe("Mask value", () => {
expect(text("test")).toBe("t***")
expect(text("test.with.dot")).toBe("t************")
})
test("masks whole string properly", () => {
expect(all("test")).toBe("****")
expect(all("123jknasd@iajsd.c")).toBe("*****************")
})
})