- Index component property definitions and variable asset references once per export or override context\n- Skip converged instance fill and text propagation and use native binary hex encoding\n- Add a non-populating parse mode for raw fixture validation\n- Reduce the Material 3 round trip from minutes to about twenty seconds
24 lines
848 B
TypeScript
24 lines
848 B
TypeScript
export function hexToBytes(hex: string): Uint8Array {
|
|
if (hex.length % 2 !== 0) {
|
|
throw new Error('Hex string must contain an even number of characters')
|
|
}
|
|
|
|
const bytes = new Uint8Array(hex.length / 2)
|
|
for (let i = 0; i < bytes.length; i++) {
|
|
const byte = Number.parseInt(hex.slice(i * 2, i * 2 + 2), 16)
|
|
if (Number.isNaN(byte)) throw new Error('Hex string contains invalid characters')
|
|
bytes[i] = byte
|
|
}
|
|
return bytes
|
|
}
|
|
|
|
const HEX_BYTES = Array.from({ length: 256 }, (_, byte) => byte.toString(16).padStart(2, '0'))
|
|
|
|
export function bytesToHex(bytes: Uint8Array): string {
|
|
if (typeof bytes.toHex === 'function') return bytes.toHex()
|
|
|
|
const chunks = Array.from({ length: bytes.length }, () => '')
|
|
for (let index = 0; index < bytes.length; index++) chunks[index] = HEX_BYTES[bytes[index]]
|
|
return chunks.join('')
|
|
}
|