Files
common/packages/util/src/string/toHex.ts
T
Jaco 5fdd967666 Small consistency cleanups (#1178)
* Small consistency cleanups

* Adjust

* Adjust
2021-11-13 17:39:52 +02:00

28 lines
645 B
TypeScript

// Copyright 2017-2021 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { AnyString, HexString } from '../types';
import { u8aToHex } from '../u8a/toHex';
import { stringToU8a } from './toU8a';
/**
* @name stringToHex
* @summary Creates a hex string from a utf-8 string
* @description
* String input values return the actual encoded hex value.
* @example
* <BR>
*
* ```javascript
* import { stringToHex } from '@polkadot/util';
*
* stringToU8a('hello'); // 0x68656c6c6f
* ```
*/
export function stringToHex (value?: AnyString): HexString {
return u8aToHex(
stringToU8a(value)
);
}