isHex(value): value is string (#1031)

* isHex stringisHex(value): value is string

* lint
This commit is contained in:
Jaco
2021-06-23 15:47:42 +02:00
committed by GitHub
parent dc06b87cdd
commit 902ff47337
3 changed files with 3 additions and 3 deletions
+1 -1
View File
@@ -18,7 +18,7 @@ const HEX_REGEX = /^0x[a-fA-F0-9]+$/;
* isHex('0x1234', 8); // => false
* ```
*/
export function isHex (value: unknown, bitLength = -1, ignoreLength = false): value is `0x${string}` {
export function isHex (value: unknown, bitLength = -1, ignoreLength = false): value is string {
return (typeof value === 'string' && (value === '0x' || HEX_REGEX.test(value)))
? bitLength === -1
? ((value.length % 2 === 0) || ignoreLength)