MCPcopy Create free account
hub / github.com/Effect-TS/effect / encodeUtf8

Function encodeUtf8

packages/sql/pg/src/PgTypes.ts:156–170  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

154}
155
156const 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. */
173const encodeUtf8Prefixed = (text: string, prefix: number): Uint8Array => {

Callers 1

PgTypes.tsFile · 0.85

Calls 3

encodeUtf8ScratchFunction · 0.85
encodeMethod · 0.80
sliceMethod · 0.80

Tested by

no test coverage detected