@flatfile/plugin-validate-date

中文文档
0.3.1发布于 2025/01/10ISCTypeScriptESM + CJS近 30 天下载 1.6万

A Flatfile plugin for normalizing date formats

原始使用文档
文档目录5 节
  1. Parameters
  2. Usage
  3. Import
  4. Example Usage
  5. Notes

The @flatfile/plugin-validate-date plugin provides date format normalization functionality for Flatfile. It detects various date formats and converts them to a specified output format, supporting multiple fields and locales.

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

Parameters

config.sheetSlug - string - default: ** - (optional)

The sheetSlug parameter is the slug of the sheet to apply the normalizer to. If not provided, it will apply to all sheets.

config.dateFields - string[]

The dateFields parameter is an array of field names that contain date values to be normalized.

config.outputFormat - string

The outputFormat parameter specifies the desired output format for the normalized dates.

config.includeTime - boolean

The includeTime parameter determines whether to include time in the normalized output.

config.locale - string - (optional)

The locale parameter specifies the locale to use for date parsing. Currently, only 'en-US' is supported.

Usage

npm install @flatfile/plugin-validate-date

Import

import { validateDate } from '@flatfile/plugin-validate-date'

Example Usage

This example sets up the date format normalizer for the "contacts" sheet, normalizing the "birthdate" and "registration_date" fields to the "MM/DD/YYYY" format.

import { FlatfileListener } from '@flatfile/listener'
import { validateDate } from '@flatfile/plugin-validate-date'

export default function (listener: FlatfileListener) {
  listener.use(
    validateDate({
      sheetSlug: 'contacts',
      dateFields: ['birth_date', 'registration_date'],
      outputFormat: 'MM/dd/yyyy',
      includeTime: false
    })
  )
}

Notes

  • The plugin uses the chrono-node library for parsing dates, which supports a wide range of date formats.
  • If a date cannot be parsed, the plugin will add an error message to the record for that field.
  • The locale parameter is included in the configuration interface but is not currently used in the implementation. The plugin defaults to using the 'en-US' locale.

版本与发布记录

@flatfile/plugin-validate-date 共发布 6 个版本,首次发布于 2024/10/10;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.3.1latest2025/01/101.8 年前
0.3.02024/11/082 年前
0.2.02024/10/302 年前
0.1.12024/10/292 年前
0.1.02024/10/112 年前
0.0.02024/10/102 年前

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

@flatfile/plugin-validate-date 是什么?

A Flatfile plugin for normalizing date formats

如何安装 @flatfile/plugin-validate-date?

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

@flatfile/plugin-validate-date 支持 TypeScript 吗?

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

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

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

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

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

@flatfile/plugin-validate-date 可以商用吗?

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

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

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

@flatfile/plugin-validate-date 还在维护吗?

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