UNPKG

823 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.numberToU8a = void 0;
4const toU8a_js_1 = require("../hex/toU8a.js");
5const toHex_js_1 = require("./toHex.js");
6/**
7 * @name numberToU8a
8 * @summary Creates a Uint8Array object from a number.
9 * @description
10 * `null`/`undefined`/`NaN` inputs returns an empty `Uint8Array` result. `number` input values return the actual bytes value converted to a `Uint8Array`. With `bitLength`, it converts the value to the equivalent size.
11 * @example
12 * <BR>
13 *
14 * ```javascript
15 * import { numberToU8a } from '@polkadot/util';
16 *
17 * numberToU8a(0x1234); // => [0x12, 0x34]
18 * ```
19 */
20function numberToU8a(value, bitLength = -1) {
21 return (0, toU8a_js_1.hexToU8a)((0, toHex_js_1.numberToHex)(value, bitLength));
22}
23exports.numberToU8a = numberToU8a;