The string to encode
Optionalformat: "uint8"Output format (default: 'uint8')
The encoded bytes
Encode a string to UTF-8 bytes (strict mode)
Throws on invalid Unicode (unpaired surrogates)
This is similar to the following snippet (but works on all engines):
// Strict encode, requiring Unicode codepoints to be valid
if (typeof string !== 'string' || !string.isWellFormed()) throw new TypeError()
return new TextEncoder().encode(string)
The string to encode
Output format (default: 'uint8')
The encoded bytes
Encode a string to UTF-8 bytes (strict mode)
Throws on invalid Unicode (unpaired surrogates)
This is similar to the following snippet (but works on all engines):
// Strict encode, requiring Unicode codepoints to be valid
if (typeof string !== 'string' || !string.isWellFormed()) throw new TypeError()
return new TextEncoder().encode(string)
The string to encode
Output format (default: 'uint8')
The encoded bytes
Encode a string to UTF-8 bytes (strict mode)
Throws on invalid Unicode (unpaired surrogates)
This is similar to the following snippet (but works on all engines):
// Strict encode, requiring Unicode codepoints to be valid
if (typeof string !== 'string' || !string.isWellFormed()) throw new TypeError()
return new TextEncoder().encode(string)
The string to encode
Optionalformat: OutputFormatOutput format (default: 'uint8')
The encoded bytes
Encode a string to UTF-8 bytes (strict mode)
Throws on invalid Unicode (unpaired surrogates)
This is similar to the following snippet (but works on all engines):