-
Notifications
You must be signed in to change notification settings - Fork 2
feat: implement createSinglebyteEncoder #10
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
base: master
Are you sure you want to change the base?
Conversation
b88e93a to
0b5559b
Compare
0b5559b to
4dd8630
Compare
There was a problem hiding this 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. |
Copilot
AI
Dec 28, 2025
There was a problem hiding this comment.
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".
| Returns a function `encode(string)` that decodes bytes to a string. | |
| Returns a function `encode(string)` that encodes a string to bytes. |
|
|
||
| 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`. |
Copilot
AI
Dec 28, 2025
There was a problem hiding this comment.
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".
| 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`. |
Ref: #9
Doesn't yet solve that, but a step towards encoders