This commit is contained in:
zyronon
2023-11-19 01:25:51 +08:00
parent 0ea816dc73
commit 642e1e3dee
16 changed files with 254 additions and 786 deletions

View File

@@ -3,8 +3,10 @@ import mitt from 'mitt'
export const emitter = mitt()
export const EventKey = {
resetWord: 'resetWord',
changeDict: 'changeDict',
openStatModal: 'openStatModal',
openWordListModal: 'openWordListModal',
openDictModal: 'openDictModal',
openArticleListModal: 'openArticleListModal',
closeOther: 'closeOther',
keydown: 'keydown',

View File

@@ -1,42 +1,3 @@
export function getRandom(a: number, b: number): number {
return Math.random() * (b - a) + a;
}
export function sizeofByte(str, charset = 'utf-16') {
let total = 0
let charCode
charset = charset.toLowerCase()
if (charset === 'utf-8' || charset === 'utf8') {
for (let i = 0, len = str.length; i < len; i++) {
charCode = str.codePointAt(i)
if (charCode <= 0x007f) {
total += 1
} else if (charCode <= 0x07ff) {
total += 2
} else if (charCode <= 0xffff) {
total += 3
} else {
total += 4
i++
}
}
} else if (charset === 'utf-16' || charset === 'utf16') {
for (let i = 0, len = str.length; i < len; i++) {
charCode = str.codePointAt(i)
if (charCode <= 0xffff) {
total += 2
} else {
total += 4
i++
}
}
} else {
total = str.replace(/[^\x00-\xff]/g, 'aa').length
}
return total
}