1 | ;
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.stringToU8a = stringToU8a;
|
7 |
|
8 | var _xTextencoder = require("@polkadot/x-textencoder");
|
9 |
|
10 | // Copyright 2017-2022 @polkadot/util authors & contributors
|
11 | // SPDX-License-Identifier: Apache-2.0
|
12 | const encoder = new _xTextencoder.TextEncoder();
|
13 | /**
|
14 | * @name stringToU8a
|
15 | * @summary Creates a Uint8Array object from a utf-8 string.
|
16 | * @description
|
17 | * String input values return the actual encoded `UInt8Array`. `null` or `undefined` values returns an empty encoded array.
|
18 | * @example
|
19 | * <BR>
|
20 | *
|
21 | * ```javascript
|
22 | * import { stringToU8a } from '@polkadot/util';
|
23 | *
|
24 | * stringToU8a('hello'); // [0x68, 0x65, 0x6c, 0x6c, 0x6f]
|
25 | * ```
|
26 | */
|
27 | // eslint-disable-next-line @typescript-eslint/ban-types
|
28 |
|
29 | function stringToU8a(value) {
|
30 | return value ? encoder.encode(value.toString()) : new Uint8Array();
|
31 | } |
\ | No newline at end of file |