2020-10-11 18:41:17 +02:00
|
|
|
export class PlatformBrowser {
|
|
|
|
private textEncoder: TextEncoder;
|
|
|
|
|
2021-01-24 17:08:04 +01:00
|
|
|
fetch(path: string, init?: any): Promise<Response> {
|
2020-10-11 18:41:17 +02:00
|
|
|
return fetch(path, init);
|
|
|
|
}
|
|
|
|
|
|
|
|
now(): number {
|
|
|
|
return performance.now();
|
|
|
|
}
|
|
|
|
|
|
|
|
encode(text: string, encoding: string): Uint8Array {
|
|
|
|
if (encoding !== 'utf-8' && encoding !== 'utf8') {
|
2020-12-27 00:35:17 +01:00
|
|
|
throw new Error(`Browser's encoder only supports utf-8, but got ${encoding}`);
|
2020-10-11 18:41:17 +02:00
|
|
|
}
|
|
|
|
if (this.textEncoder == null) {
|
|
|
|
this.textEncoder = new TextEncoder();
|
|
|
|
}
|
|
|
|
return this.textEncoder.encode(text);
|
|
|
|
}
|
2020-12-27 00:35:17 +01:00
|
|
|
|
2020-10-11 18:41:17 +02:00
|
|
|
decode(bytes: Uint8Array, encoding: string): string {
|
|
|
|
return new TextDecoder(encoding).decode(bytes);
|
|
|
|
}
|
|
|
|
}
|