@@ -49,7 +49,9 @@ export interface SinglebyteEncoderOptions {
4949}
5050
5151/**
52- * Create a decoder function for a single-byte character encoding
52+ * Create a decoder for a supported one-byte `encoding`, given its lowercased name `encoding`.
53+ *
54+ * Returns a function `decode(arr)` that decodes bytes to a string.
5355 *
5456 * @param encoding - The encoding name (e.g., 'iso-8859-1', 'windows-1252')
5557 * @param loose - If true, replaces unmapped bytes with replacement character instead of throwing (default: false)
@@ -61,7 +63,12 @@ export function createSinglebyteDecoder(
6163) : ( arr : Uint8ArrayBuffer ) => string ;
6264
6365/**
64- * Create an encoder function for a single-byte character encoding
66+ * Create an encoder for a supported one-byte `encoding`, given its lowercased name `encoding`.
67+ *
68+ * Returns a function `encode(string)` that encodes a string to bytes.
69+ *
70+ * In `'fatal'` mode (default), will throw on non well-formed strings or any codepoints which could
71+ * not be encoded in the target encoding.
6572 *
6673 * @param encoding - The encoding name (e.g., 'iso-8859-1', 'windows-1252')
6774 * @param options - Encoding options
@@ -73,35 +80,62 @@ export function createSinglebyteEncoder(
7380) : ( string : string ) => Uint8ArrayBuffer ;
7481
7582/**
76- * Decode ISO-8859-1 (Latin-1) bytes to a string
83+ * Decode `iso-8859-1` bytes to a string.
84+ *
85+ * There is no loose variant for this encoding, all bytes can be decoded.
86+ *
87+ * Same as:
88+ * ```js
89+ * const latin1toString = createSinglebyteDecoder('iso-8859-1')
90+ * ```
91+ *
92+ * Note: this is different from `new TextDecoder('iso-8859-1')` and `new TextDecoder('latin1')`, as
93+ * those alias to `new TextDecoder('windows-1252')`.
7794 *
7895 * @param arr - The bytes to decode
7996 * @returns The decoded string
8097 */
8198export const latin1toString : ( arr : Uint8ArrayBuffer ) => string ;
8299
83100/**
84- * Encode a string to ISO-8859-1 (Latin-1) bytes
101+ * Encode a string to `iso-8859-1` bytes.
102+ *
103+ * Will throw on non well-formed strings or any codepoints which could not be encoded in `iso-8859-1`.
85104 *
86- * Throws on characters that cannot be encoded in Latin-1
105+ * Same as:
106+ * ```js
107+ * const latin1fromString = createSinglebyteEncoder('iso-8859-1', { mode: 'fatal' })
108+ * ```
87109 *
88110 * @param string - The string to encode
89111 * @returns The encoded bytes
90112 */
91113export const latin1fromString : ( string : string ) => Uint8ArrayBuffer ;
92114
93115/**
94- * Decode Windows-1252 bytes to a string
116+ * Decode `windows-1252` bytes to a string.
117+ *
118+ * There is no loose variant for this encoding, all bytes can be decoded.
119+ *
120+ * Same as:
121+ * ```js
122+ * const windows1252toString = createSinglebyteDecoder('windows-1252')
123+ * ```
95124 *
96125 * @param arr - The bytes to decode
97126 * @returns The decoded string
98127 */
99128export const windows1252toString : ( arr : Uint8ArrayBuffer ) => string ;
100129
101130/**
102- * Encode a string to Windows-1252 bytes
131+ * Encode a string to `windows-1252` bytes.
132+ *
133+ * Will throw on non well-formed strings or any codepoints which could not be encoded in `windows-1252`.
103134 *
104- * Throws on characters that cannot be encoded in Windows-1252
135+ * Same as:
136+ * ```js
137+ * const windows1252fromString = createSinglebyteEncoder('windows-1252', { mode: 'fatal' })
138+ * ```
105139 *
106140 * @param string - The string to encode
107141 * @returns The encoded bytes
0 commit comments