[英]Convert string from ISO-2022-JP to UTF-8 in Node.js
我有一個帶有 ISO-2020-JP 編碼文本的Buffer
,我需要將其轉換為 UTF-8。 我在 NPM 上找到了許多庫,例如:
但我不知道也找不到任何地方,其中的確切編碼對應於 ISO-2020-JP。 請指教。
您可以使用encoding.js 。
const Encoding = require('encoding-japanese');
const buffer = [27, 36, 66, 36, 51, 36, 115, 36, 75, 36, 65, 36, 79, 27, 40, 74]; // こんにちは in ISO-2022-JP
// if you want to convert an ISO-2022-JP byte array to a UTF-8 byte array:
const utf8Array = Encoding.convert(buffer, {
to: 'UTF8',
from: 'JIS'
});
console.log(utf8Array);
// if you want to convert ISO-2022-JP byte array to JavaScript string:
const unicodeArray = Encoding.convert(buffer, {
to: 'UNICODE',
from: 'JIS'
});
console.log(Encoding.codeToString(unicodeArray));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.