Files
common/packages/util/src/hex/hasPrefix.ts
T
Jaco Greeff 89030f41b3 2019 (#287)
* 2019

* Bump deps

* Cleanup deps

* Update dev (markdown plugin)

* Bump deps (hopefully finally fixes doc gen)

* Fix inherit plugin
2019-01-04 14:50:50 +01:00

25 lines
771 B
TypeScript

// Copyright 2017-2019 @polkadot/util authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import isHex from '../is/hex';
/**
* @name hexHasPrefix
* @signature hexHasPrefix (value: ?string): boolean
* @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 default function hexHasPrefix (value: string | null | undefined): boolean {
return !!(value && isHex(value, -1, true) && value.substr(0, 2) === '0x');
}