@dittowords/text-extract

中文文档
0.5.0发布于 2026/10/22MITTypeScriptCommonJS近 30 天下载 8323

Deterministic extraction of candidate user-facing strings from a codebase.

原始使用文档
文档目录3 节
  1. Usage
  2. Notes
  3. Development

@dittowords/text-extract

Finds strings in a codebase that are potentially user-facing.

Usage

A whole directory:

import { runExtract } from "@dittowords/text-extract";

const { candidates, summary } = await runExtract({ inputPath: "/path/to/repo" });

Skips vendored, build and test trees, and honors .gitignore.

One file:

import { extractFile } from "@dittowords/text-extract";

const { candidates, skipped } = await extractFile({
  relPath: "src/Button.tsx", // used verbatim as `location.file`
  source: fileContents,
  framework: ["react", "next"], // optional
});

Scans whatever path it's given — no exclusions are applied. framework is the same token list runExtract derives from package.json files and native project markers; omitting it only costs a classification hint.

skipped is set when the file wasn't scanned at all (unsupported_language, unconfirmed_i18n_file, minified) — not the same as scanning it and finding nothing.

Both entry points reach the same verdict on the same file.

Notes

  • Candidate order may not be stable between runs, because globby's file iteration order varies. The set is stable; compare accordingly.
  • summary.filesFailed counts files an extractor threw on. They're dropped from the results, so a non-zero count means strings are missing.
  • summary.linesStoppedEarly counts lines that were skipped because they are longer than MAX_LINE_LENGTH or slower than LINE_TIME_LIMIT_MS to tokenize. A skipped line has no candidates. summary.stoppedEarlyLines lists up to 20 skipped lines with their files. extractFile returns all skipped lines of its file in stoppedEarlyLines.

Development

yarn test
yarn typecheck
yarn build
Tests
lang/extractors/*.test.tsPer-construct classification. Exact line and column.
golden.test.tsRealistic fixtures from testing/golden/, with hand-written expectations. Fixtures are tested under a relPath that need not match their location on disk, since path shape drives i18n admission and locale detection.
extract-file.test.tsThat the two entry points agree per file.
extract-failures.test.tsThat a throwing extractor is counted, not swallowed.
extract-performance.test.tsThat the grammar extractor doesn't backtrack catastrophically on dense input.
line-time-limit.test.tsThat long or slow lines are skipped and reported per file, and that the state after a skipped line is correct.

版本与发布记录

@dittowords/text-extract 共发布 7 个版本,首次发布于 2026/08/11;过去 12 个月发布了 7 个版本。

版本发布日期距今
0.5.0latest2026/10/2221 天前
0.4.12026/10/1528 天前
0.4.02026/10/091 个月前
0.3.02026/08/202 个月前
0.2.12026/08/182 个月前
0.2.02026/08/142 个月前

关于 @dittowords/text-extract 的常见问题

@dittowords/text-extract 是什么?

Deterministic extraction of candidate user-facing strings from a codebase.

如何安装 @dittowords/text-extract?

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

@dittowords/text-extract 支持 TypeScript 吗?

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

@dittowords/text-extract 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@dittowords/text-extract 需要什么版本的 Node.js?

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

@dittowords/text-extract 可以商用吗?

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

@dittowords/text-extract 的下载量有多少?

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

@dittowords/text-extract 还在维护吗?

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