Move user router to trpc package * Move more schemas in hotel router * Fix deps * fix getNonContentstackUrls * Fix import error * Fix entry error handling * Fix generateMetadata metrics * Fix alertType enum * Fix duplicated types * lint:fix * Merge branch 'master' into feat/sw-2863-move-contentstack-router-to-trpc-package * Fix broken imports * Move booking router to trpc package * Move partners router to trpc package * Move autocomplete router to trpc package * Move booking router to trpc package * Remove translations from My Pages navigation trpc procedure * Move navigation router to trpc package * Move user router to trpc package * Merge branch 'master' into feat/sw-2862-move-booking-router-to-trpc-package * Merge branch 'feat/sw-2862-move-booking-router-to-trpc-package' into feat/sw-2865-move-navigation-router-to-trpc-package * Merge branch 'master' into feat/sw-2865-move-navigation-router-to-trpc-package * Merge branch 'master' into feat/sw-2865-move-navigation-router-to-trpc-package * Merge branch 'master' into feat/sw-2865-move-navigation-router-to-trpc-package * Merge branch 'feat/sw-2865-move-navigation-router-to-trpc-package' into feat/sw-2867-move-user-router-to-trpc-package * Merge branch 'master' into feat/sw-2867-move-user-router-to-trpc-package Approved-by: Linus Flood
53 lines
1.1 KiB
TypeScript
53 lines
1.1 KiB
TypeScript
function maskAll(str: string) {
|
|
return "*".repeat(str.length)
|
|
}
|
|
|
|
function maskAllButFirstChar(str: string) {
|
|
const first = str[0]
|
|
const rest = str.substring(1)
|
|
const restMasked = maskAll(rest)
|
|
|
|
return `${first}${restMasked}`
|
|
}
|
|
|
|
function maskAllButLastTwoChar(str: string) {
|
|
const lastTwo = str.slice(-2)
|
|
const rest = str.substring(0, str.length - 2)
|
|
const restMasked = maskAll(rest)
|
|
|
|
return `${restMasked}${lastTwo}`
|
|
}
|
|
|
|
export function email(str: string) {
|
|
const parts = str.split("@")
|
|
|
|
const aliasMasked = maskAllButFirstChar(parts[0])
|
|
|
|
if (parts[1]) {
|
|
const domainParts = parts[1].split(".")
|
|
if (domainParts.length > 1) {
|
|
const domainTLD = domainParts.pop()
|
|
const domainPartsMasked = domainParts
|
|
.map((domainPart, i) => {
|
|
return maskAllButFirstChar(domainPart)
|
|
})
|
|
.join(".")
|
|
return `${aliasMasked}@${domainPartsMasked}.${domainTLD}`
|
|
}
|
|
}
|
|
|
|
return maskAllButFirstChar(str)
|
|
}
|
|
|
|
export function phone(str: string) {
|
|
return maskAllButLastTwoChar(str)
|
|
}
|
|
|
|
export function text(str: string) {
|
|
return maskAllButFirstChar(str)
|
|
}
|
|
|
|
export function all(str: string) {
|
|
return maskAll(str)
|
|
}
|