MCPcopy Create free account
hub / github.com/wevm/viem / bytesToBool

Function bytesToBool

src/utils/encoding/fromBytes.ts:149–161  ·  view source on GitHub ↗
(
  bytes_: ByteArray,
  opts: BytesToBoolOpts = {},
)

Source from the content-addressed store, hash-verified

147 * // true
148 */
149export function bytesToBool(
150 bytes_: ByteArray,
151 opts: BytesToBoolOpts = {},
152): boolean {
153 let bytes = bytes_
154 if (typeof opts.size !== 'undefined') {
155 assertSize(bytes, { size: opts.size })
156 bytes = trim(bytes)
157 }
158 if (bytes.length > 1 || bytes[0] > 1)
159 throw new InvalidBytesBooleanError(bytes)
160 return Boolean(bytes[0])
161}
162
163export type BytesToNumberOpts = BytesToBigIntOpts
164

Callers 3

fromBytesFunction · 0.85
fromBytes.test.tsFile · 0.85
decodeBoolFunction · 0.85

Calls 2

assertSizeFunction · 0.85
trimFunction · 0.85

Tested by

no test coverage detected