27 lines
674 B
TypeScript
27 lines
674 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 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 default function stringToHex (value?: string): string {
|
|
return u8aToHex(
|
|
stringToU8a(value)
|
|
);
|
|
}
|