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

feat: add error fallback option in Encoding.convert #44

Merged
merged 3 commits into from
Jun 8, 2024

Conversation

polygonplanet
Copy link
Owner

Resolve #43

Added a new { fallback: 'error' } option to Encoding.convert.
This option throws an error if a character cannot be converted, allowing for explicit error handling.

Example:

const unicodeArray = Encoding.stringToCode('おにぎり🍙ラーメン🍜');
try {
  const sjisArray = Encoding.convert(unicodeArray, {
    to: 'SJIS',
    from: 'UNICODE',
    fallback: 'error' // Specify 'error' to throw an exception
  });
} catch (e) {
  console.error(e); // Error: Character cannot be represented: [240, 159, 141, 153]
}

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