scratch-parser is a Node.js module designed for parsing and validating Scratch project files, including `.sb2` and `.sb3` formats. Its current stable version is 6.0.0. The library provides programmatic access to the internal structure of Scratch projects, enabling developers to inspect sprites, scripts, assets, and metadata. It has an active development cycle, with bug fixes and dependency updates released periodically, though major versions are less frequent. Key differentiators include its direct integration with the Scratch ecosystem, offering reliable parsing for official Scratch project formats, and its focus on providing a structured JavaScript object representation of the project data.
npm install scratch-parserVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to read a Scratch project file from disk and parse it using the `scratch-parser` library, handling potential errors and logging basic project information.
Review your project's licensing compatibility with AGPL-3.0-only. If incompatible, you may need to remain on an older version or find an alternative.
Ensure that any SB2 files provided to the parser are not gzipped. If you previously handled gzipped files, you must decompress them manually before passing the buffer to `scratch-parser`.
Always validate the input buffer for integrity if it originates from an untrusted source. Implement robust error handling around parser calls.
When accessing `project.info` fields, always check for their existence before using them (e.g., `project.info?.flashVersion`).
Ensure you are on the latest version to benefit from bug fixes related to character parsing. If on an affected version, be aware that strings like `\b` might be misparsed.
Verify the integrity and format of the input file. Ensure it's a `.sb2` or `.sb3` file and that the buffer correctly contains its contents. Check that gzipped SB2 files are decompressed before passing them to the parser (v5.0.0+).
Implement robust error handling around the parser callback and defensively check for the existence of properties before accessing them (e.g., `if (project && project.targets) { ... }`).Double-check the file path and ensure the file exists at the specified location. Use absolute paths or correctly resolve relative paths.
No dependency data recorded yet.