| 127 | } |
| 128 | |
| 129 | export class PlatformReactNative implements Platform { |
| 130 | /** |
| 131 | * Makes an HTTP request. |
| 132 | * |
| 133 | * see @fetch docs above. |
| 134 | */ |
| 135 | async fetch( |
| 136 | path: string, |
| 137 | init?: RequestInit, |
| 138 | options?: tf.io.RequestDetails |
| 139 | ) { |
| 140 | return fetch(path, init, options); |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * Encode the provided string into an array of bytes using the provided |
| 145 | * encoding. |
| 146 | */ |
| 147 | encode(text: string, encoding: string): Uint8Array { |
| 148 | // See https://www.w3.org/TR/encoding/#utf-16le |
| 149 | if (encoding === "utf-16") { |
| 150 | encoding = "utf16le"; |
| 151 | } |
| 152 | return new Uint8Array(Buffer.from(text, encoding as BufferEncoding)); |
| 153 | } |
| 154 | /** Decode the provided bytes into a string using the provided encoding. */ |
| 155 | decode(bytes: Uint8Array, encoding: string): string { |
| 156 | // See https://www.w3.org/TR/encoding/#utf-16le |
| 157 | if (encoding === "utf-16") { |
| 158 | encoding = "utf16le"; |
| 159 | } |
| 160 | return Buffer.from(bytes).toString(encoding as BufferEncoding); |
| 161 | } |
| 162 | |
| 163 | now(): number { |
| 164 | //@ts-ignore |
| 165 | if (global.nativePerformanceNow) { |
| 166 | //@ts-ignore |
| 167 | return global.nativePerformanceNow(); |
| 168 | } |
| 169 | return Date.now(); |
| 170 | } |
| 171 | |
| 172 | setTimeoutCustom() { |
| 173 | throw new Error("react native does not support setTimeoutCustom"); |
| 174 | } |
| 175 | |
| 176 | isTypedArray( |
| 177 | a: unknown |
| 178 | ): a is Uint8Array | Float32Array | Int32Array | Uint8ClampedArray { |
| 179 | return ( |
| 180 | a instanceof Float32Array || |
| 181 | a instanceof Int32Array || |
| 182 | a instanceof Uint8Array || |
| 183 | a instanceof Uint8ClampedArray |
| 184 | ); |
| 185 | } |
| 186 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…