@gmod/trix

中文文档
3.2.3发布于 2026/11/16Apache-2.0TypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 3.1万

Read UCSC Trix indexes in pure JavaScript

原始使用文档
文档目录7 节
  1. Install
  2. Usage
  3. API
  4. new Trix(ixxFile, ixFile, maxResults?)
  5. trix.search(searchString, opts?)
  6. Reading over HTTP
  7. Reference

Build Status

trix-js

Read UCSC Trix indexes in pure JavaScript

Install

npm install @gmod/trix

Usage

import Trix from '@gmod/trix'
import { RemoteFile } from 'generic-filehandle2'

// generic-filehandle2 also has LocalFile for files on disk
const trix = new Trix(
  new RemoteFile('https://jbrowse.org/genomes/GRCh38/trix/hg38.ixx'),
  new RemoteFile('https://jbrowse.org/genomes/GRCh38/trix/hg38.ix'),
)

const results = await trix.search('oca')
// => [[term, record], ...]

API

new Trix(ixxFile, ixFile, maxResults?)

  • ixxFile - filehandle for the .ixx file
  • ixFile - filehandle for the .ix file
  • maxResults - most results a search returns, default 20. Also settable afterwards as trix.maxResults

Any object with read(length, position, opts?) resolving to a Uint8Array and readFile({ encoding: 'utf8' }) resolving to a string works, which includes every generic-filehandle2 handle. The exported Filehandle type describes it.

trix.search(searchString, opts?)

Prefix-searches the index and resolves to [term, record][], where term is the indexed word that matched and record is the key it points to. Records are deduplicated, so two terms hitting the same record yield one result.

  • searchString - the query. Each whitespace-separated word is prefix-searched and a record is returned when every word finds it, in any order. A word of a multi-word query is read for at most 200 records (or maxResults, if larger), and one with more cannot rule a record out: b brca2 answers with the brca2 records
  • opts.signal - an AbortSignal to cancel the underlying reads

Reading over HTTP

A search fetches the .ixx once, then reads the .ix from the matching checkpoint, 256 KiB first and doubling after that. A typeahead's consecutive keystrokes read nearby offsets, so typing spd_00 into the 1.7 MB test index makes six reads at three distinct offsets. With @gmod/range-cache-filehandle under both filehandles, four 256 KiB chunks serve all six, and backspacing needs no new fetch:

import { RemoteFileWithRangeCache } from '@gmod/range-cache-filehandle'

const trix = new Trix(
  new RemoteFileWithRangeCache(`${url}.ixx`),
  new RemoteFileWithRangeCache(`${url}.ix`),
)

Reference

See the UCSC trix documentation for the concepts, and ixixx-js for a JavaScript implementation of the ixIxx command that builds these indexes.

See CONTRIBUTING.md for development and release steps.

版本与发布记录

@gmod/trix 共发布 43 个版本,首次发布于 2021/04/13;过去 12 个月发布了 22 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
3.2.3latest2026/11/16今天
3.2.22026/11/106 天前
3.2.12026/11/106 天前
3.2.02026/11/106 天前
3.1.02026/10/151 个月前
3.0.222026/08/153 个月前

关于 @gmod/trix 的常见问题

@gmod/trix 是什么?

Read UCSC Trix indexes in pure JavaScript

如何安装 @gmod/trix?

在项目目录运行 npm install @gmod/trix,或使用 pnpm add / yarn add / bun add。

@gmod/trix 支持 TypeScript 吗?

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

@gmod/trix 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@gmod/trix 可以商用吗?

@gmod/trix 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@gmod/trix 的下载量有多少?

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

@gmod/trix 还在维护吗?

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