MCPcopy Create free account
hub / github.com/tensorflow/tfjs / encode

Method encode

tfjs-core/src/platforms/platform_browser.ts:47–56  ·  view source on GitHub ↗
(text: string, encoding: string)

Source from the content-addressed store, hash-verified

45 }
46
47 encode(text: string, encoding: string): Uint8Array {
48 if (encoding !== 'utf-8' && encoding !== 'utf8') {
49 throw new Error(
50 `Browser's encoder only supports utf-8, but got ${encoding}`);
51 }
52 if (this.textEncoder == null) {
53 this.textEncoder = new TextEncoder();
54 }
55 return this.textEncoder.encode(text);
56 }
57 decode(bytes: Uint8Array, encoding: string): string {
58 return new TextDecoder(encoding).decode(bytes);
59 }

Callers

nothing calls this directly

Calls 1

encodeMethod · 0.65

Tested by

no test coverage detected