FITS file format implementation for JavaScript runtimes
Issues
·
Contributing
·
Docs
Note
This project is in early development and is not recommended for production usage, but feedback is very welcome on GitHub.
FITS (Flexible Image Transport System) is the container format astronomy runs on. Telescopes, sky surveys, and public data archives store images and tabular catalogs as FITS. A sequence of header-and-data units holds N-dimensional image arrays, binary and ASCII tables, and optionally tile-compressed image data.
fits-js reads and writes FITS in TypeScript. The parser handles the full header grammar (including CONTINUE and HIERARCH), the image decoder covers every BITPIX with astropy-parity scaling, and I/O goes through a small web-standard byte-source interface, so the same code runs on Node, Bun, Deno, Cloudflare Workers, and the browser. @fits-js/core carries no runtime dependencies.
npm install @fits-js/coreimport { NodeFileReader, openFits, readImage } from "@fits-js/core";
const reader = await NodeFileReader.open("data/image.fits");
try {
const { hdus } = await openFits(reader);
const region = { start: [0, 0], shape: [16, 16] };
const { data } = await readImage(hdus[0], reader, { region });
console.log(data.slice(0, 8));
} finally {
await reader.close();
}openFits enumerates HDUs and reads only header blocks. readImage with a region reads only the bytes that region covers, so a small cutout from a multi-gigabyte cube stays cheap. HttpRangeReader and BlobReader are the byte-source adapters for URLs and browser File inputs.
Requires Node 22 or later. In the browser, any environment with fetch, Blob, and TypedArray works.
| Package | Description |
|---|---|
@fits-js/core |
Parser, image decoder, and four RandomAccessReader implementations (in-memory, Blob/File, Node file, HTTP Range) |
Full docs at prustic.github.io/fits-js.
fits-js is free and open source, licensed under Apache-2.0.
If you discover a security vulnerability, please see SECURITY.md for how to report it responsibly.