@fideus-labs/ngff-zarr

中文文档
0.42.0发布于 2026/11/13MITTypeScriptES Module构建来源已验证近 30 天下载 8482

TypeScript implementation of ngff-zarr for reading and writing OME-Zarr files

原始使用文档
文档目录21 节
  1. Features
  2. Installation
  3. Node.js/npm
  4. Quick Start
  5. Reading OME-Zarr files
  6. Writing OME-Zarr files
  7. Schema Validation
  8. API Reference
  9. Core Types
  10. I/O Classes
  11. Validation
  12. Factory Functions
  13. Development
  14. Prerequisites
  15. Setup
  16. Commands
  17. Browser Testing
  18. Project Structure
  19. Relationship to Python Package
  20. Contributing
  21. License

ngff-zarr TypeScript

npm - Version

A TypeScript implementation of ngff-zarr for reading and writing OME-Zarr files, compatible with Node.js and the browser.

Features

  • 📘 TypeScript-first: Written in TypeScript, shipped with declarations
  • 📦 npm package: ESM build for Node.js, bundlers, and the browser
  • 🔍 Type-safe: Full TypeScript support with Zod schema validation
  • 🗂️ OME-Zarr support: Read OME-Zarr v0.4, v0.5, and v0.6, and write v0.5 and v0.6 (Zarr v3), using fizarrita
  • 🧪 Well-tested: Comprehensive test suite run with Vitest, Node, and Playwright
  • 🏗️ Mirrors Python API: TypeScript classes and types mirror the Python dataclasses

Installation

Node.js/npm

npm install @fideus-labs/ngff-zarr
import * as ngffZarr from "@fideus-labs/ngff-zarr";

The codec worker ships as a separate file in dist/workers/ and is spawned with new Worker(new URL("../workers/omero_codec_worker.js", import.meta.url), { type: "module" }), the form bundlers such as Vite and webpack 5 recognise as a worker entry point and emit alongside your bundle without configuration.

Quick Start

Reading OME-Zarr files

import { OMEZarrReader } from "@fideus-labs/ngff-zarr";

const reader = new OMEZarrReader({ validate: true });
const multiscales = await reader.fromNgffZarr("path/to/image.ome.zarr");

console.log(`Loaded ${multiscales.images.length} scale levels`);
console.log(`Image shape: ${multiscales.images[0].data.shape}`);

Writing OME-Zarr files

import {
  createMetadata,
  createMultiscales,
  createNgffImage,
  OMEZarrWriter,
} from "@fideus-labs/ngff-zarr";

// Create a simple 2D image
const image = createNgffImage(
  new ArrayBuffer(256 * 256),
  [256, 256],
  "uint8",
  ["y", "x"],
  { y: 1.0, x: 1.0 },
  { y: 0.0, x: 0.0 },
);

// Create metadata
const axes = [
  { name: "y", type: "space" },
  { name: "x", type: "space" },
];
const datasets = [
  {
    path: "0",
    coordinateTransformations: [
      { type: "scale", scale: [1.0, 1.0] },
      { type: "translation", translation: [0.0, 0.0] },
    ],
  },
];
const metadata = createMetadata(axes, datasets);

// Create multiscales
const multiscales = createMultiscales([image], metadata);

// Write to OME-Zarr
const writer = new OMEZarrWriter();
await writer.toOmeZarr("output.ome.zarr", multiscales);

Schema Validation

import { MetadataSchema, validateMetadata } from "@fideus-labs/ngff-zarr";

const metadata = {
  axes: [
    { name: "y", type: "space" },
    { name: "x", type: "space" },
  ],
  datasets: [
    {
      path: "0",
      coordinateTransformations: [
        { type: "scale", scale: [1.0, 1.0] },
        { type: "translation", translation: [0.0, 0.0] },
      ],
    },
  ],
  name: "test_image",
  version: "0.4",
};

// Validate using Zod schema
const validatedMetadata = MetadataSchema.parse(metadata);

// Or use utility function
const validatedMetadata2 = validateMetadata(metadata);

API Reference

Core Types

  • NgffImage: Represents an image with associated metadata
  • Multiscales: Container for multiple scale levels of an image
  • DaskArray: Metadata representation of dask arrays
  • Metadata: OME-Zarr metadata structure

I/O Classes

  • OMEZarrReader: Read OME-Zarr files using fizarrita
  • OMEZarrWriter: Write OME-Zarr files using fizarrita

Validation

  • Zod schemas for all data structures
  • Utility functions for validation
  • Type-safe parsing and validation

