(text: string)
| 154 | } |
| 155 | |
| 156 | const encodeUtf8 = (text: string): Uint8Array => { |
| 157 | const length = text.length |
| 158 | if (length <= asciiEncodeLimit) { |
| 159 | const bytes = new Uint8Array(length) |
| 160 | let i = 0 |
| 161 | for (; i < length; i++) { |
| 162 | const code = text.charCodeAt(i) |
| 163 | if (code > 0x7f) break |
| 164 | bytes[i] = code |
| 165 | } |
| 166 | if (i === length) return bytes |
| 167 | } |
| 168 | const written = encodeUtf8Scratch(text) |
| 169 | return written === -1 ? textEncoder.encode(text) : scratchUtf8.slice(0, written) |
| 170 | } |
| 171 | |
| 172 | /** As `encodeUtf8`, but leaves `prefix` bytes free at the front. */ |
| 173 | const encodeUtf8Prefixed = (text: string, prefix: number): Uint8Array => { |
no test coverage detected