Skip to content

Conversation

@ChALkeR
Copy link
Collaborator

@ChALkeR ChALkeR commented Dec 27, 2025

Ref: #9
Doesn't yet solve that, but a step towards encoders

@ChALkeR ChALkeR force-pushed the chalker/single-byte/0 branch 12 times, most recently from b88e93a to 0b5559b Compare December 28, 2025 07:01
@ChALkeR ChALkeR force-pushed the chalker/single-byte/0 branch from 0b5559b to 4dd8630 Compare December 28, 2025 11:36
@ChALkeR ChALkeR marked this pull request as ready for review December 28, 2025 14:03
@ChALkeR ChALkeR requested a review from Copilot December 28, 2025 14:03
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements the createSinglebyteEncoder function to provide encoding functionality for single-byte character encodings, complementing the existing decoder functionality. It adds support for encoding strings to bytes according to the WHATWG Encoding standard's legacy single-byte encodings.

  • Implements createSinglebyteEncoder() with optimized paths for Node.js and fallback implementations
  • Adds comprehensive test coverage for encoder functionality including ASCII subset validation and error cases
  • Updates documentation with API details for the new encoder functions

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/single-byte.test.js Adds encoder tests to validate encoding for ASCII subsets, encoding indices, and x-user-defined encoding with error cases
single-byte.node.js Implements Node.js-optimized encoder using Buffer and Uint16Array for performance, with ASCII fast path
single-byte.js Implements fallback encoder with native encoder support and optimistic encoding strategy
fallback/single-byte.js Adds encodeMap() function to generate reverse lookup maps for encoding codepoints to bytes
benchmarks/windows1252.bench.js Adds benchmark tests comparing encoder performance across libraries for ASCII and complex strings
README.md Documents the new createSinglebyteEncoder() and windows1252fromString() functions with usage examples

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


Create an encoder for a supported one-byte `encoding`, given it's lowercased name `encoding`.

Returns a function `encode(string)` that decodes bytes to a string.
Copy link

Copilot AI Dec 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description says "that decodes bytes to a string" but this function encodes a string to bytes. The description should say "that encodes a string to bytes".

Suggested change
Returns a function `encode(string)` that decodes bytes to a string.
Returns a function `encode(string)` that encodes a string to bytes.

Copilot uses AI. Check for mistakes.

Also supports `ascii` and `latin-1` as those are strict subsets of `windows-1252`.

Will throw on non well-formed strings or any codepoins which could not be encoded in `windows-1252`.
Copy link

Copilot AI Dec 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: "codepoins" should be "codepoints".

Suggested change
Will throw on non well-formed strings or any codepoins which could not be encoded in `windows-1252`.
Will throw on non well-formed strings or any codepoints which could not be encoded in `windows-1252`.

Copilot uses AI. Check for mistakes.
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.

2 participants