Factory Functions

  • createNgffImage(): Create NgffImage instances
  • createMetadata(): Create metadata structures
  • createMultiscales(): Create multiscale containers

Development

Prerequisites

  • Node.js 22.18, 24.11, or newer (npm included)
  • Pixi (optional; provides Node.js and the task aliases below)

The toolchain is Vite+ (vp), installed as a dev dependency: Vitest for tests, Oxlint and Oxfmt for linting and formatting, tsdown for the build.

Setup

cd ts/
npm ci          # or: pixi run install

Commands

# Run tests
npm test                 # or: pixi run test

# Format code
npm run fmt              # or: pixi run fmt

# Lint code
npm run lint             # or: pixi run lint

# Format + lint + type check in one pass
npm run check            # or: pixi run check

# Build the npm package into dist/
npm run build            # or: pixi run build

# Node tests against the built package
npm run test:node        # or: pixi run test-node

# Browser testing with Playwright
npm run test:browser     # or: pixi run test-browser

# Browser testing with UI
npm run test:browser:ui

# Run all tests (including browser tests)
npm run test:all         # or: pixi run test-all

Browser Testing

This project includes comprehensive browser testing using Playwright. The browser tests verify that the npm-transpiled package works correctly in real browser environments.

Features:

  • Multi-browser testing (Chrome, Firefox, Safari, Mobile)
  • NPM package validation in browser context
  • Import resolution testing for dependencies
  • Schema validation in browser environment

Quick Start:

# Build the package, inline the worker, bundle, and run the browser tests
npm run test:browser

# Run browser tests with interactive UI
npm run test:browser:ui

# Debug browser tests
npm run test:browser:debug

Test Files:

  • /test/browser-npm/ - Browser test files and configuration
  • /test/browser/server.ts - Test server for serving assets
  • /scripts/run_playwright.mjs - Node.js wrapper for Playwright execution

See test/browser/README.md for detailed browser testing documentation.

Project Structure

ts/
├── src/
│   ├── types/          # TypeScript type definitions
│   ├── schemas/        # Zod validation schemas
│   ├── io/            # Zarr I/O operations
│   ├── utils/         # Utility functions
│   └── mod.ts         # Main module exports
├── test/              # Test files
├── scripts/           # Build scripts
├── package.json       # npm package manifest and scripts
├── vite.config.ts     # Vite+ configuration (test, lint, fmt, pack)
├── tsconfig.json      # TypeScript configuration
├── pixi.toml          # Pixi environment
└── README.md

Relationship to Python Package

This TypeScript package mirrors the Python ngff-zarr package:

  • Types: TypeScript interfaces/classes correspond to Python dataclasses
  • API: Similar function names and patterns
  • Validation: Zod schemas provide runtime validation like Python
  • I/O: fizarrita provides Zarr operations like zarr-python

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Run the test suite: npm test
  6. Submit a pull request

License

MIT License - see LICENSE file for details.

版本与发布记录

@fideus-labs/ngff-zarr 共发布 59 个版本,首次发布于 2025/07/16;过去 12 个月发布了 57 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.42.0latest2026/11/131 天前
0.41.02026/11/059 天前
0.40.02026/10/3115 天前
0.39.02026/10/2421 天前
0.38.02026/10/081 个月前
0.36.02026/10/081 个月前

关于 @fideus-labs/ngff-zarr 的常见问题

@fideus-labs/ngff-zarr 是什么?

TypeScript implementation of ngff-zarr for reading and writing OME-Zarr files

如何安装 @fideus-labs/ngff-zarr?

在项目目录运行 npm install @fideus-labs/ngff-zarr,或使用 pnpm add / yarn add / bun add。

@fideus-labs/ngff-zarr 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@fideus-labs/ngff-zarr 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@fideus-labs/ngff-zarr 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js ^22.18.0 || ^24.11.0 || >=26.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@fideus-labs/ngff-zarr 可以商用吗?

@fideus-labs/ngff-zarr 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@fideus-labs/ngff-zarr 的下载量有多少?

根据 npm 官方下载统计,@fideus-labs/ngff-zarr 在 2026/10/15 – 2026/11/13 这 30 天内被下载 8,482 次,日均约 283 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@fideus-labs/ngff-zarr 还在维护吗?

最新版本 0.42.0 发布于 2026/11/13(1 天前);至今共发布 59 个版本,其中过去 12 个月发布了 57 个;首次发布于 2025/07/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。