* Aligh u8aToHex optimization * Adjust * Fix failing tests, empty value * Adjust * numberToHex fix * Fix hexFixLength tests
25 lines
629 B
TypeScript
25 lines
629 B
TypeScript
// Copyright 2017-2021 @polkadot/util authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import type { HexString } from '../types';
|
|
|
|
import { isHex } from '../is/hex';
|
|
|
|
/**
|
|
* @name hexHasPrefix
|
|
* @summary Tests for the existence of a `0x` prefix.
|
|
* @description
|
|
* Checks for a valid hex input value and if the start matched `0x`
|
|
* @example
|
|
* <BR>
|
|
*
|
|
* ```javascript
|
|
* import { hexHasPrefix } from '@polkadot/util';
|
|
*
|
|
* console.log('has prefix', hexHasPrefix('0x1234')); // => true
|
|
* ```
|
|
*/
|
|
export function hexHasPrefix (value?: string | null): value is HexString {
|
|
return !!value && isHex(value, -1);
|
|
}
|