document-bytes 1.8.1 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -64,6 +64,16 @@ interface InflateResult {
64
64
  }
65
65
  declare function inflateTolerant(data: Uint8Array<ArrayBuffer>): InflateResult;
66
66
  //#endregion
67
+ //#region src/text/decode-dbcs.d.ts
68
+ /**
69
+ * A legacy multi-byte or double-byte CJK encoding {@link decodeText} can decode when the caller declares it explicitly, decoded by this file's own decoders. Never produced by detection, for the same reason a {@link LegacySingleByteEncodingLabel} never is: nothing distinguishes one of these code pages from another, or from any single-byte encoding, without the statistical model this module does not carry (see {@link TextEncodingLabel}). `gbk` and `gb18030` share one decoder ({@link decodeGb18030}) because the Encoding Standard defines GBK's decoder as gb18030's own (https://encoding.spec.whatwg.org/#gbk-decoder).
70
+ */
71
+ type DbcsEncodingLabel = "shift_jis" | "euc-jp" | "euc-kr" | "gbk" | "gb18030" | "big5";
72
+ //#endregion
73
+ //#region src/text/decode-iso-2022-jp.d.ts
74
+ /** ISO-2022-JP's own label — its own union member, kept apart from {@link DbcsEncodingLabel} in decode-dbcs.ts, for the reason this file's own header comment gives. */
75
+ type Iso2022JpEncodingLabel = "iso-2022-jp";
76
+ //#endregion
67
77
  //#region src/text/legacy-single-byte-tables.d.ts
68
78
  /** A legacy single-byte encoding {@link decodeText} can decode when the caller declares it explicitly. Never produced by detection: nothing distinguishes one of these code pages from another, or from windows-1252, without the statistical model this module does not carry (see {@link TextEncodingLabel}). */
69
79
  type LegacySingleByteEncodingLabel = "ibm866" | "iso-8859-2" | "iso-8859-3" | "iso-8859-4" | "iso-8859-5" | "iso-8859-6" | "iso-8859-7" | "iso-8859-8" | "iso-8859-8-i" | "iso-8859-10" | "iso-8859-13" | "iso-8859-14" | "iso-8859-15" | "iso-8859-16" | "koi8-r" | "koi8-u" | "macintosh" | "windows-874" | "windows-1250" | "windows-1251" | "windows-1253" | "windows-1254" | "windows-1255" | "windows-1256" | "windows-1257" | "windows-1258" | "x-mac-cyrillic";
@@ -74,9 +84,9 @@ type LegacySingleByteEncodingLabel = "ibm866" | "iso-8859-2" | "iso-8859-3" | "i
74
84
  *
75
85
  * Detection stays deliberately bounded to `"utf-8"`, `"utf-16le"`, `"utf-16be"`, `"utf-32le"`, `"utf-32be"` and `"windows-1252"`: each of those is either self-identifying through a byte order mark, structurally checkable through its own validity rules, or guessable behind a stated plausibility test, and nothing distinguishes one legacy code page from another, or from windows-1252, without the statistical model this module does not carry. Bytes that look like an undetected legacy encoding are refused rather than guessed at.
76
86
  *
