@flatfile/util-extractor

中文文档
2.8.0发布于 2025/10/18ISCTypeScriptESM + CJS近 30 天下载 7.2万

A library containing common utilities and helpers for extractors.

原始使用文档
文档目录6 节
  1. Code Breakdown
  2. Import Statements
  3. Extractor Function
  4. Extraction Process
  5. Helper Functions
  6. Type Definitions

The @flatfile/util-extractor utility is designed to handle various file formats and extract structured data efficiently. It leverages the power of the Flatfile API to facilitate smooth data extraction and processing.

When embedding Flatfile, this plugin should be deployed in a server-side listener. Learn more

Code Breakdown

This code defines a shared utility used in Flatfile Extractor plugins for data extraction. The purpose of this utility is to process files and extract structured data from them using the Flatfile API. It leverages various Flatfile SDK components and utilities (@flatfile/util-file-buffer to perform the data extraction process efficiently. Let's break down the main components of the code:

Import Statements

  • The code starts by importing various dependencies and modules required for data extraction. These include FlatfileListener from @flatfile/listener, fileBuffer from @flatfile/util-file-buffer, api and Flatfile from @flatfile/api, and mapValues from remeda.

Extractor Function

  • The Extractor function is the main entry point of the utility. It takes three parameters:
    • fileExt: A string or regular expression representing the file extension(s) to be processed.
    • parseBuffer: A callback function that processes the file buffer and returns a WorkbookCapture.
    • options: An optional object containing additional configuration options for data extraction.
      • options.chunkSize: Specifies the quantity of Records per chunk. Default value is 10_000.
      • options.parallel: Determines how many chunks are processed simultaneously. Default value is 1.
  • Inside the Extractor function, a FlatfileListener is used to intercept files with the specified extensions and perform the extraction process.

Extraction Process

  • When a file with the specified extension is received, the extraction process begins. The utility creates a job using the Flatfile API to track the extraction progress.
  • The parseBuffer function is then called to extract data from the file buffer using the provided options.
  • A workbook is created based on the extracted data using the createWorkbook function. The workbook is then updated with sheets containing the extracted data.

Helper Functions

  • The code includes several helper functions to assist in the extraction process:
    • createWorkbook: Creates a Flatfile workbook based on the extracted data.
    • getWorkbookConfig: Generates the configuration for the workbook, including sheet names, fields, and constraints.
    • getSheetConfig: Generates the configuration for each sheet, including field names, labels, and constraints.
    • asyncBatch: A utility function that processes data in chunks asynchronously to improve performance.

Type Definitions

  • The code defines two generic type structures: WorkbookCapture and SheetCapture. These types represent the structure of captured workbooks and sheets.

版本与发布记录

@flatfile/util-extractor 共发布 58 个版本,首次发布于 2023/08/02;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.8.0latest2025/10/181.1 年前
2.7.52025/09/201.2 年前
2.7.42025/08/281.2 年前
2.7.32025/08/271.2 年前
2.7.22025/08/151.3 年前
2.7.12025/07/131.3 年前

关于 @flatfile/util-extractor 的常见问题

@flatfile/util-extractor 是什么?

A library containing common utilities and helpers for extractors.

如何安装 @flatfile/util-extractor?

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

@flatfile/util-extractor 支持 TypeScript 吗?

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

@flatfile/util-extractor 支持 ESM 还是 CommonJS?

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

@flatfile/util-extractor 需要什么版本的 Node.js?

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

@flatfile/util-extractor 可以商用吗?

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

@flatfile/util-extractor 的下载量有多少?

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

@flatfile/util-extractor 还在维护吗?

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