MCPcopy Create free account
hub / github.com/LibPDF-js/core / hexToBytes

Function hexToBytes

src/helpers/buffer.ts:88–102  ·  view source on GitHub ↗
(hex: string)

Source from the content-addressed store, hash-verified

86 * ```
87 */
88export function hexToBytes(hex: string): Uint8Array {
89 // Remove whitespace
90 const clean = hex.replace(/\s/g, "");
91
92 // Pad odd-length with trailing 0
93 const padded = clean.length % 2 === 1 ? `${clean}0` : clean;
94
95 const bytes = new Uint8Array(padded.length / 2);
96
97 for (let i = 0; i < bytes.length; i++) {
98 bytes[i] = Number.parseInt(padded.slice(i * 2, i * 2 + 2), 16);
99 }
100
101 return bytes;
102}

Callers 2

fromHexMethod · 0.90
signMethod · 0.90

Calls 2

parseIntMethod · 0.80
sliceMethod · 0.80

Tested by

no test coverage detected