Adjust isHex with template return (#1103)
* Adjust isHex with template return * Unneeded assignment * CHANGELOG * typo * Additional HexString types * Additional HexString inputs * Use U8aLike as applicable * typo * Unneeded type * HexString outputs * Export types
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { HexString } from '../types';
|
||||
|
||||
const HEX_REGEX = /^0x[a-fA-F0-9]+$/;
|
||||
|
||||
/**
|
||||
@@ -18,7 +20,7 @@ const HEX_REGEX = /^0x[a-fA-F0-9]+$/;
|
||||
* isHex('0x1234', 8); // => false
|
||||
* ```
|
||||
*/
|
||||
export function isHex (value: unknown, bitLength = -1, ignoreLength = false): value is string {
|
||||
export function isHex (value: unknown, bitLength = -1, ignoreLength = false): value is HexString {
|
||||
return (typeof value === 'string' && (value === '0x' || HEX_REGEX.test(value)))
|
||||
? bitLength === -1
|
||||
? ((value.length % 2 === 0) || ignoreLength)
|
||||
|
||||
Reference in New Issue
Block a user