Skip to content

2.5.0

Latest

Choose a tag to compare

@polygonplanet polygonplanet released this 02 Nov 19:08

What's Changed

This release has no breaking API changes and focuses on making encoding.js faster and smaller: a roughly 60% reduction in minified bundle size, faster character encoding conversions, and lower memory usage.
And I've finally set up GitHub Sponsors!

Features

  • Improve TypeScript definitions: support case-insensitive encoding names and aliases through EncodingName, allow string input in urlEncode() and base64Encode(), and accept typed arrays in the Zenkaku/Hankaku conversion functions (d769950)

Bug Fixes

  • Fix an extra NUL byte when decoding JIS X 0212 0x2237 from EUCJP and JIS by @youdie006 in #69
  • Ignore stray continuation bytes when converting from UTF8, preventing the previous character from being repeated (#71)
  • Use the fallback character for values above U+10FFFF when converting from UNICODE to UTF8 (#71)
  • Fix codeToString() and string output potentially throwing a RangeError on a deep call stack (055ede8)
  • Fix base64Decode() to ignore non-ASCII characters (61e7dc2)
  • Fix convert() to return a new array even when no conversion is needed (86f2a7e)

Performance

Smaller bundle size

Reduced the bundle size by compressing the UTF-8 to JIS conversion tables into a compact text format. Conversion results and APIs are unchanged.

The tables are expanded lazily only when a conversion is actually needed, rather than at module load time, to avoid unnecessary initialization overhead. See #70 for more details.

v2.4.0 v2.5.0 Change
encoding.js 304 KB 148 KB -51%
encoding.min.js 229 KB 88 KB -62%
encoding.min.js (gzip) 76 KB 39 KB -49%

Faster conversions

Improved conversion performance by prioritizing typed arrays.
This makes convert() about 1.5-3.5x faster for most encoding pairs (about 1.3x when converting from UTF-8) and reduces peak memory during conversion by about 25-60%.

Selected benchmark results from #71 (in ops/sec, higher is better):

Conversion v2.4.0 v2.5.0 Speedup
SJIS -> UNICODE 64.51 160 2.5x
EUCJP -> UNICODE 65.96 182 2.8x
UNICODE -> SJIS 23.63 54.25 2.3x
UNICODE -> UTF8 54.85 183 3.3x
SJIS -> UTF8 84.82 154 1.8x
UTF8 -> SJIS 62.02 79.35 1.3x

Benchmark on Node.js v24 with the full text of "I Am a Cat" (about 350,000 characters), type: 'array'.

Other performance improvements:

  • Improve codeToString() and string output performance by keeping the fast conversion path available after processing large arrays (055ede8)
  • Improve the performance of stringToCode(), base64Encode(), urlDecode() and the Zenkaku/Hankaku conversion functions by preallocating result arrays, up to about 3x faster for large input (055ede8, cf887c6)

Maintenance

  • Update minify options to keep encoding.min.js ES5-compatible (9a8d3b2)
  • Update devDependencies (9357cc1, f0c942e)

GitHub Sponsors

I've started GitHub Sponsors!
If encoding.js is useful to you, please consider supporting my work.
Your support would mean a lot. Thank you!

New Contributors

Full Changelog: 2.4.0...2.5.0