Debian Codegraph @

node/@bufbuild/protobuf/dist/commonjs/wire/text-encoding.d.ts

raw
1 interface TextEncoding {
2 /**
3 * Verify that the given text is valid UTF-8.
4 */
5 checkUtf8: (text: string) => boolean;
6 /**
7 * Encode UTF-8 text to binary.
8 */
9 encodeUtf8: (text: string) => Uint8Array<ArrayBuffer>;
10 /**
11 * Encode UTF-8 text to a Uint8Array. The destination must be large enough.
12 */
13 encodeUtf8Into: (text: string, dest: Uint8Array) => {
14 written: number;
15 };
16 /**
17 * Decode UTF-8 text from binary. If `strict` is true, throw on invalid byte
18 * sequences instead of silently substituting U+FFFD. Implementations that
19 * do not support strict decoding may ignore the flag.
20 */
21 decodeUtf8: (bytes: Uint8Array, strict?: boolean) => string;
22 }
23 type TextEncodingConfig = Omit<TextEncoding, "encodeUtf8Into"> & Partial<Pick<TextEncoding, "encodeUtf8Into">>;
24 /**
25 * Protobuf-ES requires the Text Encoding API to convert UTF-8 from and to
26 * binary. This WHATWG API is widely available, but it is not part of the
27 * ECMAScript standard. This function used to be the way to supply an
28 * implementation on runtimes that do not provide one.
29 *
30 * It only configures the copy of the library it is imported from. To provide
31 * the encoding API for every copy of Protobuf-ES in an isolate, install
32 * `TextEncoder` (with the methods `encode` and optionally `encodeInto`) and
33 * `TextDecoder` (with the `fatal: true` constructor argument and the `decode`
34 * method) on `globalThis`.
35 *
36 * Providing `encodeUtf8Into` is optional for backwards compatibility. If it
37 * is omitted, we emulate it with a wrapper that calls `encodeUtf8`.
38 *
39 * Note that the Text Encoding API does not provide a way to validate UTF-8.
40 * Our implementation uses String.prototype.isWellFormed, and falls back
41 * to use encodeURIComponent().
42 *
43 * @deprecated Install `TextEncoder` and `TextDecoder` on `globalThis` instead.
44 */
45 export declare function configureTextEncoding(textEncoding: TextEncodingConfig): void;
46 export declare function getTextEncoding(): TextEncoding;
47 /**
48 * Simplistic polyfill for encodeUtf8Into.
49 *
50 * @private
51 */
52 export declare function emulateEncodeInto(encodeUtf8: (str: string) => Uint8Array): TextEncoding["encodeUtf8Into"];
53 export {};