@citation-js/date

中文文档
0.5.1发布于 2021/12/02MITCommonJS零依赖近 30 天下载 35.2万

Date parser and formatter

原始使用文档
文档目录4 节
  1. Install
  2. Use
  3. Input
  4. API

Install

npm install @citation-js/date

Use

let { parse, format } = require('@citation-js/date')

parse('2000-12-31')
// { 'date-parts': [[2000, 12, 31]] }

format({ 'date-parts': [[2000, 12, 31]] }, '/')
// '2000/12/31'

Input

Supported formats:

  • Epoch time (in number form)
  • YYYY-MM-DD
  • [+-]YYYYYY[Y...]-MM-DD
  • [DDD, ]DD MMM YYYY
  • M[M]/D[D]/YY[YY] (1)
  • D[D] M[M] Y[Y...] (2, 1)
  • [-]Y[Y...] M[M] D[D] (2)
  • D[D] MMM Y[Y...] (2)
  • [-]Y[Y...] MMM D[D] (2)
  • M[M] [-]Y[Y...] (3, 5)
  • [-]Y[Y...] M[M] (3, 4, 5)
  • MMM [-]Y[Y...] (3, 5)
  • [-]Y[Y...] MMM (3, 5)
  • [-]Y[Y...] (5)

Generally, formats support trailing parts, which are disregarded.

  1. When the former of these formats overlaps with the latter, the former is preferred
  2. " ", ".", "-" and "/" are all supported as separator
  3. Any sequence of non-alphanumerical characters are supported as separator
  4. This format is only assumed if the year is bigger than the month
  5. This format doesn't support trailing parts

API

parse(String date[, String endDate]) -> Object

  • String date: Any date
  • String endDate optional: Any date; when added, the first parameter is treated as the start date of the range.

format(Object date[, String delimiter = '-']) -> String

  • Object date: Any date
  • String delimiter optional: Separate parts by delimiter

Here, Object date (CSL-JSON date format) can have the following properties:

  • date-parts: array with one or two dates, each date being an array of [year, month, day], the last two parts being optional
  • raw: raw date

版本与发布记录

@citation-js/date 共发布 7 个版本,首次发布于 2018/07/24;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.5.1latest2021/12/024 年前
0.5.02021/05/205 年前
0.4.42019/04/277 年前
0.4.32019/01/057 年前
0.4.22018/12/257 年前
0.4.12018/08/278 年前

关于 @citation-js/date 的常见问题

@citation-js/date 是什么?

Date parser and formatter

如何安装 @citation-js/date?

在项目目录运行 npm install @citation-js/date,或使用 pnpm add / yarn add / bun add。

@citation-js/date 支持 TypeScript 吗?

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

@citation-js/date 支持 ESM 还是 CommonJS?

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

@citation-js/date 需要什么版本的 Node.js?

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

@citation-js/date 可以商用吗?

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

@citation-js/date 的下载量有多少?

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

@citation-js/date 还在维护吗?

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