Base64 API
encodeBase64Bytes Encode
Encodes arbitrary bytes as standard Base64.
Signature
ts
export function encodeBase64Bytes(bytes: Uint8Array): string;Example
ts
import { encodeBase64Bytes } from "@fast-china/utils";
const result = encodeBase64Bytes(new Uint8Array([70, 97, 115, 116]));
console.log(result); // "RmFzdA=="Input
| Input | Type | Required / default | Description |
|---|---|---|---|
bytes | Uint8Array | Required | Byte sequence; not mutated. |
Returns
| Value | Type | Description |
|---|---|---|
result | string | Base64 text with standard = padding. |
decodeBase64Bytes Decode
Decodes standard Base64.
Signature
ts
export function decodeBase64Bytes(value: string): Uint8Array;Example
ts
import { decodeBase64Bytes } from "@fast-china/utils";
const result = decodeBase64Bytes("RmFzdA==");Input
| Input | Type | Required / default | Description |
|---|---|---|---|
value | string | Required | Base64 text. |
Returns
| Value | Type | Description |
|---|---|---|
result | Uint8Array | New byte array. |
encodeBase64 Encode
Encodes UTF-8 text as standard Base64.
Signature
ts
export function encodeBase64(value: string): string;Example
ts
import { encodeBase64 } from "@fast-china/utils";
const result = encodeBase64("Fast 文档");Input
| Input | Type | Required / default | Description |
|---|---|---|---|
value | string | Required | Any Unicode string. |
Returns
| Value | Type | Description |
|---|---|---|
result | string | Base64 text with standard padding. |
decodeBase64 Decode
Decodes standard Base64 into UTF-8 text.
Signature
ts
export function decodeBase64(value: string): DecodedText;Example
ts
import { decodeBase64 } from "@fast-china/utils";
const result = decodeBase64("RmFzdA==");Input
| Input | Type | Required / default | Description |
|---|---|---|---|
value | string | Required | Base64 text. |
Returns
| Value | Type | Description |
|---|---|---|
result | DecodedText | Raw Unicode string usable directly or through explicit .parseJson<Value>(). |
encodeBase64UrlBytes Encode
Encodes arbitrary bytes as unpadded Base64URL.
Signature
ts
export function encodeBase64UrlBytes(bytes: Uint8Array): string;Example
ts
import { encodeBase64UrlBytes } from "@fast-china/utils";
const result = encodeBase64UrlBytes(new Uint8Array([70, 97, 115, 116]));Input
| Input | Type | Required / default | Description |
|---|---|---|---|
bytes | Uint8Array | Required | Byte sequence; not mutated. |
Returns
| Value | Type | Description |
|---|---|---|
result | string | Text using only the URL-safe alphabet. |
decodeBase64UrlBytes Decode
Decodes Base64URL bytes.
Signature
ts
export function decodeBase64UrlBytes(value: string): Uint8Array;Example
ts
import { decodeBase64UrlBytes } from "@fast-china/utils";
const result = decodeBase64UrlBytes("RmFzdA");Input
| Input | Type | Required / default | Description |
|---|---|---|---|
value | string | Required | Base64URL text. |
Returns
| Value | Type | Description |
|---|---|---|
result | Uint8Array | New byte array. |
encodeBase64Url Encode
Encodes UTF-8 text as unpadded Base64URL.
Signature
ts
export function encodeBase64Url(value: string): string;Example
ts
import { encodeBase64Url } from "@fast-china/utils";
const result = encodeBase64Url("Fast 文档");Input
| Input | Type | Required / default | Description |
|---|---|---|---|
value | string | Required | Any Unicode string. |
Returns
| Value | Type | Description |
|---|---|---|
result | string | Text using only the URL-safe alphabet. |
decodeBase64Url Decode
Decodes Base64URL into UTF-8 text.
Signature
ts
export function decodeBase64Url(value: string): DecodedText;Example
ts
import { decodeBase64Url } from "@fast-china/utils";
const result = decodeBase64Url("RmFzdA");Input
| Input | Type | Required / default | Description |
|---|---|---|---|
value | string | Required | Padded or unpadded Base64URL text. |
Returns
| Value | Type | Description |
|---|---|---|
result | DecodedText | Raw Unicode string usable directly or through explicit .parseJson<Value>(). |
encodeLatin1Base64 Encode
Encodes Latin-1 text as standard Base64.
Signature
ts
export function encodeLatin1Base64(value: string): string;Example
ts
import { encodeLatin1Base64 } from "@fast-china/utils";
const result = encodeLatin1Base64("Fast");Input
| Input | Type | Required / default | Description |
|---|---|---|---|
value | string | Required | Text whose UTF-16 code units are all between 0 and 255. |
Returns
| Value | Type | Description |
|---|---|---|
result | string | Base64 text with standard padding. |
decodeLatin1Base64 Decode
Decodes standard Base64 into Latin-1 text.
Signature
ts
export function decodeLatin1Base64(value: string): DecodedText;Example
ts
import { decodeLatin1Base64 } from "@fast-china/utils";
const result = decodeLatin1Base64("RmFzdA==");Input
| Input | Type | Required / default | Description |
|---|---|---|---|
value | string | Required | Standard Base64 text; ASCII whitespace and omitted trailing padding are accepted. |
Returns
| Value | Type | Description |
|---|---|---|
result | DecodedText | Raw Latin-1 string usable directly or through explicit .parseJson<Value>(). |
encodeSecureBase64 Encode
Encodes text with a fixed dictionary and random prefix.
Signature
ts
export function encodeSecureBase64(value: string, prefixLength: number = defaultRandomPrefixLength): string;Example
ts
import { encodeSecureBase64 } from "@fast-china/utils";
const result = encodeSecureBase64("Fast");Input
| Input | Type | Required / default | Description |
|---|---|---|---|
value | string | Required | Unicode text accepted by encodeURIComponent. |
prefixLength | number | Optional; defaults to defaultRandomPrefixLength | Random alphabetic prefix length; defaults to 6. |
Returns
| Value | Type | Description |
|---|---|---|
result | string | Base64 text with a random prefix and compatibility dictionary characters; empty input returns an empty string. |
decodeSecureBase64 Decode
Decodes the SecureBase64 compatibility format.
Signature
ts
export function decodeSecureBase64(value: string, prefixLength: number = defaultRandomPrefixLength): DecodedText;Example
ts
import { decodeSecureBase64, encodeSecureBase64 } from "@fast-china/utils";
const payload = encodeSecureBase64("Fast");
const result = decodeSecureBase64(payload);Input
| Input | Type | Required / default | Description |
|---|---|---|---|
value | string | Required | SecureBase64 text; use the same prefix length as encoding. |
prefixLength | number | Optional; defaults to defaultRandomPrefixLength | Prefix length to remove; defaults to 6. A value of 0 removes no dictionary characters. |
Returns
| Value | Type | Description |
|---|---|---|
result | DecodedText | Raw Unicode string usable directly or through explicit .parseJson<Value>(); empty input returns an empty string. |
DecodedText.parseJson Parse
Explicitly attempts JSON parsing of a decoded or decrypted raw string.
Signature
ts
parseJson<Value = any>(): Value;Example
ts
import { decodeBase64 } from "@fast-china/utils";
const text = decodeBase64("eyJpZCI6MX0=");
const result = text.parseJson<{ id: number }>();Input
This method has no input parameters.
Returns
| Value | Type | Description |
|---|---|---|
result | Value | Parsed result for valid JSON; otherwise the original string. The generic type performs no runtime validation. |
