Files
web/packages/common/utils/maskValue.ts
Anton Gunnarsson 1bd8fe6821 Merged in feat/sw-2879-booking-widget-to-booking-flow-package (pull request #2532)
feat(SW-2879): Move BookingWidget to booking-flow package

* Fix lockfile

* Fix styling

* a tiny little booking widget test

* Tiny fixes

* Merge branch 'master' into feat/sw-2879-booking-widget-to-booking-flow-package

* Remove unused scripts

* lint:fix

* Merge branch 'master' into feat/sw-2879-booking-widget-to-booking-flow-package

* Tiny lint fixes

* update test

* Update Input in booking-flow

* Clean up comments etc

* Merge branch 'master' into feat/sw-2879-booking-widget-to-booking-flow-package

* Setup tracking context for booking-flow

* Add missing use client

* Fix temp tracking function

* Pass booking to booking-widget

* Remove comment

* Add use client to booking widget tracking provider

* Add use client to tracking functions

* Merge branch 'master' into feat/sw-2879-booking-widget-to-booking-flow-package

* Move debug page

* Merge branch 'master' into feat/sw-2879-booking-widget-to-booking-flow-package

* Merge branch 'master' into feat/sw-2879-booking-widget-to-booking-flow-package

* Merge branch 'master' into feat/sw-2879-booking-widget-to-booking-flow-package


Approved-by: Bianca Widstam
2025-08-05 09:20:20 +00:00

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