shawko 475955660d
Some checks failed
CI / Test (ubuntu-latest) (push) Has been cancelled
CI / Test (windows-latest) (push) Has been cancelled
CI / Lint (ubuntu-latest) (push) Has been cancelled
CI / Lint (windows-latest) (push) Has been cancelled
CI / Check (ubuntu-latest) (push) Has been cancelled
CI / Check (windows-latest) (push) Has been cancelled
CI / CI OK (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
Deploy Website on push / Deploy Push Playground Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Docs Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Antd Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Element Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Naive Ftp (push) Has been cancelled
Deploy Website on push / Rerun on failure (push) Has been cancelled
Release Drafter / update_release_draft (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Issue Close Require / close-issues (push) Has been cancelled
Close stale issues / stale (push) Has been cancelled
‘add第一次提交’
2026-05-09 16:58:26 +08:00

52 lines
1.1 KiB
TypeScript

const redaction = (val: string) => {
if (!val || val?.length < 2) return val
// 隐藏中间的
const hideLen = Math.trunc(val.length / 2)
let idx = (val.length - hideLen) >> 1
if (idx < 1) {
// 左右至少要显示1个文字
idx = 1
}
return `${val.slice(0, idx)}*${val.slice(Math.max(0, val.length - idx))}`
}
const redactionPhone = (val: string) => {
if (val?.length !== 11) return val
return `${val.slice(0, 3)}${'*'.repeat(4)}${val.slice(-4)}`
}
const redactionRemark = (val: string) => {
if (!val) return val
const matches = val.match(/\{\{(.*?)\}\}/g)
if (matches?.length) {
matches.forEach((item) => {
const newItem = redaction(item.replace('{{', '').replace('}}', ''))
val = val.replace(item, `[${newItem}]`)
})
}
return val
}
const toList = (str: any) => {
if (typeof str === 'string') {
try {
str = JSON.parse(str)
} catch {
str = [str]
}
}
return str
}
const capitalize = (str?: null | string): string => {
return str ? str.charAt(0).toUpperCase() + str.slice(1) : ''
}
export default {
capitalize,
redaction,
toList,
redactionPhone,
redactionRemark,
}