1 | ;
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.hexAddPrefix = hexAddPrefix;
|
7 |
|
8 | var _hasPrefix = require("./hasPrefix");
|
9 |
|
10 | // Copyright 2017-2022 @polkadot/util authors & contributors
|
11 | // SPDX-License-Identifier: Apache-2.0
|
12 |
|
13 | /**
|
14 | * @name hexAddPrefix
|
15 | * @summary Adds the `0x` prefix to string values.
|
16 | * @description
|
17 | * Returns a `0x` prefixed string from the input value. If the input is already prefixed, it is returned unchanged.
|
18 | * @example
|
19 | * <BR>
|
20 | *
|
21 | * ```javascript
|
22 | * import { hexAddPrefix } from '@polkadot/util';
|
23 | *
|
24 | * console.log('With prefix', hexAddPrefix('0a0b12')); // => 0x0a0b12
|
25 | * ```
|
26 | */
|
27 | function hexAddPrefix(value) {
|
28 | return value && (0, _hasPrefix.hexHasPrefix)(value) ? value : `0x${value && value.length % 2 === 1 ? '0' : ''}${value || ''}`;
|
29 | } |
\ | No newline at end of file |