gx
chenyc
2025-06-12 7b72ac13a83764a662159d4a49b7fffb90476ecb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
export class PlatformBrowser {
  private textEncoder: TextEncoder;
 
  constructor() {
    this.textEncoder = new TextEncoder();
  }
 
  fetch(path: string, init?: any): Promise<Response> {
    return fetch(path, init);
  }
 
  now(): number {
    return performance.now();
  }
 
  encode(text: string, encoding: string): Uint8Array {
    if (encoding !== 'utf-8' && encoding !== 'utf8') {
      throw new Error(`Browser's encoder only supports utf-8, but got ${encoding}`);
    }
    return this.textEncoder.encode(text);
  }
 
  decode(bytes: Uint8Array, encoding: string): string {
    return new TextDecoder(encoding).decode(bytes);
  }
}