@hyperfrontend/immutable-api-utils/built-in-copy/encoding

encoding

Locked, prototype-pollution-resistant copies of the global text encoding APIs.

TextEncoder and TextDecoder constructors are wrapped in factories, and atob / btoa references are captured at module-load time and frozen into a tamper-proof namespace, so encoding and base64 work continues to behave correctly even if the globals are later patched. Effective only when imported before any untrusted code has had a chance to mutate the prototype chain.

API Reference

ƒ Functions

§function

atob(data: string): string

(Safe copy) Decodes a base64-encoded string. Use this instead of atob().

Parameters

NameTypeDescription
§data
string
The base64-encoded string to decode.

Returns

string
The decoded string.
§function

btoa(data: string): string

(Safe copy) Encodes a string to base64. Use this instead of btoa().

Parameters

NameTypeDescription
§data
string
The string to encode.

Returns

string
The base64-encoded string.
§function

createTextDecoder(label?: string, options?: TextDecoderOptions): TextDecoder

(Safe copy) Creates a new TextDecoder using the captured TextDecoder constructor. Use this instead of new TextDecoder().

Parameters

NameTypeDescription
§label?
string
The encoding label (e.g., 'utf-8', 'utf-16'). Defaults to 'utf-8'.
§options?
TextDecoderOptions
Optional TextDecoderOptions.

Returns

TextDecoder
A new TextDecoder instance.
§function

createTextEncoder(): TextEncoder

(Safe copy) Creates a new TextEncoder using the captured TextEncoder constructor. Use this instead of new TextEncoder().

Returns

TextEncoder
A new TextEncoder instance.

Variables

§type

Encoding

(Safe copy) Namespace object containing all encoding utilities. Note: Importing this imports all methods in this namespace (no tree-shaking).