@@ -131,16 +131,42 @@ import { createSinglebyteDecoder, createSinglebyteEncoder } from '@exodus/bytes/
131131import { windows1252toString , windows1252fromString } from ' @exodus/bytes/single-byte.js'
132132```
133133
134- Decode the legacy single-byte encodings according to the [ Encoding standard] ( https://encoding.spec.whatwg.org/ )
135- ([ §9] ( https://encoding.spec.whatwg.org/#legacy-single-byte-encodings ) and
136- [ §14.5] ( https://encoding.spec.whatwg.org/#x-user-defined ) ).
134+ Decode / encode the legacy single-byte encodings according to the
135+ [ Encoding standard] ( https://encoding.spec.whatwg.org/ )
136+ ([ §9] ( https://encoding.spec.whatwg.org/#legacy-single-byte-encodings ) ,
137+ [ §14.5] ( https://encoding.spec.whatwg.org/#x-user-defined ) ),
138+ and [ unicode.org] ( https://unicode.org/Public/MAPPINGS/ISO8859 ) ` iso-8859-* ` mappings.
137139
138- Supports all single-byte encodings listed in the standard:
140+ Supports all single-byte encodings listed in the WHATWG Encoding standard:
139141` ibm866 ` , ` iso-8859-2 ` , ` iso-8859-3 ` , ` iso-8859-4 ` , ` iso-8859-5 ` , ` iso-8859-6 ` , ` iso-8859-7 ` , ` iso-8859-8 ` ,
140142` iso-8859-8-i ` , ` iso-8859-10 ` , ` iso-8859-13 ` , ` iso-8859-14 ` , ` iso-8859-15 ` , ` iso-8859-16 ` , ` koi8-r ` , ` koi8-u ` ,
141143` macintosh ` , ` windows-874 ` , ` windows-1250 ` , ` windows-1251 ` , ` windows-1252 ` , ` windows-1253 ` , ` windows-1254 ` ,
142144` windows-1255 ` , ` windows-1256 ` , ` windows-1257 ` , ` windows-1258 ` , ` x-mac-cyrillic ` and ` x-user-defined ` .
143145
146+ Also supports ` iso-8859-1 ` , ` iso-8859-9 ` , ` iso-8859-11 ` as defined at
147+ [ unicode.org] ( https://unicode.org/Public/MAPPINGS/ISO8859 )
148+ (and all other ` iso-8859-* ` encodings there as they match WHATWG).
149+
150+ > [ !NOTE]
151+ > While all ` iso-8859-* ` encodings supported by the [ WHATWG Encoding standard] ( https://encoding.spec.whatwg.org/ ) match
152+ > [ unicode.org] ( https://unicode.org/Public/MAPPINGS/ISO8859 ) , the WHATWG Encoding spec doesn't support
153+ > ` iso-8859-1 ` , ` iso-8859-9 ` , ` iso-8859-11 ` , and instead maps them as labels to ` windows-1252 ` , ` windows-1254 ` , ` windows-874 ` .\
154+ > ` createSinglebyteDecoder() ` (unlike ` TextDecoder ` or ` legacyHookDecode() ` ) does not do such mapping,
155+ > so its results will differ from ` TextDecoder ` for those encoding names.
156+
157+ ``` js
158+ > new TextDecoder (' iso-8859-1' ).encoding
159+ ' windows-1252'
160+ > new TextDecoder (' iso-8859-9' ).encoding
161+ ' windows-1254'
162+ > new TextDecoder (' iso-8859-11' ).encoding
163+ ' windows-874'
164+ > new TextDecoder (' iso-8859-9' ).decode (Uint8Array .of (0x80 , 0x81 , 0xd0 ))
165+ ' €\x81 Ğ' // this is actually decoded according to windows-1254 per TextDecoder spec
166+ > createSinglebyteDecoder (' iso-8859-9' )(Uint8Array .of (0x80 , 0x81 , 0xd0 ))
167+ ' \x80\x81 Ğ' // this is iso-8859-9 as defined at https://unicode.org/Public/MAPPINGS/ISO8859/8859-9.txt
168+ ```
169+
144170##### ` createSinglebyteDecoder(encoding, loose = false) `
145171
146172Create a decoder for a supported one-byte ` encoding ` , given its lowercased name ` encoding ` .
@@ -156,12 +182,35 @@ Returns a function `encode(string)` that encodes a string to bytes.
156182In ` 'fatal' ` mode (default), will throw on non well-formed strings or any codepoints which could
157183not be encoded in the target encoding.
158184
185+ ##### ` latin1toString(arr) `
186+
187+ Decode ` iso-8859-1 ` bytes to a string.
188+
189+ There is no loose variant for this encoding, all bytes can be decoded.
190+
191+ Same as:
192+ ``` js
193+ const latin1toString = createSinglebyteDecoder (' iso-8859-1' )
194+ ```
195+
196+ Note: this is different from ` new TextDecoder('iso-8859-1') ` and ` new TextDecoder('latin1') ` , as
197+ those alias to ` new TextDecoder('windows-1252') ` .
198+
199+ ##### ` latin1fromString(string) `
200+
201+ Encode a string to ` iso-8859-1 ` bytes.
202+
203+ Will throw on non well-formed strings or any codepoints which could not be encoded in ` iso-8859-1 ` .
204+
205+ Same as:
206+ ``` js
207+ const latin1fromString = createSinglebyteEncoder (' iso-8859-1' , { mode: ' fatal' })
208+ ```
209+
159210##### ` windows1252toString(arr) `
160211
161212Decode ` windows-1252 ` bytes to a string.
162213
163- Also supports ` ascii ` and ` latin-1 ` as those are strict subsets of ` windows-1252 ` .
164-
165214There is no loose variant for this encoding, all bytes can be decoded.
166215
167216Same as:
@@ -173,8 +222,6 @@ const windows1252toString = createSinglebyteDecoder('windows-1252')
173222
174223Encode a string to ` windows-1252 ` bytes.
175224
176- Also supports ` ascii ` and ` latin-1 ` as those are strict subsets of ` windows-1252 ` .
177-
178225Will throw on non well-formed strings or any codepoints which could not be encoded in ` windows-1252 ` .
179226
180227Same as:
0 commit comments