@gabrielbryk/jq-ts

中文文档
1.7.0发布于 2026/07/02MITTypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 5.2万

Deterministic TypeScript implementation of a jq subset for workflow isolates

原始使用文档
文档目录8 节
  1. Features
  2. Install
  3. Usage
  4. Builtins
  5. Docs
  6. Development
  7. Contributing
  8. License

jq-ts

CI npm version license node engines

Pure TypeScript implementation of a deterministic, zero-dependency subset of the jq query language. Safe for V8 isolates (no Node.js built-ins, no filesystem/network), making it compatible with Temporal Workflows and other sandboxed runtimes.

Features

  • Parser → validator → interpreter pipeline with span-rich errors.
  • Deterministic evaluation: stable object key ordering; configurable limits for steps/depth/outputs; zero runtime dependencies.
  • Never touches the host clock, filesystem, network, or environment on its own. Time is available only when you inject it (options.now).
  • Broad jq builtin coverage — types/conversions, collections, strings, math, generators, path operations, and an injectable-clock date suite (see Builtins).
  • Advanced language features: reduce, foreach, try/catch, recursive descent (..), assignment/update operators (=, |=, +=, …), and destructuring as bindings.
  • Dual ESM/CJS builds via tsdown with .d.ts types.

Install

npm install @gabrielbryk/jq-ts
# or: pnpm add @gabrielbryk/jq-ts

Usage

import { run } from '@gabrielbryk/jq-ts'

const [result] = run('.foo // "fallback"', { foo: null })
// result === "fallback"

run(source, input, options?) returns an array of results (jq filters yield zero or more values). Options include limits, predefined vars, and now:

// Seed variables (without the `$` prefix):
run('.[] | . + $bump', [1, 2], { vars: { bump: 10 } }) // => [11, 12]

// `now` and date builtins require an injected instant (a Date or epoch seconds).
// Without it, `now` throws — jq-ts never reads the host clock itself.
run('now | todate', null, { now: 1_700_000_000 }) // => ["2023-11-14T22:13:20Z"]

Builtins

A representative (not exhaustive) view of what's implemented; see planning-docs/compatibility.md for the full jq 1.8 matrix.

  • Types & conversion: type, tostring, tonumber, toboolean, length, not, has, in, keys, keys_unsorted, and type filters (arrays, objects, booleans, numbers, strings, nulls, values, iterables, scalars, finites, normals).
  • Collections: map, map_values, select, sort, sort_by, group_by, unique, unique_by, reverse, flatten, add, min/max/min_by/max_by, to_entries, from_entries, with_entries, del, pick, transpose, bsearch, combinations, contains, inside.
  • Strings: split, join, startswith, endswith, ltrimstr/rtrimstr/trimstr, trim/ltrim/rtrim, ascii_downcase, ascii_upcase, explode, implode, index, rindex, indices, utf8bytelength, tojson, fromjson.
  • Math: floor, ceil, round, abs, sqrt, nan, infinite, isnan, isinfinite, isfinite, isnormal.
  • Generators & iteration: range, limit, skip, first, last, nth, while, until, repeat, recurse, isempty, all, any, empty.
  • Paths: path, paths, getpath, setpath, delpaths.
  • Dates (require an injected clock for now): now, gmtime, localtime, mktime, strftime, strflocaltime, strptime, todate/todateiso8601, fromdate/fromdateiso8601.
  • Errors & control flow: error, try/catch, if/then/elif/else/end, reduce, foreach, inline def, as destructuring, alternative //, and optional ?.

Docs

Development

git clone https://github.com/gabrielbryk/jq-ts.git
cd jq-ts
pnpm install
pnpm run build

Key commands:

  • pnpm run dev — Vitest watch
  • pnpm run test — full test suite (includes jq integration; auto-skips if jq missing)
  • pnpm run test:coverage — tests with coverage
  • pnpm run lint — ESLint
  • pnpm run format:write — Prettier formatting
  • pnpm run build — build CJS/ESM + types
  • pnpm run ci — build + format check + exports + lint + tests

Contributing

See CONTRIBUTING.md. We follow Conventional Commits and require pnpm run ci before PRs. Contributor guide: AGENTS.md.

License

MIT

版本与发布记录

@gabrielbryk/jq-ts 共发布 13 个版本,首次发布于 2025/12/13;过去 12 个月发布了 13 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.7.0latest2026/07/024 个月前
1.6.02026/06/304 个月前
1.5.02026/06/204 个月前
1.4.02026/05/026 个月前
1.3.62025/12/2510 个月前
1.3.52025/12/2510 个月前

关于 @gabrielbryk/jq-ts 的常见问题

@gabrielbryk/jq-ts 是什么?

Deterministic TypeScript implementation of a jq subset for workflow isolates

如何安装 @gabrielbryk/jq-ts?

在项目目录运行 npm install @gabrielbryk/jq-ts,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:typescript(^5.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@gabrielbryk/jq-ts 支持 TypeScript 吗?

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

@gabrielbryk/jq-ts 支持 ESM 还是 CommonJS?

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

@gabrielbryk/jq-ts 需要什么版本的 Node.js?

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

@gabrielbryk/jq-ts 可以商用吗?

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

@gabrielbryk/jq-ts 的下载量有多少?

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

@gabrielbryk/jq-ts 还在维护吗?

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