Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F4503869
test_uint8array_base64_hex.cjs
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
test_uint8array_base64_hex.cjs
View Options
function assert(condition, message) {
if (!condition) throw new Error(message);
}
const bytes = new Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100]);
assert(bytes.toHex() === "48656c6c6f20576f726c64", "Uint8Array.prototype.toHex");
assert(bytes.toBase64() === "SGVsbG8gV29ybGQ=", "Uint8Array.prototype.toBase64");
const fromHex = Uint8Array.fromHex("48656c6c6f20576f726c64");
assert(fromHex.length === bytes.length, "Uint8Array.fromHex length");
assert(bytes.every((value, index, array) => array === bytes && value === fromHex[index]), "Uint8Array.fromHex bytes");
const fromBase64 = Uint8Array.fromBase64("SGVsbG8gV29ybGQ=");
assert(fromBase64.length === bytes.length, "Uint8Array.fromBase64 length");
assert(bytes.every((value, index) => value === fromBase64[index]), "Uint8Array.fromBase64 bytes");
const hexTarget = new Uint8Array(16);
const hexResult = hexTarget.setFromHex("48656c6c6f20576f726c64");
assert(hexResult.read === 22, "Uint8Array.setFromHex read count");
assert(hexResult.written === 11, "Uint8Array.setFromHex written count");
assert(bytes.every((value, index) => value === hexTarget[index]), "Uint8Array.setFromHex bytes");
const base64Target = new Uint8Array(16);
const base64Result = base64Target.setFromBase64("SGVsbG8gV29ybGQ=");
assert(base64Result.read === 16, "Uint8Array.setFromBase64 read count");
assert(base64Result.written === 11, "Uint8Array.setFromBase64 written count");
assert(bytes.every((value, index) => value === base64Target[index]), "Uint8Array.setFromBase64 bytes");
console.log("Uint8Array base64/hex tests completed!");
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, May 3, 9:37 AM (1 d, 8 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
542848
Default Alt Text
test_uint8array_base64_hex.cjs (1 KB)
Attached To
Mode
rANT Ant
Attached
Detach File
Event Timeline
Log In to Comment