@fits-js/core
v0.1.0
Published
FITS file parser for JavaScript and TypeScript, in Node and the browser, with no runtime dependencies
Maintainers
Readme
@fits-js/core
FITS parser, image decoder, and byte-source readers for JavaScript runtimes, in pure TypeScript with zero runtime dependencies.
Note: This project is in early development and is not recommended for production usage, but feedback is very welcome on GitHub.
Install
npm install @fits-js/coreRequires Node 22 or later. In the browser, any environment with fetch, Blob, and TypedArray works.
Quick example
import { 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();
}Public surface
openFits(reader)enumerates HDUs lazily, reading only header blocks.readImage(hdu, reader, { region? })decodes a 2D or higher image HDU. With aregion, only the bytes covering that cutout are fetched.RandomAccessReaderimplementations:BytesReader(in-memory),BlobReader(browserBlob/File),HttpRangeReader(HTTPRangewith LRU paging andIf-Range),NodeFileReader(fs-backed).FitsHeaderwith typed accessors (getNumber,getString,getBoolean,get,getAll).- Typed error hierarchy:
FitsError,FitsHeaderError,FitsStructureError,FitsUnsupportedError,FitsIoError.
Documentation
Full docs at prustic.github.io/fits-js.
