isHex
Checks whether the value is a hex value or not.
Install
import { isHex } from 'viem'Usage
import { isHex } from 'viem'
isHex('0x1a4')
// true
isHex('0x1a4z')
isHex('foo')
// falseReturns
boolean
Returns truthy is the value is a hex value.
Parameters
value
- Type:
unknown
The value to check.
isHex(
'0x1a4'
)
// trueoptions.strict
- Type:
boolean - Default:
true
When enabled, checks if the value strictly consists of only hex characters ("0x[0-9a-fA-F]*").
When disabled, checks if the value loosely matches hex format (value.startsWith('0x')).
isHex('0xlol', { strict: false })
// true
isHex('0xlol', { strict: true })
// false
isHex('lol', { strict: false })
// false