@11ty/parse-date-strings

中文文档
2.0.6发布于 2025/12/03MITES Module零依赖构建来源已验证近 30 天下载 7598

Parsing content date strings in Eleventy core.

原始使用文档
文档目录3 节
  1. Usage
  2. Comparisons
  3. luxon

@11ty/parse-date-strings

Features:

  • Zero dependency super minimal RFC 9557-compatible date parsing library. Date strings are also parseable by Temporal.PlainDate.from, Temporal.Instant.from, or Temporal.PlainDateTime.from to prepare for wider Temporal API support.
  • Invalid strings throw errors.
  • Time zone notes:
    • Defaults to UTC when time zone is unknown (not local time). This matches previous behavior in Eleventy and this feature maintains consistency between build and deploy servers.
    • Supports +00, +00:00, -00, or -00:00 style time zone offsets (: delimiter is optional)
  • Delimiter notes:
    • Requires a T or t or (space) delimiter with DateTime strings
    • Delimiters in dates (-) and times (:) are optional

Not supported (for RFC 9557 compatibility):

  • Standalone time formats are not supported (must be Date or DateTime)
  • ISO week date syntax is not supported (e.g. YYYY-W01-1)
  • Day of year syntax is not supported (e.g. YYYY-001, YYYY-365)
  • Fractional hours or minutes (e.g. T14.6 or T10:30.6) are not supported. Fractional seconds (e.g. milliseconds) are supported (of course).

Usage

npm install @11ty/parse-date-strings
import { parse } from "@11ty/parse-date-strings

// `parse` returns JavaScript Date

parse("2000-01-01") instanceof Date
// true

parse("2000-01-01").toUTCString()
// "Mon, 01 Jan 2001 00:00:00 GMT"

Comparisons

luxon

More strict parsing compared with Luxon’s fromISO (used in Eleventy v0.x through v3):

2016-05-25
20160525
2016-05-25T09
2016-05-25T09:24
2016-05-25T09:24:15
2016-05-25T09:24:15.123
2016-05-25T0924
2016-05-25T092415
2016-05-25T092415.123
2016-05-25T09:24:15,123

# No YYYY or YYYYMM syntax
2016                      # Dropped
2016-05                   # Dropped
201605                    # Dropped

# No ISO week date syntax
2016-W21-3                # Dropped
2016W213                  # Dropped
2016-W21-3T09:24:15.123   # Dropped
2016W213T09:24:15.123     # Dropped

# No day of year syntax (e.g. 200th day of the year)
2016-200                  # Dropped
2016200                   # Dropped
2016-200T09:24:15.123     # Dropped

# No implied current day (time-only syntax)
09:24                     # Dropped
09:24:15                  # Dropped
09:24:15.123              # Dropped
09:24:15,123              # Dropped

版本与发布记录

@11ty/parse-date-strings 共发布 8 个版本,首次发布于 2025/07/22;过去 12 个月发布了 1 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.0.6latest2025/12/0311 个月前
2.0.52025/07/281.3 年前
2.0.42025/07/251.3 年前
2.0.32025/07/251.3 年前
2.0.22025/07/251.3 年前
2.0.12025/07/241.3 年前

关于 @11ty/parse-date-strings 的常见问题

@11ty/parse-date-strings 是什么?

Parsing content date strings in Eleventy core.

如何安装 @11ty/parse-date-strings?

在项目目录运行 npm install @11ty/parse-date-strings,或使用 pnpm add / yarn add / bun add。

@11ty/parse-date-strings 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/11ty__parse-date-strings 是否存在。

@11ty/parse-date-strings 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@11ty/parse-date-strings 需要什么版本的 Node.js?

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

@11ty/parse-date-strings 可以商用吗?

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

@11ty/parse-date-strings 的下载量有多少?

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

@11ty/parse-date-strings 还在维护吗?

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