Files
common/packages/util/src/string/toHex.ts
T
Jaco 9fc57a23e8 Adjust isHex with template return (#1103)
* Adjust isHex with template return

* Unneeded assignment

* CHANGELOG

* typo

* Additional HexString types

* Additional HexString inputs

* Use U8aLike as applicable

* typo

* Unneeded type

* HexString outputs

* Export types
2021-09-08 14:38:53 +02:00

29 lines
697 B
TypeScript

// Copyright 2017-2021 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { 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
* ```
*/
// eslint-disable-next-line @typescript-eslint/ban-types
export function stringToHex (value?: String | string): HexString {
return u8aToHex(
stringToU8a(value)
);
}