@date/generator

中文文档
0.2.0发布于 2018/07/20MITCommonJS零依赖近 30 天下载 1.2万

Calculate dates with easy to read helper functions

原始使用文档
文档目录7 节
  1. Install
  2. Usage
  3. Order
  4. Days
  5. Months
  6. Years
  7. MIT License

@date/generator

Build Status npm version Coverage Status

Generate dates with readable function chaining.

Also has functions accepting numbers to help with using values provided from elsewhere.

Install

npm install @date/generator --save

Usage

var gen = require('@date/generator')

// these are equivalent:
//   specify each thing individually
var washingtonDay = gen.third().monday().in().february().of(2016)
//   skip the in() and of() and specify the year in the february() call
var washingtonDay = gen.third().monday().february(2016)
//   specify 'third' with a '3' to monday(),
//           'february' with '1' to month()
var washingtonDay = gen.monday(3).month(1).of(2016)

var thanksgiving  = gen.fourth().thursday().in().november().of(2016)

Order

Start with the order functions:

  1. first() - 1
  2. second() - 2
  3. third() - 3
  4. fourth() - 4
  5. last() - 5 (will be last, even when last is the fourth)

Days

Day functions are available after calling an order function, or, start with them and specify the order value as 1-5:

  1. sunday()
  2. monday()
  3. tuesday()
  4. wednesday()
  5. thursday()
  6. friday()
  7. saturday()

Months

Month functions are available after calling a day function:

  1. january()
  2. february()
  3. march()
  4. april()
  5. may()
  6. june()
  7. july()
  8. august()
  9. september()
  10. october()
  11. november()
  12. december()

Also, shortcut making a call to of(year) after it and specify the year in the month call, like august(2016).

Years

Last call specifies the year to function of(year) and returns a Date instance.

MIT License

版本与发布记录

@date/generator 共发布 3 个版本,首次发布于 2016/07/01;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.2.0latest2018/07/208 年前
0.1.12016/07/2310 年前
0.1.02016/07/0110 年前

关于 @date/generator 的常见问题

@date/generator 是什么?

Calculate dates with easy to read helper functions

如何安装 @date/generator?

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

@date/generator 支持 TypeScript 吗?

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

@date/generator 支持 ESM 还是 CommonJS?

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

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

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

@date/generator 可以商用吗?

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

@date/generator 的下载量有多少?

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

@date/generator 还在维护吗?

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