We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9760615 commit ffeacf5Copy full SHA for ffeacf5
packages/thirdweb/src/utils/encoding/helpers/role-bytes.ts
@@ -0,0 +1,20 @@
1
+import { type Hex, isHex } from "../hex.js";
2
+
3
+/**
4
+ * Calculates the byte size of a Hex string or Uint8Array.
5
+ * If the value is a Hex string, it accounts for the leading "0x" prefix.
6
+ * @param value The Hex string or Uint8Array.
7
+ * @returns The byte size of the value.
8
+ * @example
9
+ * ```ts
10
+ * import { byteSize } from "thirdweb/utils";
11
+ * const size = byteSize("0x1a4");
12
+ * console.log(size); // 2
13
+ * ```
14
+ */
15
+export function byteSize(value: Hex | Uint8Array) {
16
+ if (isHex(value, { strict: false })) {
17
+ return Math.ceil((value.length - 2) / 2);
18
+ }
19
+ return value.length;
20
+}
0 commit comments