feat: finished 1.0.0

This commit is contained in:
2024-03-14 21:55:01 +08:00
parent d1005bcd13
commit d88cc8a01b
26 changed files with 6962 additions and 55 deletions

View File

@@ -1,18 +1,15 @@
import { Codec } from '@/utils/codecs'
import '@/utils/iconv'
export class EncodingConverter {
async convert(codec: Codec, text: string): Promise<string | null> {
let convertedText: string | null = null
try {
const byteArray = new TextEncoder().encode(text)
const decodedText = new TextDecoder(codec.origin).decode(byteArray)
const byteArray2 = new TextEncoder().encode(decodedText)
convertedText = new TextDecoder(codec.target).decode(byteArray2)
const byteArray = iconv.encode(text, codec.origin)
convertedText = iconv.decode(byteArray, codec.target)
text = convertedText
} catch (error) {
console.error(
`Failed to convert from ${codec.origin} to ${codec.target}: ${error}`
)
console.error(`Failed to convert from ${codec.origin} to ${codec.target}: ${error}`)
return null
}
return convertedText