feat: add TypeScript definitions for utf16.js#30
Conversation
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
array.d.ts
Outdated
|
|
||
| // >= TypeScript 5.9 made Uint16Array templated with <> and defaulted to ArrayBufferLike | ||
| // which would incorrectly accept SharedArrayBuffer instances. | ||
| // < TypeScript 5.7 doesn't support templates for Uint16Array. | ||
| // So this type is defined as a workaround to evaluate to Uint16Array<ArrayBuffer> on all versions of TypeScript. |
There was a problem hiding this comment.
| // >= TypeScript 5.9 made Uint16Array templated with <> and defaulted to ArrayBufferLike | |
| // which would incorrectly accept SharedArrayBuffer instances. | |
| // < TypeScript 5.7 doesn't support templates for Uint16Array. | |
| // So this type is defined as a workaround to evaluate to Uint16Array<ArrayBuffer> on all versions of TypeScript. |
There was a problem hiding this comment.
Removed blank line between type definitions (099ae6b)
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
| /** | ||
| * Encode a string to UTF-16 bytes (strict mode) | ||
| * | ||
| * Throws on invalid Unicode (unpaired surrogates) |
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
utf16.d.ts
Outdated
| * Replaces invalid Unicode (unpaired surrogates) with replacement codepoints `U+FFFD` | ||
| * per [WHATWG Encoding](https://encoding.spec.whatwg.org/) specification. | ||
| * | ||
| * _Such replacement is a non-injective function, is irreversible and causes collisions._ |
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
utf16.d.ts
Outdated
| * import { utf16fromStringLoose, utf16toStringLoose } from '@exodus/bytes/utf16.js' | ||
| * ``` | ||
| * | ||
| * _These methods by design encode/decode BOM (codepoint `U+FEFF` Byte Order Mark) as-is._ |
There was a problem hiding this comment.
Fixed module-level JSDoc formatting with backslash continuation (d149023)
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
|
|
||
| Replaces invalid UTF-16 byte sequences with replacement codepoints `U+FFFD` | ||
| per [WHATWG Encoding](https://encoding.spec.whatwg.org/) specification. | ||
|
|
There was a problem hiding this comment.
| Throws on non-even byte length. |
@copilot here and in README, for utf16toStringLoose
There was a problem hiding this comment.
Added note about throwing on non-even byte length to both utf16toString and utf16toStringLoose in utf16.d.ts and README.md (8aef664)
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR adds TypeScript type definitions for the utf16.js module, enabling type-safe usage of UTF-16 encoding/decoding functions. The implementation follows the same pattern as the existing utf8.d.ts file and includes comprehensive JSDoc documentation.
Changes:
- Added TypeScript definitions with proper function overloads for format parameter type safety
- Introduced
Uint16ArrayBuffertype inarray.d.tsfor consistency withUint8ArrayBuffer - Updated package.json to expose types in the exports map and files array
- Enhanced README.md with detailed API documentation matching the UTF-8 section format
Reviewed changes
Copilot reviewed 2 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| utf16.d.ts | New TypeScript definitions file with type-safe function overloads for utf16fromString, utf16fromStringLoose, utf16toString, and utf16toStringLoose, including comprehensive JSDoc documentation |
| array.d.ts | Added Uint16ArrayBuffer type definition next to Uint8ArrayBuffer for type safety |
| package.json | Added utf16.d.ts to files array and types field to utf16.js exports configuration |
| README.md | Added detailed API documentation for UTF-16 functions with descriptions, behavior notes, and format parameters |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Add TypeScript types for utf16.js
utf16.d.tsfile with TypeScript type definitionspackage.jsonto include types for utf16.js exportSummary
Successfully added complete TypeScript type definitions for
utf16.jsmodule following the same pattern asutf8.d.ts. The implementation includes:Uint16ArrayBuffertype definition inarray.d.ts(next toUint8ArrayBuffer) to prevent SharedArrayBuffer acceptanceOriginal prompt
utf16.js#24💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.