npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@cron-zen/core

v0.2.5

Published

Framework-agnostic Quartz/cron.ren Cron parser, generator, validator, describe, and next-run estimates

Downloads

2,083

Readme

@cron-zen/core

cron-zen 核心逻辑层:Cron 表达式解析、生成与校验。无框架依赖——原生 JS、Node、非 Vue 前端都应优先用本包。

需要可视化时另装 vanilla / react / vue2 / vue3(不能用 UI 包替代 core)。

完整函数说明(参数 / 返回 / 示例) → 文档 · API · core
在线引擎沙箱 → examples/core.html
选包:选哪个包

Install

npm install @cron-zen/core
# or
pnpm add @cron-zen/core

API (当前)

parseCron(expression: string): ParseResult

解析 5 / 6 / 7 段 Cron 表达式为可视化状态。

import { parseCron } from '@cron-zen/core';

const res = parseCron('0 0 2 * * ? *');
if (res.success) {
  console.log(res.state);
} else {
  console.error(res.error);
}

validateCronState(state): ValidateResult

校验范围、日周互斥、非法日期(如 2 月 31 日)。

import { validateCronState, createDefaultCronState } from '@cron-zen/core';

const res = validateCronState(createDefaultCronState());
console.log(res.valid, res.errors, res.warnings);

generateCron(state, options?): GenerateResult

由可视化状态生成 7 段表达式(默认自动日周互斥)。

import { generateCron, createDefaultCronState } from '@cron-zen/core';

const res = generateCron(createDefaultCronState());
// { success: true, expression: '* * * * * ? *' }

getNextRuns / getPrevRuns

估算最近 N 次触发(未来)与已触发(新→旧)。已覆盖日 L / LW / nW、周 nL / n#m / 裸 L,以及倒序区间回绕。

import { getNextRuns, getPrevRuns, parseCron, formatRunTime } from '@cron-zen/core';

const { state } = parseCron('0 0 9 ? * 6#3');
const from = new Date('2026-01-01');
console.log(getNextRuns(state!, 3, from).map(formatRunTime));
console.log(getPrevRuns(state!, 3, from).map(formatRunTime));

getCronPresets / listCronPresetDefs

常用模板(每分钟 / 工作日 9 点 / 月末…);getCronPresets(locale) 带中英标签。

其他导出

  • parseField / stringifyField — 单字段解析 / 序列化
  • escapeCronPercent / unescapeCronPercent — % 转义
  • enforceDayWeekMutex / assertDayWeekMutex — 日周互斥
  • describeCron / formatRunTime / getUiMessages — 自然语言与 UI 文案
  • lastDayOfMonth / lastWeekdayOfMonth / nearestWeekdayOfMonth — 日日历
  • lastQuartzWeekdayOfMonth / nthQuartzWeekdayOfMonth — 周日历(nL / #)
  • QUARTZ_MONTH_LABELS / quartzMonthLabel — 月标签
  • getCronTabs — UI Tab 元数据
  • createDefaultCronState — 默认 UI 状态
  • generateCronOrThrow — 生成失败时抛错

Build

pnpm --filter @cron-zen/core build

产物:dist/(ESM / CJS + .d.ts),仅 dist 会随 npm 包发布。

License

MIT