Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SJIS, EUC-JP, JISに変換できないときに数値文字参照に変換する #23

Merged
merged 3 commits into from
Aug 1, 2021

Conversation

tohutohu
Copy link
Contributor

@tohutohu tohutohu commented Jul 18, 2021

現在の仕様では、Shift_JIS・EUC-JP・JISに変換できない文字は ? に変換されますが、オプションとして数値文字参照に変換できるようにします。

数値文字参照について:https://e-words.jp/w/%E6%96%87%E5%AD%97%E5%8F%82%E7%85%A7.html

例えば 🍣寿司ビール🍺(UNICODE) が ?寿司ビール? (Shift_JIS) に変換されていたものが 🍣寿司ビール🍺 (Shift_JIS) に変換できるようになります。

@polygonplanet
Copy link
Owner

ありがとうございます!
数値文字参照はHTML文章に限定されてしまうので、オプション形式などAPIが複雑化しないようある程度修正させていただくことになりそうですが、取り込ませていただきますね。
あと4bytes時の変換が足りてなかったですね…こちらもありがとうございます。

@polygonplanet polygonplanet merged commit 688cb56 into polygonplanet:master Aug 1, 2021
@p-chan
Copy link

p-chan commented Feb 12, 2022

@polygonplanet 本 PR の変更ですが、beta や alpha のリリースでも良いので、npm 経由でインストールできるよう、publish いただくことって可能でしょうか...?

@polygonplanet
Copy link
Owner

polygonplanet commented Mar 29, 2022

@p-chan @tohutohu v2.0.0 でHTMLエンティティ(数値文字参照)に置き換えるオプションを追加しました。
bower (bower.json) を削除したのでメジャーバージョンが上がってますが、APIは追加のみで変更はありません。
オプション名はPRいただいた内容から unknownfallback に変更しています。また4byteの処理周りも高速化のため多少更新しています。

const unicodeArray = Encoding.stringToCode('寿司🍣ビール🍺');
Encoding.convert(unicodeArray, {
  to: 'SJIS',
  from: 'UNICODE',
  fallback: 'html-entity'
});
console.log(sjisArray); // '寿司🍣ビール🍺' の数値配列に変換されます

のように指定できます。( READMEにも追記しています )
なかなか更新できず、お待たせしました 🙏 PRありがとうございました!

@p-chan
Copy link

p-chan commented Apr 2, 2022

v2.0 ありがとうございました〜:pray:
DefinitelyTyped の方にも PR 投げておきました:tada:
DefinitelyTyped/DefinitelyTyped#59656

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants