Web standards
边缘函数基于 V8 JavaScript 引擎设计实现的 Serverless 代码执行环境,提供了以下标准化的 Web APIs。
JavaScript 标准内置对象
URL
const urlInfo = new URL('https://www.tencentcloud.com/');
Blob
const blob = new Blob(['hello', 'world'], { type: 'text/plain' });
Base64
btoa
function btoa(data: string | ArrayBuffer | ArrayBufferView): string;
atob
function atob(data: string): string;
btoaUTF8
function btoaUTF8(data: string): string;
执行 base64 编码,支持 Unicode 字符串。
atobUTF8
function atobUTF8(data: string): string;
执行 base64 解码,不支持 Unicode 字符串。
定时器
setTimeout
setTimeout(func: function): number;setTimeout(func: function, delay: number): number;setTimeout(func: function, delay: number, ...args: any[]): number;
clearTimeout
clearTimeout(timeoutID: number): void;
setInterval
setInterval(func: function): number;setInterval(func: function, delay: number): number;setInterval(func: function, delay: number, ...args: any[]): number;
clearInterval
clearInterval(intervalID: number): void;
setImmediate
setImmediate(func: function): number;setImmediate(func: function, ...args: any[]): number;
clearImmediate
clearImmediate(immediateID: number): void;
事件发布与订阅
EventTarget
const eventTarget = new EventTarget();
Event
const event = new Event('type name');
中止信号与控制器
AbortSignal
const signal = AbortSignal.abort();
AbortController
const controller = new AbortController();
解压缩流
CompressionStream
const { readable, writable } = new CompressionStream('gzip');
DecompressionStream
const { readable, writable } = new DecompressionStream('gzip');