requireBytes()function

requireBytes(value: PossibleBytes, min = 0, max = Number.POSITIVE_INFINITY, caller: AnyCaller = requireBytes): Uint8Array<ArrayBuffer>
ParamType
valuePossibleBytes
The possible bytes to convert. required
minunknown
Minimum allowed length (defaults to 0). Defaults to 0
maxunknown
Maximum allowed length (defaults to Infinity). Defaults to Number.POSITIVE_INFINITY
callerAnyCaller
Function to attribute a thrown error to (defaults to requireBytes itself). Defaults to requireBytes
Return
Uint8Array<ArrayBuffer>
The converted byte sequence.
Throws
RequiredError
If value cannot be converted or is outside the allowed length range.

Convert a possible set of bytes to a Uint8Array byte sequence, or throw RequiredError if the value cannot be converted.

Examples

requireBytes("abc") // Uint8Array([97, 98, 99])