@@ -331,6 +331,9 @@ export const userQueryRouter = router({
|
|||||||
user.address.zipCode = verifiedData.data.address?.zipCode
|
user.address.zipCode = verifiedData.data.address?.zipCode
|
||||||
? maskValue.text(verifiedData.data.address.zipCode)
|
? maskValue.text(verifiedData.data.address.zipCode)
|
||||||
: ""
|
: ""
|
||||||
|
|
||||||
|
user.dateOfBirth = maskValue.all(user.dateOfBirth)
|
||||||
|
|
||||||
user.email = maskValue.email(user.email)
|
user.email = maskValue.email(user.email)
|
||||||
|
|
||||||
user.phoneNumber = user.phoneNumber
|
user.phoneNumber = user.phoneNumber
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
|
function maskAll(str: string) {
|
||||||
|
return "*".repeat(str.length)
|
||||||
|
}
|
||||||
|
|
||||||
function maskAllButFirstChar(str: string) {
|
function maskAllButFirstChar(str: string) {
|
||||||
const first = str[0]
|
const first = str[0]
|
||||||
const rest = str.substring(1)
|
const rest = str.substring(1)
|
||||||
const restMasked = "*".repeat(rest.length)
|
const restMasked = maskAll(rest)
|
||||||
|
|
||||||
return `${first}${restMasked}`
|
return `${first}${restMasked}`
|
||||||
}
|
}
|
||||||
@@ -9,7 +13,7 @@ function maskAllButFirstChar(str: string) {
|
|||||||
function maskAllButLastTwoChar(str: string) {
|
function maskAllButLastTwoChar(str: string) {
|
||||||
const lastTwo = str.slice(-2)
|
const lastTwo = str.slice(-2)
|
||||||
const rest = str.substring(0, str.length - 2)
|
const rest = str.substring(0, str.length - 2)
|
||||||
const restMasked = "*".repeat(rest.length)
|
const restMasked = maskAll(rest)
|
||||||
|
|
||||||
return `${restMasked}${lastTwo}`
|
return `${restMasked}${lastTwo}`
|
||||||
}
|
}
|
||||||
@@ -42,3 +46,7 @@ export function phone(str: string) {
|
|||||||
export function text(str: string) {
|
export function text(str: string) {
|
||||||
return maskAllButFirstChar(str)
|
return maskAllButFirstChar(str)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function all(str: string) {
|
||||||
|
return maskAll(str)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { describe, expect, test } from "@jest/globals"
|
import { describe, expect, test } from "@jest/globals"
|
||||||
|
|
||||||
import { email, phone, text } from "./maskValue"
|
import { all, email, phone, text } from "./maskValue"
|
||||||
|
|
||||||
describe("Mask value", () => {
|
describe("Mask value", () => {
|
||||||
test("masks e-mails properly", () => {
|
test("masks e-mails properly", () => {
|
||||||
@@ -19,4 +19,9 @@ describe("Mask value", () => {
|
|||||||
expect(text("test")).toBe("t***")
|
expect(text("test")).toBe("t***")
|
||||||
expect(text("test.with.dot")).toBe("t************")
|
expect(text("test.with.dot")).toBe("t************")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("masks whole string properly", () => {
|
||||||
|
expect(all("test")).toBe("****")
|
||||||
|
expect(all("123jknasd@iajsd.c")).toBe("*****************")
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user