t-comm
Version:
专业、稳定、纯粹的工具库
26 lines (25 loc) • 861 B
TypeScript
/**
* 将字符串编码为 Base64 格式
* 支持 Unicode 字符(包括中文、emoji 等),兼容小程序环境
* @param str - 要编码的字符串
* @returns Base64 编码后的字符串
* @example
* ```ts
* encode('Hello World'); // 'SGVsbG8gV29ybGQ='
* encode('你好世界'); // '5L2g5aW95LiW55WM'
* encode('😀'); // '8J+YgA=='
* ```
*/
export declare const encode: (str: string) => string;
/**
* Base64 编码的内部实现(小程序版本的 btoa)
* 将 Latin1 范围内的字符串编码为 Base64
* @param string - 要编码的字符串(仅支持 Latin1 字符)
* @returns Base64 编码后的字符串
* @throws {TypeError} 当字符串包含 Latin1 范围外的字符时抛出错误
* @example
* ```ts
* innerEncode('Hello'); // 'SGVsbG8='
* ```
*/
export declare const innerEncode: (string: string) => string;