@flatfile/plugin-autocast

中文文档
7.0.0发布于 2025/01/10ISCTypeScriptESM + CJS近 30 天下载 2890

A plugin for automatically casting values in Flatfile.

原始使用文档
文档目录7 节
  1. Parameters
  2. API Calls
  3. Usage
  4. Strings
  5. Numbers
  6. Booleans
  7. Dates

@flatfile/plugin-autocast

Automatically cast values in Flatfile to their appropriate types with this plugin.

The @flatfile/plugin-autocast plugin is an opinionated transformer that will automatically convert the data in the Sheet to match the type defined by the Blueprint.

Event Type: listener.on('commit:created')

Supported field types: number, boolean, date

Parameters

sheetSlug - string - (required)

The sheetSlug indicates the slug name of the sheet you want to monitor.

fieldFilters - string[]

Use the fieldFilters parameter to select specific fields to monitor. Without any specified fieldFilters, the plugin will automatically monitor all castable fields, including strings, numbers, booleans, and dates.

options.chunkSize - default: "10_000" - number

The chunkSize parameter allows you to specify the quantity of records to in each chunk.

options.parallel - default: "1" - number

The parallel parameter allows you to specify the number of chunks to process in parallel.

API Calls

  • api.sheets.get

Usage

The autocast plugin will listen for the commit:created event and cast strings, numbers, booleans, and dates to the appropriate Blueprint type. Note that the recordHook and bulkRecordHook plugins listen for the same event type. Plugins will fire in the order they are placed in the listener.

Strings

Numbers and booleans are transformed from strings to their respective types (i.e., '1' to 1, "true" to true).

Numbers

String numbers (i.e '1'), string decimals (i.e '1.1'), and string numbers with commas (i.e '1,000') are interpreted as numbers.

Booleans

'1', 'yes', 'true', 'on', 't', 'y', and 1 are interpreted as truthy values.

'-1', '0', 'no', 'false', 'off', 'f', 'n', 0, -1 are interpreted as falsy values.

Dates

Date strings and numbers are cast to UTC strings. For example, YYYY-MM-DD... formats are treated as ISO 8601 dates (UTC), whereas other formats are considered local time and converted to UTC:

  • '2023-08-16' => 'Wed, 16 Aug 2023 00:00:00 GMT'
  • '08-16-2023' => 'Wed, 16 Aug 2023 00:00:00 GMT'
  • '08/16/2023' => 'Wed, 16 Aug 2023 00:00:00 GMT'
  • 'Aug 16, 2023' => 'Wed, 16 Aug 2023 00:00:00 GMT'
  • 'August 16, 2023' => 'Wed, 16 Aug 2023 00:00:00 GMT'
  • '2023-08-16T00:00:00.000Z' => 'Wed, 16 Aug 2023 00:00:00 GMT'
  • 1692144000000 => 'Wed, 16 Aug 2023 00:00:00 GMT'

install

npm i @flatfile/plugin-autocast

import

import { autocast } from "@flatfile/plugin-autocast";

listener.js

listener.use(autocast("sheetSlug"));

listener.js w/ fieldFilters

listener.use(autocast("sheetSlug", ["numberField", "dateField"]));

listener.js w/ fieldFilters & options

listener.use(
  autocast("sheetSlug", ["numberField", "dateField"], {
    chunkSize: 10_000,
    parallel: 2,
  })
);

版本与发布记录

@flatfile/plugin-autocast 共发布 42 个版本,首次发布于 2023/04/27;过去 12 个月发布了 0 个版本。

版本发布日期距今
7.0.0latest2025/01/101.8 年前
6.0.12024/12/111.9 年前
6.0.02024/11/192 年前
5.0.02024/11/082 年前
4.0.02024/11/012 年前
3.0.02024/10/302 年前

关于 @flatfile/plugin-autocast 的常见问题

@flatfile/plugin-autocast 是什么?

A plugin for automatically casting values in Flatfile.

如何安装 @flatfile/plugin-autocast?

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

@flatfile/plugin-autocast 支持 TypeScript 吗?

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

@flatfile/plugin-autocast 支持 ESM 还是 CommonJS?

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

@flatfile/plugin-autocast 需要什么版本的 Node.js?

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

@flatfile/plugin-autocast 可以商用吗?

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

@flatfile/plugin-autocast 的下载量有多少?

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

@flatfile/plugin-autocast 还在维护吗?

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