isHex(value): value is string (#1031)
* isHex stringisHex(value): value is string * lint
This commit is contained in:
@@ -29,6 +29,6 @@ export function decodeAddress (encoded?: string | Uint8Array | null, ignoreCheck
|
||||
|
||||
return decoded.slice(ss58Length, endPos);
|
||||
} catch (error) {
|
||||
throw new Error(`Decoding ${encoded}: ${(error as Error).message}`);
|
||||
throw new Error(`Decoding ${encoded as string}: ${(error as Error).message}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user