mirror of
https://gitee.com/jeecg/JeecgBoot.git
synced 2025-12-30 09:22:26 +00:00
25 lines
587 B
JavaScript
25 lines
587 B
JavaScript
|
|
export const getStrFullLength = (str = '') =>
|
|
str.split('').reduce((pre, cur) => {
|
|
const charCode = cur.charCodeAt(0)
|
|
if (charCode >= 0 && charCode <= 128) {
|
|
return pre + 1
|
|
}
|
|
return pre + 2
|
|
}, 0)
|
|
|
|
export const cutStrByFullLength = (str = '', maxLength) => {
|
|
let showLength = 0
|
|
return str.split('').reduce((pre, cur) => {
|
|
const charCode = cur.charCodeAt(0)
|
|
if (charCode >= 0 && charCode <= 128) {
|
|
showLength += 1
|
|
} else {
|
|
showLength += 2
|
|
}
|
|
if (showLength <= maxLength) {
|
|
return pre + cur
|
|
}
|
|
return pre
|
|
}, '')
|
|
} |