Utilities
Three standalone helpers are exported for convenience. The library uses them internally; they are exposed because they are handy when working with the same formats by hand.
md5(input)
input:Uint8Array | ArrayBuffer— bytes to hash.- Returns:
string— 32-character lowercase hex digest.
Compute the lowercase hex MD5 digest of some bytes. This is a dependency-free,
pure-JS implementation of RFC 1321 that runs identically in Node and the browser.
Scratch names asset files by the MD5 of their bytes, which is why the library
needs it — and why md5(bytes) matches the assetId of a costume/sound holding
those same bytes.
uid()
- Returns:
string— a fresh 20-character Scratch-style id.
Generate a unique id drawn from the same character "soup" Scratch uses for
blocks, variables, lists and broadcasts, so generated ids look native and stay
clear of JSON-unsafe characters. Use it when writing raw
blocks or other id-keyed entries by hand.
Ids are random per call. The library's setVariable / setList /
addBroadcast already mint ids for you — reach for uid() only for low-level
edits the typed API doesn't cover, such as authoring blocks.
sniffFormat(bytes)
bytes:Uint8Array— the asset contents.- Returns:
string | undefined— the detecteddataFormat, orundefinedif unknown.
Guess a Scratch dataFormat (file extension) from raw asset bytes by inspecting
their leading bytes. Recognises:
This is what lets addCostume and
addSound accept a bare buffer without you spelling out
dataFormat. When detection fails they fall back to png / wav respectively;
pass options.dataFormat to be explicit.