1 | ;
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.hexAddPrefix = void 0;
|
4 | const hasPrefix_js_1 = require("./hasPrefix.js");
|
5 | /**
|
6 | * @name hexAddPrefix
|
7 | * @summary Adds the `0x` prefix to string values.
|
8 | * @description
|
9 | * Returns a `0x` prefixed string from the input value. If the input is already prefixed, it is returned unchanged.
|
10 | * @example
|
11 | * <BR>
|
12 | *
|
13 | * ```javascript
|
14 | * import { hexAddPrefix } from '@polkadot/util';
|
15 | *
|
16 | * console.log('With prefix', hexAddPrefix('0a0b12')); // => 0x0a0b12
|
17 | * ```
|
18 | */
|
19 | function hexAddPrefix(value) {
|
20 | return value && (0, hasPrefix_js_1.hexHasPrefix)(value)
|
21 | ? value
|
22 | : `0x${value && value.length % 2 === 1 ? '0' : ''}${value || ''}`;
|
23 | }
|
24 | exports.hexAddPrefix = hexAddPrefix;
|