deduplicate task parsing and masking helpers
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
type MaskPhoneOptions = {
|
||||
maskShort?: boolean
|
||||
shortMask?: string
|
||||
}
|
||||
|
||||
type MaskCodeOptions = {
|
||||
shortMask?: string
|
||||
}
|
||||
|
||||
export function maskSecret(value: unknown): string {
|
||||
const normalized = String(value || '').trim()
|
||||
if (!normalized) {
|
||||
return ''
|
||||
}
|
||||
|
||||
if (normalized.length <= 10) {
|
||||
return `${normalized.slice(0, 2)}****${normalized.slice(-2)}`
|
||||
}
|
||||
|
||||
return `${normalized.slice(0, 6)}****${normalized.slice(-6)}`
|
||||
}
|
||||
|
||||
export function maskPhone(value: unknown, options: MaskPhoneOptions = {}): string {
|
||||
const text = String(value || '').trim()
|
||||
if (!text) {
|
||||
return ''
|
||||
}
|
||||
|
||||
if (text.length <= 7) {
|
||||
if (options.maskShort === false) {
|
||||
return text
|
||||
}
|
||||
|
||||
return `${text.slice(0, 2)}${options.shortMask || '***'}${text.slice(-2)}`
|
||||
}
|
||||
|
||||
return `${text.slice(0, 3)}****${text.slice(-4)}`
|
||||
}
|
||||
|
||||
export function maskCode(value: unknown, options: MaskCodeOptions = {}): string {
|
||||
const text = String(value || '').trim()
|
||||
if (!text) {
|
||||
return ''
|
||||
}
|
||||
|
||||
if (text.length <= 8) {
|
||||
return `${text.slice(0, 2)}${options.shortMask || '***'}${text.slice(-2)}`
|
||||
}
|
||||
|
||||
return `${text.slice(0, 4)}****${text.slice(-4)}`
|
||||
}
|
||||
Reference in New Issue
Block a user