77
- * {@link DecodeTextOptions.encoding} can name more than detection can reach, though: every {@link LegacySingleByteEncodingLabel} the WHATWG Encoding Standard defines is also accepted, for a caller who already knows their file's code page rather than asking this module to guess it (ExaDev/documents.js#1361). Legacy multi-byte and double-byte CJK encodings (Shift_JIS, EUC-JP, ISO-2022-JP, GBK, gb18030, Big5, EUC-KR) remain outside what either detection or a declared `encoding` can reach; see legacy-single-byte-tables.ts for why that is a different kind of change, tracked separately as ExaDev/documents.js#1388.
87
+ * {@link DecodeTextOptions.encoding} can name more than detection can reach, though: every {@link LegacySingleByteEncodingLabel} the WHATWG Encoding Standard defines is also accepted, for a caller who already knows their file's code page rather than asking this module to guess it (ExaDev/documents.js#1361), and so is every {@link DbcsEncodingLabel} and {@link Iso2022JpEncodingLabel} — the standard's legacy multi-byte and double-byte CJK encodings, decoded against decode-dbcs.ts's own generated index tables, and ISO-2022-JP's own escape-sequence state machine in decode-iso-2022-jp.ts, for the same reason (ExaDev/documents.js#1388).
78
88
  */
79
- type TextEncodingLabel = "utf-8" | "utf-16le" | "utf-16be" | "utf-32le" | "utf-32be" | "windows-1252" | LegacySingleByteEncodingLabel;
89
+ type TextEncodingLabel = "utf-8" | "utf-16le" | "utf-16be" | "utf-32le" | "utf-32be" | "windows-1252" | LegacySingleByteEncodingLabel | DbcsEncodingLabel | Iso2022JpEncodingLabel;
80
90
  /**
81
91
  * How {@link decodeText} arrived at the encoding it used.
82
92
  *
@@ -121,6 +131,18 @@ declare class UndecodableTextError extends Error {
121
131
  * Exported so tests can place inputs on and around a chunk boundary without repeating the figure.
122
132
  */
123
133
  declare const TEXT_DECODE_CHUNK_CODE_UNITS: number;
134
+ /**
135
+ * Splits `codePoint` into one or two UTF-16 code units and pushes them onto `units`: the code point itself below the supplementary plane, a surrogate pair biased by {@link SURROGATE_BITS} and {@link LOW_SURROGATE_MASK} above it. Shared by every decoder here that can produce a code point outside the Basic Multilingual Plane — {@link decodeUtf32} for UTF-32's own scalar values, and decode-dbcs.ts's decoders for the WHATWG index tables' own supplementary-plane entries (Big5's CJK Compatibility Ideographs Supplement pointers, gb18030's final algorithmic range) — so the split happens in exactly one place rather than once per caller.
136
+ * @param units - The code unit array to push onto, in place.
137
+ * @param codePoint - A Unicode scalar value in the range 0 to {@link MAX_CODE_POINT}.
138
+ */
139
+ declare function appendCodePoint(units: number[], codePoint: number): void;
140
+ /**
141
+ * Converts a sequence of UTF-16 code units to a string in fixed-size chunks (see {@link TEXT_DECODE_CHUNK_CODE_UNITS}), shared by every decoder in this module and in decode-dbcs.ts so each collects code units into a plain array and calls this once at the end rather than concatenating a string one character at a time.
142
+ * @param units - The code units to convert, in order.
143
+ * @returns The resulting string.
144
+ */
145
+ declare function fromCodeUnits(units: readonly number[]): string;
124
146
  /** A byte order mark's own encoding, and how many leading bytes it occupies. */
125
147
  interface ByteOrderMark {
126
148
  /** The encoding the mark identifies. */
@@ -216,4 +238,4 @@ interface JpegInfo {
216
238
  }
217
239
  declare function readJpegInfo(bytes: Uint8Array<ArrayBuffer>): JpegInfo;
218
240
  //#endregion
219
- export { BASE64_ENCODE_CHUNK_CHARS, ByteOrderMark, ByteReader, ByteWriter, DecodeTextOptions, DecodedText, DecodedTextConfidence, DecodedTextSource, DeflateLevel, InflateResult, JpegInfo, MAX_INFLATE_OUTPUT_BYTES, PNG_MAX_DIMENSION, PNG_MAX_PIXELS, PngDecodeOptions, PngEncodeOptions, PngFilterType, RawImage, TEXT_DECODE_CHUNK_CODE_UNITS, TextEncodingLabel, UndecodableTextError, UndecodableTextReason, base64ToBytes, bytesToBase64, concatBytes, crc32, decodePng, decodeText, deflate, detectByteOrderMark, encodePng, exceedsMaxPixelCount, filterScanlines, inflate, inflateTolerant, isAsciiWhitespace, isProbablyText, readJpegInfo, resolveEncodingLabel, tryDecodeText, unfilterScanlines };
241
+ export { BASE64_ENCODE_CHUNK_CHARS, ByteOrderMark, ByteReader, ByteWriter, DecodeTextOptions, DecodedText, DecodedTextConfidence, DecodedTextSource, DeflateLevel, InflateResult, JpegInfo, MAX_INFLATE_OUTPUT_BYTES, PNG_MAX_DIMENSION, PNG_MAX_PIXELS, PngDecodeOptions, PngEncodeOptions, PngFilterType, RawImage, TEXT_DECODE_CHUNK_CODE_UNITS, TextEncodingLabel, UndecodableTextError, UndecodableTextReason, appendCodePoint, base64ToBytes, bytesToBase64, concatBytes, crc32, decodePng, decodeText, deflate, detectByteOrderMark, encodePng, exceedsMaxPixelCount, filterScanlines, fromCodeUnits, inflate, inflateTolerant, isAsciiWhitespace, isProbablyText, readJpegInfo, resolveEncodingLabel, tryDecodeText, unfilterScanlines };
package/dist/index.d.ts CHANGED
@@ -64,6 +64,16 @@ interface InflateResult {
64
64
  }
65
65
  declare function inflateTolerant(data: Uint8Array<ArrayBuffer>): InflateResult;
66
66
  //#endregion
67
+ //#region src/text/decode-dbcs.d.ts
68
+ /**
69
+ * A legacy multi-byte or double-byte CJK encoding {@link decodeText} can decode when the caller declares it explicitly, decoded by this file's own decoders. Never produced by detection, for the same reason a {@link LegacySingleByteEncodingLabel} never is: nothing distinguishes one of these code pages from another, or from any single-byte encoding, without the statistical model this module does not carry (see {@link TextEncodingLabel}). `gbk` and `gb18030` share one decoder ({@link decodeGb18030}) because the Encoding Standard defines GBK's decoder as gb18030's own (https://encoding.spec.whatwg.org/#gbk-decoder).
70
+ */
71
+ type DbcsEncodingLabel = "shift_jis" | "euc-jp" | "euc-kr" | "gbk" | "gb18030" | "big5";
72
+ //#endregion
73
+ //#region src/text/decode-iso-2022-jp.d.ts
74
+ /** ISO-2022-JP's own label — its own union member, kept apart from {@link DbcsEncodingLabel} in decode-dbcs.ts, for the reason this file's own header comment gives. */
75
+ type Iso2022JpEncodingLabel = "iso-2022-jp";
76
+ //#endregion
67
77
  //#region src/text/legacy-single-byte-tables.d.ts
68
78
  /** A legacy single-byte encoding {@link decodeText} can decode when the caller declares it explicitly. Never produced by detection: nothing distinguishes one of these code pages from another, or from windows-1252, without the statistical model this module does not carry (see {@link TextEncodingLabel}). */
69
79
  type LegacySingleByteEncodingLabel = "ibm866" | "iso-8859-2" | "iso-8859-3" | "iso-8859-4" | "iso-8859-5" | "iso-8859-6" | "iso-8859-7" | "iso-8859-8" | "iso-8859-8-i" | "iso-8859-10" | "iso-8859-13" | "iso-8859-14" | "iso-8859-15" | "iso-8859-16" | "koi8-r" | "koi8-u" | "macintosh" | "windows-874" | "windows-1250" | "windows-1251" | "windows-1253" | "windows-1254" | "windows-1255" | "windows-1256" | "windows-1257" | "windows-1258" | "x-mac-cyrillic";
@@ -74,9 +84,9 @@ type LegacySingleByteEncodingLabel = "ibm866" | "iso-8859-2" | "iso-8859-3" | "i
74
84
  *
75
85
  * Detection stays deliberately bounded to `"utf-8"`, `"utf-16le"`, `"utf-16be"`, `"utf-32le"`, `"utf-32be"` and `"windows-1252"`: each of those is either self-identifying through a byte order mark, structurally checkable through its own validity rules, or guessable behind a stated plausibility test, and nothing distinguishes one legacy code page from another, or from windows-1252, without the statistical model this module does not carry. Bytes that look like an undetected legacy encoding are refused rather than guessed at.
76
86
  *
77
- * {@link DecodeTextOptions.encoding} can name more than detection can reach, though: every {@link LegacySingleByteEncodingLabel} the WHATWG Encoding Standard defines is also accepted, for a caller who already knows their file's code page rather than asking this module to guess it (ExaDev/documents.js#1361). Legacy multi-byte and double-byte CJK encodings (Shift_JIS, EUC-JP, ISO-2022-JP, GBK, gb18030, Big5, EUC-KR) remain outside what either detection or a declared `encoding` can reach; see legacy-single-byte-tables.ts for why that is a different kind of change, tracked separately as ExaDev/documents.js#1388.
87
+ * {@link DecodeTextOptions.encoding} can name more than detection can reach, though: every {@link LegacySingleByteEncodingLabel} the WHATWG Encoding Standard defines is also accepted, for a caller who already knows their file's code page rather than asking this module to guess it (ExaDev/documents.js#1361), and so is every {@link DbcsEncodingLabel} and {@link Iso2022JpEncodingLabel} — the standard's legacy multi-byte and double-byte CJK encodings, decoded against decode-dbcs.ts's own generated index tables, and ISO-2022-JP's own escape-sequence state machine in decode-iso-2022-jp.ts, for the same reason (ExaDev/documents.js#1388).
78
88
  */
79
- type TextEncodingLabel = "utf-8" | "utf-16le" | "utf-16be" | "utf-32le" | "utf-32be" | "windows-1252" | LegacySingleByteEncodingLabel;
89
+ type TextEncodingLabel = "utf-8" | "utf-16le" | "utf-16be" | "utf-32le" | "utf-32be" | "windows-1252" | LegacySingleByteEncodingLabel | DbcsEncodingLabel | Iso2022JpEncodingLabel;
80
90
  /**
81
91
  * How {@link decodeText} arrived at the encoding it used.
82
92
  *
@@ -121,6 +131,18 @@ declare class UndecodableTextError extends Error {
121
131
  * Exported so tests can place inputs on and around a chunk boundary without repeating the figure.
122
132
  */
123
133
  declare const TEXT_DECODE_CHUNK_CODE_UNITS: number;
134
+ /**
135
+ * Splits `codePoint` into one or two UTF-16 code units and pushes them onto `units`: the code point itself below the supplementary plane, a surrogate pair biased by {@link SURROGATE_BITS} and {@link LOW_SURROGATE_MASK} above it. Shared by every decoder here that can produce a code point outside the Basic Multilingual Plane — {@link decodeUtf32} for UTF-32's own scalar values, and decode-dbcs.ts's decoders for the WHATWG index tables' own supplementary-plane entries (Big5's CJK Compatibility Ideographs Supplement pointers, gb18030's final algorithmic range) — so the split happens in exactly one place rather than once per caller.
136
+ * @param units - The code unit array to push onto, in place.
137
+ * @param codePoint - A Unicode scalar value in the range 0 to {@link MAX_CODE_POINT}.
138
+ */
139
+ declare function appendCodePoint(units: number[], codePoint: number): void;
140
+ /**
141
+ * Converts a sequence of UTF-16 code units to a string in fixed-size chunks (see {@link TEXT_DECODE_CHUNK_CODE_UNITS}), shared by every decoder in this module and in decode-dbcs.ts so each collects code units into a plain array and calls this once at the end rather than concatenating a string one character at a time.
142
+ * @param units - The code units to convert, in order.
143
+ * @returns The resulting string.
144
+ */
145
+ declare function fromCodeUnits(units: readonly number[]): string;
124
146
  /** A byte order mark's own encoding, and how many leading bytes it occupies. */
125
147
  interface ByteOrderMark {
126
148
  /** The encoding the mark identifies. */
@@ -216,4 +238,4 @@ interface JpegInfo {
216
238
  }
217
239
  declare function readJpegInfo(bytes: Uint8Array<ArrayBuffer>): JpegInfo;
218
240
  //#endregion
219
- export { BASE64_ENCODE_CHUNK_CHARS, ByteOrderMark, ByteReader, ByteWriter, DecodeTextOptions, DecodedText, DecodedTextConfidence, DecodedTextSource, DeflateLevel, InflateResult, JpegInfo, MAX_INFLATE_OUTPUT_BYTES, PNG_MAX_DIMENSION, PNG_MAX_PIXELS, PngDecodeOptions, PngEncodeOptions, PngFilterType, RawImage, TEXT_DECODE_CHUNK_CODE_UNITS, TextEncodingLabel, UndecodableTextError, UndecodableTextReason, base64ToBytes, bytesToBase64, concatBytes, crc32, decodePng, decodeText, deflate, detectByteOrderMark, encodePng, exceedsMaxPixelCount, filterScanlines, inflate, inflateTolerant, isAsciiWhitespace, isProbablyText, readJpegInfo, resolveEncodingLabel, tryDecodeText, unfilterScanlines };
241
+ export { BASE64_ENCODE_CHUNK_CHARS, ByteOrderMark, ByteReader, ByteWriter, DecodeTextOptions, DecodedText, DecodedTextConfidence, DecodedTextSource, DeflateLevel, InflateResult, JpegInfo, MAX_INFLATE_OUTPUT_BYTES, PNG_MAX_DIMENSION, PNG_MAX_PIXELS, PngDecodeOptions, PngEncodeOptions, PngFilterType, RawImage, TEXT_DECODE_CHUNK_CODE_UNITS, TextEncodingLabel, UndecodableTextError, UndecodableTextReason, appendCodePoint, base64ToBytes, bytesToBase64, concatBytes, crc32, decodePng, decodeText, deflate, detectByteOrderMark, encodePng, exceedsMaxPixelCount, filterScanlines, fromCodeUnits, inflate, inflateTolerant, isAsciiWhitespace, isProbablyText, readJpegInfo, resolveEncodingLabel, tryDecodeText, unfilterScanlines };