va-claw 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (316) hide show
  1. package/CONTRIBUTING.md +36 -0
  2. package/LICENSE +21 -0
  3. package/README.md +337 -0
  4. package/bin/va-claw +3 -0
  5. package/bin/va-claw.mjs +3 -0
  6. package/docs/README.md +6 -0
  7. package/index.html +728 -0
  8. package/package.json +43 -0
  9. package/packages/channels/discord/dist/.tsbuildinfo +1 -0
  10. package/packages/channels/discord/dist/cli-runner.d.ts +18 -0
  11. package/packages/channels/discord/dist/cli-runner.d.ts.map +1 -0
  12. package/packages/channels/discord/dist/cli-runner.js +58 -0
  13. package/packages/channels/discord/dist/cli-runner.js.map +1 -0
  14. package/packages/channels/discord/dist/cli-runner.test.d.ts +2 -0
  15. package/packages/channels/discord/dist/cli-runner.test.d.ts.map +1 -0
  16. package/packages/channels/discord/dist/cli-runner.test.js +173 -0
  17. package/packages/channels/discord/dist/cli-runner.test.js.map +1 -0
  18. package/packages/channels/discord/dist/discord-client.d.ts +3 -0
  19. package/packages/channels/discord/dist/discord-client.d.ts.map +1 -0
  20. package/packages/channels/discord/dist/discord-client.js +49 -0
  21. package/packages/channels/discord/dist/discord-client.js.map +1 -0
  22. package/packages/channels/discord/dist/format.d.ts +6 -0
  23. package/packages/channels/discord/dist/format.d.ts.map +1 -0
  24. package/packages/channels/discord/dist/format.js +19 -0
  25. package/packages/channels/discord/dist/format.js.map +1 -0
  26. package/packages/channels/discord/dist/format.test.d.ts +2 -0
  27. package/packages/channels/discord/dist/format.test.d.ts.map +1 -0
  28. package/packages/channels/discord/dist/format.test.js +63 -0
  29. package/packages/channels/discord/dist/format.test.js.map +1 -0
  30. package/packages/channels/discord/dist/index.d.ts +3 -0
  31. package/packages/channels/discord/dist/index.d.ts.map +1 -0
  32. package/packages/channels/discord/dist/index.js +2 -0
  33. package/packages/channels/discord/dist/index.js.map +1 -0
  34. package/packages/channels/discord/dist/prompt.d.ts +4 -0
  35. package/packages/channels/discord/dist/prompt.d.ts.map +1 -0
  36. package/packages/channels/discord/dist/prompt.js +28 -0
  37. package/packages/channels/discord/dist/prompt.js.map +1 -0
  38. package/packages/channels/discord/dist/prompt.test.d.ts +2 -0
  39. package/packages/channels/discord/dist/prompt.test.d.ts.map +1 -0
  40. package/packages/channels/discord/dist/prompt.test.js +130 -0
  41. package/packages/channels/discord/dist/prompt.test.js.map +1 -0
  42. package/packages/channels/discord/dist/runtime.d.ts +11 -0
  43. package/packages/channels/discord/dist/runtime.d.ts.map +1 -0
  44. package/packages/channels/discord/dist/runtime.js +66 -0
  45. package/packages/channels/discord/dist/runtime.js.map +1 -0
  46. package/packages/channels/discord/dist/runtime.test.d.ts +2 -0
  47. package/packages/channels/discord/dist/runtime.test.d.ts.map +1 -0
  48. package/packages/channels/discord/dist/runtime.test.js +107 -0
  49. package/packages/channels/discord/dist/runtime.test.js.map +1 -0
  50. package/packages/channels/discord/dist/types.d.ts +30 -0
  51. package/packages/channels/discord/dist/types.d.ts.map +1 -0
  52. package/packages/channels/discord/dist/types.js +2 -0
  53. package/packages/channels/discord/dist/types.js.map +1 -0
  54. package/packages/channels/discord/package.json +21 -0
  55. package/packages/channels/dist/.tsbuildinfo +1 -0
  56. package/packages/channels/dist/index.d.ts +14 -0
  57. package/packages/channels/dist/index.d.ts.map +1 -0
  58. package/packages/channels/dist/index.js +25 -0
  59. package/packages/channels/dist/index.js.map +1 -0
  60. package/packages/channels/package.json +23 -0
  61. package/packages/channels/slack/dist/.tsbuildinfo +1 -0
  62. package/packages/channels/slack/dist/cli.d.ts +7 -0
  63. package/packages/channels/slack/dist/cli.d.ts.map +1 -0
  64. package/packages/channels/slack/dist/cli.js +53 -0
  65. package/packages/channels/slack/dist/cli.js.map +1 -0
  66. package/packages/channels/slack/dist/cli.test.d.ts +2 -0
  67. package/packages/channels/slack/dist/cli.test.d.ts.map +1 -0
  68. package/packages/channels/slack/dist/cli.test.js +43 -0
  69. package/packages/channels/slack/dist/cli.test.js.map +1 -0
  70. package/packages/channels/slack/dist/index.d.ts +7 -0
  71. package/packages/channels/slack/dist/index.d.ts.map +1 -0
  72. package/packages/channels/slack/dist/index.js +28 -0
  73. package/packages/channels/slack/dist/index.js.map +1 -0
  74. package/packages/channels/slack/dist/message.d.ts +15 -0
  75. package/packages/channels/slack/dist/message.d.ts.map +1 -0
  76. package/packages/channels/slack/dist/message.js +38 -0
  77. package/packages/channels/slack/dist/message.js.map +1 -0
  78. package/packages/channels/slack/dist/slack.test.d.ts +2 -0
  79. package/packages/channels/slack/dist/slack.test.d.ts.map +1 -0
  80. package/packages/channels/slack/dist/slack.test.js +23 -0
  81. package/packages/channels/slack/dist/slack.test.js.map +1 -0
  82. package/packages/channels/slack/dist/types.d.ts +22 -0
  83. package/packages/channels/slack/dist/types.d.ts.map +1 -0
  84. package/packages/channels/slack/dist/types.js +2 -0
  85. package/packages/channels/slack/dist/types.js.map +1 -0
  86. package/packages/channels/slack/package.json +21 -0
  87. package/packages/channels/telegram/dist/.tsbuildinfo +1 -0
  88. package/packages/channels/telegram/dist/cli.d.ts +13 -0
  89. package/packages/channels/telegram/dist/cli.d.ts.map +1 -0
  90. package/packages/channels/telegram/dist/cli.js +53 -0
  91. package/packages/channels/telegram/dist/cli.js.map +1 -0
  92. package/packages/channels/telegram/dist/cli.test.d.ts +2 -0
  93. package/packages/channels/telegram/dist/cli.test.d.ts.map +1 -0
  94. package/packages/channels/telegram/dist/cli.test.js +167 -0
  95. package/packages/channels/telegram/dist/cli.test.js.map +1 -0
  96. package/packages/channels/telegram/dist/index.d.ts +7 -0
  97. package/packages/channels/telegram/dist/index.d.ts.map +1 -0
  98. package/packages/channels/telegram/dist/index.js +21 -0
  99. package/packages/channels/telegram/dist/index.js.map +1 -0
  100. package/packages/channels/telegram/dist/message.d.ts +6 -0
  101. package/packages/channels/telegram/dist/message.d.ts.map +1 -0
  102. package/packages/channels/telegram/dist/message.js +33 -0
  103. package/packages/channels/telegram/dist/message.js.map +1 -0
  104. package/packages/channels/telegram/dist/telegram.test.d.ts +2 -0
  105. package/packages/channels/telegram/dist/telegram.test.d.ts.map +1 -0
  106. package/packages/channels/telegram/dist/telegram.test.js +25 -0
  107. package/packages/channels/telegram/dist/telegram.test.js.map +1 -0
  108. package/packages/channels/telegram/dist/types.d.ts +20 -0
  109. package/packages/channels/telegram/dist/types.d.ts.map +1 -0
  110. package/packages/channels/telegram/dist/types.js +2 -0
  111. package/packages/channels/telegram/dist/types.js.map +1 -0
  112. package/packages/channels/telegram/package.json +21 -0
  113. package/packages/cli/dist/.tsbuildinfo +1 -0
  114. package/packages/cli/dist/bin/va-claw.d.mts +3 -0
  115. package/packages/cli/dist/bin/va-claw.d.mts.map +1 -0
  116. package/packages/cli/dist/bin/va-claw.mjs +4 -0
  117. package/packages/cli/dist/bin/va-claw.mjs.map +1 -0
  118. package/packages/cli/dist/channel-handlers.d.ts +8 -0
  119. package/packages/cli/dist/channel-handlers.d.ts.map +1 -0
  120. package/packages/cli/dist/channel-handlers.js +80 -0
  121. package/packages/cli/dist/channel-handlers.js.map +1 -0
  122. package/packages/cli/dist/deps-exports.d.ts +3 -0
  123. package/packages/cli/dist/deps-exports.d.ts.map +1 -0
  124. package/packages/cli/dist/deps-exports.js +3 -0
  125. package/packages/cli/dist/deps-exports.js.map +1 -0
  126. package/packages/cli/dist/deps.d.ts +3 -0
  127. package/packages/cli/dist/deps.d.ts.map +1 -0
  128. package/packages/cli/dist/deps.js +81 -0
  129. package/packages/cli/dist/deps.js.map +1 -0
  130. package/packages/cli/dist/handlers.d.ts +33 -0
  131. package/packages/cli/dist/handlers.d.ts.map +1 -0
  132. package/packages/cli/dist/handlers.js +207 -0
  133. package/packages/cli/dist/handlers.js.map +1 -0
  134. package/packages/cli/dist/index.d.ts +10 -0
  135. package/packages/cli/dist/index.d.ts.map +1 -0
  136. package/packages/cli/dist/index.js +9 -0
  137. package/packages/cli/dist/index.js.map +1 -0
  138. package/packages/cli/dist/install-files.d.ts +11 -0
  139. package/packages/cli/dist/install-files.d.ts.map +1 -0
  140. package/packages/cli/dist/install-files.js +72 -0
  141. package/packages/cli/dist/install-files.js.map +1 -0
  142. package/packages/cli/dist/memory-status.d.ts +3 -0
  143. package/packages/cli/dist/memory-status.d.ts.map +1 -0
  144. package/packages/cli/dist/memory-status.js +45 -0
  145. package/packages/cli/dist/memory-status.js.map +1 -0
  146. package/packages/cli/dist/output.d.ts +8 -0
  147. package/packages/cli/dist/output.d.ts.map +1 -0
  148. package/packages/cli/dist/output.js +45 -0
  149. package/packages/cli/dist/output.js.map +1 -0
  150. package/packages/cli/dist/platform.d.ts +6 -0
  151. package/packages/cli/dist/platform.d.ts.map +1 -0
  152. package/packages/cli/dist/platform.js +31 -0
  153. package/packages/cli/dist/platform.js.map +1 -0
  154. package/packages/cli/dist/program.d.ts +5 -0
  155. package/packages/cli/dist/program.d.ts.map +1 -0
  156. package/packages/cli/dist/program.js +116 -0
  157. package/packages/cli/dist/program.js.map +1 -0
  158. package/packages/cli/dist/test-helpers.d.ts +7 -0
  159. package/packages/cli/dist/test-helpers.d.ts.map +1 -0
  160. package/packages/cli/dist/test-helpers.js +91 -0
  161. package/packages/cli/dist/test-helpers.js.map +1 -0
  162. package/packages/cli/dist/types.d.ts +82 -0
  163. package/packages/cli/dist/types.d.ts.map +1 -0
  164. package/packages/cli/dist/types.js +2 -0
  165. package/packages/cli/dist/types.js.map +1 -0
  166. package/packages/cli/dist/wait.d.ts +2 -0
  167. package/packages/cli/dist/wait.d.ts.map +1 -0
  168. package/packages/cli/dist/wait.js +25 -0
  169. package/packages/cli/dist/wait.js.map +1 -0
  170. package/packages/cli/package.json +29 -0
  171. package/packages/daemon/dist/.tsbuildinfo +1 -0
  172. package/packages/daemon/dist/cli-adapter.d.ts +14 -0
  173. package/packages/daemon/dist/cli-adapter.d.ts.map +1 -0
  174. package/packages/daemon/dist/cli-adapter.js +30 -0
  175. package/packages/daemon/dist/cli-adapter.js.map +1 -0
  176. package/packages/daemon/dist/index.d.ts +5 -0
  177. package/packages/daemon/dist/index.d.ts.map +1 -0
  178. package/packages/daemon/dist/index.js +4 -0
  179. package/packages/daemon/dist/index.js.map +1 -0
  180. package/packages/daemon/dist/runner.d.ts +2 -0
  181. package/packages/daemon/dist/runner.d.ts.map +1 -0
  182. package/packages/daemon/dist/runner.js +18 -0
  183. package/packages/daemon/dist/runner.js.map +1 -0
  184. package/packages/daemon/dist/runtime.d.ts +24 -0
  185. package/packages/daemon/dist/runtime.d.ts.map +1 -0
  186. package/packages/daemon/dist/runtime.js +83 -0
  187. package/packages/daemon/dist/runtime.js.map +1 -0
  188. package/packages/daemon/dist/service-files.d.ts +13 -0
  189. package/packages/daemon/dist/service-files.d.ts.map +1 -0
  190. package/packages/daemon/dist/service-files.js +84 -0
  191. package/packages/daemon/dist/service-files.js.map +1 -0
  192. package/packages/daemon/dist/service.d.ts +4 -0
  193. package/packages/daemon/dist/service.d.ts.map +1 -0
  194. package/packages/daemon/dist/service.js +31 -0
  195. package/packages/daemon/dist/service.js.map +1 -0
  196. package/packages/daemon/dist/types.d.ts +11 -0
  197. package/packages/daemon/dist/types.d.ts.map +1 -0
  198. package/packages/daemon/dist/types.js +2 -0
  199. package/packages/daemon/dist/types.js.map +1 -0
  200. package/packages/daemon/dist/wake-cycle.d.ts +17 -0
  201. package/packages/daemon/dist/wake-cycle.d.ts.map +1 -0
  202. package/packages/daemon/dist/wake-cycle.js +58 -0
  203. package/packages/daemon/dist/wake-cycle.js.map +1 -0
  204. package/packages/daemon/package.json +22 -0
  205. package/packages/identity/dist/.tsbuildinfo +1 -0
  206. package/packages/identity/dist/defaults.d.ts +5 -0
  207. package/packages/identity/dist/defaults.d.ts.map +1 -0
  208. package/packages/identity/dist/defaults.js +70 -0
  209. package/packages/identity/dist/defaults.js.map +1 -0
  210. package/packages/identity/dist/index.d.ts +6 -0
  211. package/packages/identity/dist/index.d.ts.map +1 -0
  212. package/packages/identity/dist/index.js +5 -0
  213. package/packages/identity/dist/index.js.map +1 -0
  214. package/packages/identity/dist/path.d.ts +3 -0
  215. package/packages/identity/dist/path.d.ts.map +1 -0
  216. package/packages/identity/dist/path.js +16 -0
  217. package/packages/identity/dist/path.js.map +1 -0
  218. package/packages/identity/dist/render.d.ts +4 -0
  219. package/packages/identity/dist/render.d.ts.map +1 -0
  220. package/packages/identity/dist/render.js +34 -0
  221. package/packages/identity/dist/render.js.map +1 -0
  222. package/packages/identity/dist/storage.d.ts +4 -0
  223. package/packages/identity/dist/storage.d.ts.map +1 -0
  224. package/packages/identity/dist/storage.js +27 -0
  225. package/packages/identity/dist/storage.js.map +1 -0
  226. package/packages/identity/dist/types.d.ts +29 -0
  227. package/packages/identity/dist/types.d.ts.map +1 -0
  228. package/packages/identity/dist/types.js +2 -0
  229. package/packages/identity/dist/types.js.map +1 -0
  230. package/packages/identity/dist/wizard.d.ts +3 -0
  231. package/packages/identity/dist/wizard.d.ts.map +1 -0
  232. package/packages/identity/dist/wizard.js +37 -0
  233. package/packages/identity/dist/wizard.js.map +1 -0
  234. package/packages/identity/package.json +21 -0
  235. package/packages/identity/test/identity.test.mjs +71 -0
  236. package/packages/identity/test/storage.test.mjs +91 -0
  237. package/packages/identity/vendor/clack-prompts/index.d.ts +10 -0
  238. package/packages/identity/vendor/clack-prompts/index.js +55 -0
  239. package/packages/identity/vendor/clack-prompts/package.json +11 -0
  240. package/packages/memory/dist/.tsbuildinfo +1 -0
  241. package/packages/memory/dist/default-store.d.ts +21 -0
  242. package/packages/memory/dist/default-store.d.ts.map +1 -0
  243. package/packages/memory/dist/default-store.js +52 -0
  244. package/packages/memory/dist/default-store.js.map +1 -0
  245. package/packages/memory/dist/embedding.d.ts +6 -0
  246. package/packages/memory/dist/embedding.d.ts.map +1 -0
  247. package/packages/memory/dist/embedding.js +56 -0
  248. package/packages/memory/dist/embedding.js.map +1 -0
  249. package/packages/memory/dist/forgetting-curve.d.ts +3 -0
  250. package/packages/memory/dist/forgetting-curve.d.ts.map +1 -0
  251. package/packages/memory/dist/forgetting-curve.js +21 -0
  252. package/packages/memory/dist/forgetting-curve.js.map +1 -0
  253. package/packages/memory/dist/index.d.ts +5 -0
  254. package/packages/memory/dist/index.d.ts.map +1 -0
  255. package/packages/memory/dist/index.js +4 -0
  256. package/packages/memory/dist/index.js.map +1 -0
  257. package/packages/memory/dist/memory-store.d.ts +39 -0
  258. package/packages/memory/dist/memory-store.d.ts.map +1 -0
  259. package/packages/memory/dist/memory-store.js +417 -0
  260. package/packages/memory/dist/memory-store.js.map +1 -0
  261. package/packages/memory/dist/sqlite.d.ts +19 -0
  262. package/packages/memory/dist/sqlite.d.ts.map +1 -0
  263. package/packages/memory/dist/sqlite.js +195 -0
  264. package/packages/memory/dist/sqlite.js.map +1 -0
  265. package/packages/memory/dist/types.d.ts +43 -0
  266. package/packages/memory/dist/types.d.ts.map +1 -0
  267. package/packages/memory/dist/types.js +2 -0
  268. package/packages/memory/dist/types.js.map +1 -0
  269. package/packages/memory/package.json +18 -0
  270. package/packages/skills/dist/.tsbuildinfo +1 -0
  271. package/packages/skills/dist/frontmatter.d.ts +3 -0
  272. package/packages/skills/dist/frontmatter.d.ts.map +1 -0
  273. package/packages/skills/dist/frontmatter.js +85 -0
  274. package/packages/skills/dist/frontmatter.js.map +1 -0
  275. package/packages/skills/dist/index.d.ts +6 -0
  276. package/packages/skills/dist/index.d.ts.map +1 -0
  277. package/packages/skills/dist/index.js +5 -0
  278. package/packages/skills/dist/index.js.map +1 -0
  279. package/packages/skills/dist/paths.d.ts +13 -0
  280. package/packages/skills/dist/paths.d.ts.map +1 -0
  281. package/packages/skills/dist/paths.js +43 -0
  282. package/packages/skills/dist/paths.js.map +1 -0
  283. package/packages/skills/dist/search.d.ts +3 -0
  284. package/packages/skills/dist/search.d.ts.map +1 -0
  285. package/packages/skills/dist/search.js +20 -0
  286. package/packages/skills/dist/search.js.map +1 -0
  287. package/packages/skills/dist/store.d.ts +8 -0
  288. package/packages/skills/dist/store.d.ts.map +1 -0
  289. package/packages/skills/dist/store.js +75 -0
  290. package/packages/skills/dist/store.js.map +1 -0
  291. package/packages/skills/dist/types.d.ts +9 -0
  292. package/packages/skills/dist/types.d.ts.map +1 -0
  293. package/packages/skills/dist/types.js +2 -0
  294. package/packages/skills/dist/types.js.map +1 -0
  295. package/packages/skills/package.json +18 -0
  296. package/skills/install-va-claw.md +180 -0
  297. package/vendor/commander/index.d.ts +16 -0
  298. package/vendor/commander/index.js +110 -0
  299. package/vendor/commander/package.json +11 -0
  300. package/vendor/croner/LICENSE +22 -0
  301. package/vendor/croner/README.md +339 -0
  302. package/vendor/croner/dist/croner.cjs +1 -0
  303. package/vendor/croner/dist/croner.d.cts +693 -0
  304. package/vendor/croner/dist/croner.d.ts +693 -0
  305. package/vendor/croner/dist/croner.js +1 -0
  306. package/vendor/croner/dist/croner.umd.js +1 -0
  307. package/vendor/croner/package.json +73 -0
  308. package/vendor/discord.js/index.d.ts +22 -0
  309. package/vendor/discord.js/index.js +37 -0
  310. package/vendor/discord.js/package.json +7 -0
  311. package/vendor/grammy/index.d.ts +43 -0
  312. package/vendor/grammy/index.js +89 -0
  313. package/vendor/grammy/package.json +7 -0
  314. package/vendor/slack-bolt/index.d.ts +29 -0
  315. package/vendor/slack-bolt/index.js +72 -0
  316. package/vendor/slack-bolt/package.json +7 -0
@@ -0,0 +1,339 @@
1
+ <p align="center">
2
+ <img src="https://cdn.jsdelivr.net/gh/hexagon/croner@master/croner.png" alt="Croner" width="150" height="150"><br>
3
+ Trigger functions or evaluate cron expressions in JavaScript or TypeScript. No dependencies. All features. Node. Deno. Bun. Browser. <br><br>Try it live on <a href="https://jsfiddle.net/hexag0n/hoa8kwsb/">jsfiddle</a>, and check out the full documentation on <a href="https://croner.56k.guru">croner.56k.guru</a>.<br>
4
+ </p>
5
+
6
+ # Croner - Cron for JavaScript and TypeScript
7
+
8
+ [![npm version](https://badge.fury.io/js/croner.svg)](https://badge.fury.io/js/croner) [![JSR](https://jsr.io/badges/@hexagon/croner)](https://jsr.io/@hexagon/croner) [![NPM Downloads](https://img.shields.io/npm/dw/croner.svg)](https://www.npmjs.org/package/croner)
9
+ ![No dependencies](https://img.shields.io/badge/dependencies-none-brightgreen) [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Hexagon/croner/blob/master/LICENSE)
10
+
11
+ * Trigger functions in JavaScript using [Cron](https://en.wikipedia.org/wiki/Cron#CRON_expression) syntax.
12
+ * Evaluate cron expressions and get a list of upcoming run times.
13
+ * Supports seconds and year fields, `L` (last), `W` (weekday), `#` (nth occurrence), and `+` (AND logic).
14
+ * Works in Node.js >=18.0 (both require and import), Deno >=2.0 and Bun >=1.0.0.
15
+ * Works in browsers as standalone, UMD or ES-module.
16
+ * Target different [time zones](https://croner.56k.guru/usage/examples/#time-zone).
17
+ * Built-in [overrun protection](https://croner.56k.guru/usage/examples/#overrun-protection)
18
+ * Built-in [error handling](https://croner.56k.guru/usage/examples/#error-handling)
19
+ * Includes [TypeScript](https://www.typescriptlang.org/) typings.
20
+ * Support for asynchronous functions.
21
+ * Pause, resume, or stop execution after a task is scheduled.
22
+ * Operates in-memory, with no need for a database or configuration files.
23
+ * Zero dependencies.
24
+
25
+ Quick examples:
26
+
27
+ ```javascript
28
+ // Basic: Run a function at the interval defined by a cron expression
29
+ const job = new Cron('*/5 * * * * *', () => {
30
+ console.log('This will run every fifth second');
31
+ });
32
+
33
+ // Enumeration: What dates do the next 100 sundays occur on?
34
+ const nextSundays = new Cron('0 0 0 * * 7').nextRuns(100);
35
+ console.log(nextSundays);
36
+
37
+ // Days left to a specific date
38
+ const msLeft = new Cron('59 59 23 24 DEC *').nextRun() - new Date();
39
+ console.log(Math.floor(msLeft/1000/3600/24) + " days left to next christmas eve");
40
+
41
+ // Run a function at a specific date/time using a non-local timezone (time is ISO 8601 local time)
42
+ // This will run 2024-01-23 00:00:00 according to the time in Asia/Kolkata
43
+ new Cron('2024-01-23T00:00:00', { timezone: 'Asia/Kolkata' }, () => { console.log('Yay!') });
44
+
45
+ // Check if a date matches a cron pattern
46
+ const mondayCheck = new Cron('0 0 0 * * MON');
47
+ console.log(mondayCheck.match('2024-01-01T00:00:00')); // true (Monday)
48
+ console.log(mondayCheck.match('2024-01-02T00:00:00')); // false (Tuesday)
49
+
50
+ ```
51
+
52
+ More [examples](https://croner.56k.guru/usage/examples/)...
53
+
54
+ ## Installation
55
+
56
+ Full documentation on installation and usage is found at <https://croner.56k.guru>
57
+
58
+ > **Note**
59
+ > If you are migrating from a different library such as `cron` or `node-cron`, or upgrading from a older version of croner, see the [migration section](https://croner.56k.guru/migration/) of the manual.
60
+
61
+ Install croner using your favorite package manager or CDN, then include it in you project:
62
+
63
+ Using Node.js or Bun
64
+
65
+ ```javascript
66
+ // ESM Import ...
67
+ import { Cron } from "croner";
68
+
69
+ // ... or CommonJS Require, destructure to add type hints
70
+ const { Cron } = require("croner");
71
+ ```
72
+
73
+ Using Deno
74
+
75
+ ```typescript
76
+ // From deno.land/x
77
+ import { Cron } from "https://deno.land/x/croner@10.0.0/dist/croner.js";
78
+
79
+ // ... or jsr.io
80
+ import { Cron } from "jsr:@hexagon/croner@10.0.0";
81
+ ```
82
+
83
+ In a webpage using the UMD-module
84
+
85
+ ```html
86
+ <script src="https://cdn.jsdelivr.net/npm/croner@10/dist/croner.umd.min.js"></script>
87
+ ```
88
+
89
+ ## Documentation
90
+
91
+ ### Signature
92
+
93
+ Cron takes three arguments
94
+
95
+ * [pattern](#pattern)
96
+ * [options](#options) (optional)
97
+ * scheduled function (optional)
98
+
99
+ ```javascript
100
+ // Parameters
101
+ // - First: Cron pattern, js date object (fire once), or ISO 8601 time string (fire once)
102
+ // - Second: Options (optional)
103
+ // - Third: Function run trigger (optional)
104
+ const job = new Cron("* * * * * *", { maxRuns: 1 }, () => {} );
105
+
106
+ // If function is omitted in constructor, it can be scheduled later
107
+ job.schedule(job, /* optional */ context) => {});
108
+ ```
109
+
110
+ The job will be sceduled to run at next matching time unless you supply option `{ paused: true }`. The `new Cron(...)` constructor will return a Cron instance, later called `job`, which have a couple of methods and properties listed below.
111
+
112
+ #### Status
113
+
114
+ ```javascript
115
+ job.nextRun( /*optional*/ startFromDate ); // Get a Date object representing the next run.
116
+ job.nextRuns(10, /*optional*/ startFromDate ); // Get an array of Dates, containing the next n runs.
117
+ job.previousRuns(10, /*optional*/ referenceDate ); // Get an array of Dates, containing previous n scheduled runs.
118
+ job.msToNext( /*optional*/ startFromDate ); // Get the milliseconds left until the next execution.
119
+ job.currentRun(); // Get a Date object showing when the current (or last) run was started.
120
+ job.previousRun( ); // Get a Date object showing when the previous job was started.
121
+
122
+ job.match( date ); // Check if a Date object or date string matches the cron pattern (true or false).
123
+
124
+ job.isRunning(); // Indicates if the job is scheduled and not paused or killed (true or false).
125
+ job.isStopped(); // Indicates if the job is permanently stopped using `stop()` (true or false).
126
+ job.isBusy(); // Indicates if the job is currently busy doing work (true or false).
127
+
128
+ job.getPattern(); // Returns the original pattern string
129
+ job.getOnce(); // Returns the original run-once date (Date or null)
130
+ ```
131
+
132
+ #### Control functions
133
+
134
+ ```javascript
135
+ job.trigger(); // Force a trigger instantly
136
+ job.pause(); // Pause trigger
137
+ job.resume(); // Resume trigger
138
+ job.stop(); // Stop the job completely. It is not possible to resume after this.
139
+ // Note that this also removes named jobs from the exported `scheduledJobs` array.
140
+ ```
141
+
142
+ #### Properties
143
+
144
+ ```javascript
145
+ job.name // Optional job name, populated if a name were passed to options
146
+ ```
147
+
148
+ #### Options
149
+
150
+ | Key | Default value | Data type | Remarks |
151
+ |--------------|----------------|----------------|---------------------------------------|
152
+ | name | undefined | String | If you specify a name for the job, Croner will keep a reference to the job in the exported array `scheduledJobs`. The reference will be removed on `.stop()`. |
153
+ | maxRuns | Infinite | Number | |
154
+ | catch | false | Boolean\|Function | Catch unhandled errors in triggered function. Passing `true` will silently ignore errors. Passing a callback function will trigger this callback on error. |
155
+ | timezone | undefined | String | Timezone in Europe/Stockholm format |
156
+ | startAt | undefined | String | ISO 8601 formatted datetime (2021-10-17T23:43:00)<br>in local time (according to timezone parameter if passed) |
157
+ | stopAt | undefined | String | ISO 8601 formatted datetime (2021-10-17T23:43:00)<br>in local time (according to timezone parameter if passed) |
158
+ | interval | 0 | Number | Minimum number of seconds between triggers. |
159
+ | paused | false | Boolean | If the job should be paused from start. |
160
+ | context | undefined | Any | Passed as the second parameter to triggered function |
161
+ | domAndDow | false | boolean | Combine day-of-month and day-of-week using true = AND, false = OR (default) |
162
+ | legacyMode | (deprecated) | boolean | **Deprecated:** Use `domAndDow` instead. Inverse of `domAndDow` (legacyMode: true = domAndDow: false). |
163
+ | unref | false | boolean | Setting this to true unrefs the internal timer, which allows the process to exit even if a cron job is running. |
164
+ | utcOffset | undefined | number | Schedule using a specific utc offset in minutes. This does not take care of daylight savings time, you probably want to use option `timezone` instead. |
165
+ | protect | undefined | boolean\|Function | Enabled over-run protection. Will block new triggers as long as an old trigger is in progress. Pass either `true` or a callback function to enable |
166
+ | alternativeWeekdays | false | boolean | Enable Quartz-style weekday numbering (1=Sunday, 2=Monday, ..., 7=Saturday). When false (default), uses standard cron format (0=Sunday, 1=Monday, ..., 6=Saturday). |
167
+
168
+ > **Warning**
169
+ > Unreferencing timers (option `unref`) is only supported by Node.js and Deno.
170
+ > Browsers have not yet implemented this feature, and it does not make sense to use it in a browser environment.
171
+
172
+ #### Pattern
173
+
174
+ Croner uses [Vixie Cron](https://en.wikipedia.org/wiki/Cron#CRON_expression) based expressions with the following powerful extensions:
175
+
176
+ ```javascript
177
+ // ┌──────────────── (optional) second (0 - 59)
178
+ // │ ┌────────────── minute (0 - 59)
179
+ // │ │ ┌──────────── hour (0 - 23)
180
+ // │ │ │ ┌────────── day of month (1 - 31)
181
+ // │ │ │ │ ┌──────── month (1 - 12, JAN-DEC)
182
+ // │ │ │ │ │ ┌────── day of week (0 - 6, SUN-Mon)
183
+ // │ │ │ │ │ │ (0 to 6 are Sunday to Saturday; 7 is Sunday, the same as 0)
184
+ // │ │ │ │ │ │ ┌──── (optional) year (1 - 9999)
185
+ // │ │ │ │ │ │ │
186
+ // * * * * * * *
187
+ ```
188
+
189
+ * **Optional second and year fields** for enhanced precision:
190
+ - 6-field format: `SECOND MINUTE HOUR DAY-OF-MONTH MONTH DAY-OF-WEEK`
191
+ - 7-field format: `SECOND MINUTE HOUR DAY-OF-MONTH MONTH DAY-OF-WEEK YEAR`
192
+ - Supported year range: 1-9999
193
+
194
+ * **Advanced calendar modifiers**:
195
+ - *L*: Last day of month or last occurrence of a weekday. `L` in day-of-month = last day of month; `5#L` or `FRI#L` = last Friday of the month.
196
+ - *W*: Nearest weekday. `15W` triggers on the weekday closest to the 15th (moves to Friday if 15th is Saturday, Monday if 15th is Sunday). Won't cross month boundaries.
197
+ - *#*: Nth occurrence of a weekday. `5#2` = second Friday; `MON#1` = first Monday of the month.
198
+
199
+ * **Enhanced logical control**:
200
+ - *+*: Explicit AND logic modifier. Prefix the day-of-week field with `+` to require both day-of-month AND day-of-week to match. Example: `0 12 1 * +MON` only triggers when the 1st is also a Monday.
201
+ - *?*: Wildcard alias (behaves identically to `*`). **Non-portable**: Its use is discouraged in patterns intended for cross-system use. Supported in all fields for compatibility, but primarily meaningful in day-of-month and day-of-week fields.
202
+ - Proper DST handling: Jobs scheduled during DST gaps are skipped; jobs in DST overlaps run once at first occurrence.
203
+
204
+ * Croner allows you to pass a JavaScript Date object or an ISO 8601 formatted string as a pattern. The scheduled function will trigger at the specified date/time and only once. If you use a timezone different from the local timezone, you should pass the ISO 8601 local time in the target location and specify the timezone using the options (2nd parameter).
205
+
206
+ * By default, Croner uses OR logic for day-of-month and day-of-week. Example: `0 20 1 * MON` triggers on the 1st of the month OR on Mondays. Use the `+` modifier (`0 20 1 * +MON`) or `{ domAndDow: true }` for AND logic. For more information, see issue [#53](https://github.com/Hexagon/croner/issues/53).
207
+
208
+ | Field | Required | Allowed values | Allowed special characters | Remarks |
209
+ |--------------|----------|----------------|----------------------------|---------------------------------------|
210
+ | Seconds | Optional | 0-59 | * , - / ? | Optional, defaults to 0 |
211
+ | Minutes | Yes | 0-59 | * , - / ? | |
212
+ | Hours | Yes | 0-23 | * , - / ? | |
213
+ | Day of Month | Yes | 1-31 | * , - / ? L W | L = last day, W = nearest weekday |
214
+ | Month | Yes | 1-12 or JAN-DEC| * , - / ? | |
215
+ | Day of Week | Yes | 0-7 or SUN-MON | * , - / ? L # + | 0 and 7 = Sunday (standard mode)<br>1-7 = Sunday-Saturday (Quartz mode with `alternativeWeekdays: true`)<br># = nth occurrence (e.g. MON#2)<br>+ = AND logic modifier |
216
+ | Year | Optional | 1-9999 | * , - / | Optional, defaults to * |
217
+
218
+ > **Note**
219
+ > Weekday and month names are case-insensitive. Both `MON` and `mon` work.
220
+ > When using `L` in the Day of Week field with a range, it affects all specified weekdays. For example, `5-6#L` means the last Friday and Saturday in the month.
221
+ > The `#` character specifies the "nth" weekday of the month. For example, `5#2` = second Friday, `MON#1` = first Monday.
222
+ > The `W` character operates within the current month and won't cross month boundaries. If the 1st is a Saturday, `1W` matches Monday the 3rd.
223
+ > The `+` modifier (OCPS 1.4) enforces AND logic: `0 12 1 * +MON` only runs when the 1st is also a Monday.
224
+ > **Quartz mode**: Enable `alternativeWeekdays: true` to use Quartz-style weekday numbering (1=Sunday, 2=Monday, ..., 7=Saturday) instead of the standard format (0=Sunday, 1=Monday, ..., 6=Saturday). This is useful for compatibility with Quartz cron expressions.
225
+
226
+ **Predefined schedule nicknames** are supported:
227
+
228
+ | Nickname | Description |
229
+ | -------- | ----------- |
230
+ | \@yearly / \@annually | Run once a year, i.e. "0 0 1 1 *". |
231
+ | \@monthly | Run once a month, i.e. "0 0 1 * *". |
232
+ | \@weekly | Run once a week, i.e. "0 0 * * 0". |
233
+ | \@daily / \@midnight | Run once a day, i.e. "0 0 * * *". |
234
+ | \@hourly | Run once an hour, i.e. "0 * * * *". |
235
+
236
+ ## Why another JavaScript cron implementation
237
+
238
+ Because the existing ones are not good enough. They have serious bugs, use bloated dependencies, do not work in all environments, and/or simply do not work as expected.
239
+
240
+ For example, some popular alternatives include large datetime libraries as dependencies, which significantly increases bundle size. Croner has zero dependencies and a much smaller footprint, making it ideal for applications where bundle size matters.
241
+
242
+ | | croner | cronosjs | node-cron | cron | node-schedule |
243
+ |---------------------------|:-------------------:|:-------------------:|:---------:|:-------------------------:|:-------------------:|
244
+ | **Platforms** |
245
+ | Node.js (CommonJS) | ✓ | ✓ | ✓ | ✓ | ✓ |
246
+ | Browser (ESMCommonJS) | ✓ | ✓ | | | |
247
+ | Deno (ESM) | ✓ | | | | |
248
+ | **Features** |
249
+ | Over-run protection | ✓ | | | | |
250
+ | Error handling | ✓ | | | | ✓ |
251
+ | Typescript typings | ✓ | ✓ | | ✓ | |
252
+ | Unref timers (optional) | ✓ | | | ✓ | |
253
+ | dom-OR-dow | ✓ | ✓ | ✓ | ✓ | ✓ |
254
+ | dom-AND-dow (optional) | ✓ | | | | |
255
+ | Next run | ✓ | ✓ | | ✓ | ✓ |
256
+ | Next n runs | ✓ | ✓ | | ✓ | |
257
+ | Timezone | ✓ | ✓ | ✓ | ✓ | ✓ |
258
+ | Minimum interval | ✓ | | | | |
259
+ | Controls (stop/resume) | ✓ | ✓ | ✓ | ✓ | ✓ |
260
+ | Range (0-13) | ✓ | ✓ | ✓ | ✓ | ✓ |
261
+ | Stepping (*/5) | ✓ | ✓ | ✓ | ✓ | ✓ |
262
+ | Seconds field | ✓ | | | | |
263
+ | Year field | ✓ | | | | |
264
+ | Last day of month (L) | ✓ | ✓ | | | |
265
+ | Nth weekday of month (#) | ✓ | ✓ | | | |
266
+ | Nearest weekday (W) | ✓ | ✓ | | | |
267
+ | AND logic modifier (+) | ✓ | | | | |
268
+
269
+ <details>
270
+ <summary>In depth comparison of various libraries</summary>
271
+
272
+ | | croner | cronosjs | node-cron | cron | node-schedule |
273
+ |---------------------------|:-------------------:|:-------------------:|:---------:|:-------------------------:|:-------------------:|
274
+ | **Size** |
275
+ | Minified size (KB) | 22.7 | 14.9 | 20.1 | 93.7 :warning: | 107.8 :warning: |
276
+ | Bundlephobia minzip (KB) | 6.8 | 5.1 | 6.1 | 28.2 | 31.2 :warning: |
277
+ | Dependencies | 0 | 0 | 1 | 1 | 3 :warning: |
278
+ | **Popularity** |
279
+ | Downloads/week [^1] | 2019K | 31K | 447K | 1366K | 1046K |
280
+ | **Quality** |
281
+ | Issues [^1] | 0 | 2 | 133 :warning: | 13 | 145 :warning: |
282
+ | Code coverage | 99% | 98% | 100% | 81% | 94% |
283
+ | **Performance** |
284
+ | Ops/s `1 2 3 4 5 6` | 160 651 | 55 593 | N/A :x: | 6 313 :warning: | 2 726 :warning: |
285
+ | Ops/s `0 0 0 29 2 *` | 176 714 | 67 920 | N/A :x: | 3 104 :warning: | 737 :warning: |
286
+ | **Tests** | **11/11** | **10/11** | **0/11** [^4] :question: | **7/11** :warning: | **9/11** |
287
+
288
+ > **Note**
289
+ > * Table last updated at 2023-10-10
290
+ > * node-cron has no interface to predict when the function will run, so tests cannot be carried out.
291
+ > * All tests and benchmarks were carried out using [https://github.com/Hexagon/cron-comparison](https://github.com/Hexagon/cron-comparison)
292
+
293
+ [^1]: As of 2023-10-10
294
+ [^2]: Requires support for L-modifier
295
+ [^3]: In dom-AND-dow mode, only supported by croner at the moment.
296
+ [^4]: Node-cron has no way of showing next run time.
297
+
298
+ </details>
299
+
300
+ ## Development
301
+
302
+ ### Master branch
303
+
304
+ ![Node.js CI](https://github.com/Hexagon/croner/workflows/Node.js%20CI/badge.svg?branch=master) ![Deno CI](https://github.com/Hexagon/croner/workflows/Deno%20CI/badge.svg?branch=master) ![Bun CI](https://github.com/Hexagon/croner/workflows/Bun%20CI/badge.svg?branch=master)
305
+
306
+ This branch contains the latest stable code, released on npm's default channel `latest`. You can install the latest stable revision by running the command below.
307
+
308
+ ```
309
+ npm install croner --save
310
+ ```
311
+
312
+ ### Dev branch
313
+
314
+ ![Node.js CI](https://github.com/Hexagon/croner/workflows/Node.js%20CI/badge.svg?branch=dev) ![Deno CI](https://github.com/Hexagon/croner/workflows/Deno%20CI/badge.svg?branch=dev) ![Bun CI](https://github.com/Hexagon/croner/workflows/Bun%20CI/badge.svg?branch=dev)
315
+
316
+ This branch contains code currently being tested, and is released at channel `dev` on npm. You can install the latest revision of the development branch by running the command below.
317
+
318
+ ```
319
+ npm install croner@dev
320
+ ```
321
+
322
+ > **Warning**
323
+ > Expect breaking changes if you do not pin to a specific version.
324
+
325
+ A list of fixes and features currently released in the `dev` branch is available [here](https://github.com/Hexagon/croner/issues?q=is%3Aopen+is%3Aissue+label%3Areleased-in-dev)
326
+
327
+ ## Contributing & Support
328
+
329
+ Croner is founded and actively maintained by Hexagon. If you find value in Croner and want to contribute:
330
+
331
+ - Code Contributions: See our [Contribution Guide](https://croner.56k.guru/contributing/) for details on how to contribute code.
332
+
333
+ - Sponsorship and Donations: See [github.com/sponsors/hexagon](https://github.com/sponsors/hexagon)
334
+
335
+ Your trust, support, and contributions drive the project. Every bit, irrespective of its size, is deeply appreciated.
336
+
337
+ ## License
338
+
339
+ MIT License
@@ -0,0 +1 @@
1
+ var D=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var z=Object.prototype.hasOwnProperty;var I=(s,e)=>{for(var t in e)D(s,t,{get:e[t],enumerable:!0})},L=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of S(e))!z.call(s,n)&&n!==t&&D(s,n,{get:()=>e[n],enumerable:!(r=U(e,n))||r.enumerable});return s};var Y=s=>L(D({},"__esModule",{value:!0}),s);var $={};I($,{Cron:()=>R,CronDate:()=>m,CronPattern:()=>p,scheduledJobs:()=>b});module.exports=Y($);function C(s){return Date.UTC(s.y,s.m-1,s.d,s.h,s.i,s.s)}function v(s,e){return s.y===e.y&&s.m===e.m&&s.d===e.d&&s.h===e.h&&s.i===e.i&&s.s===e.s}function F(s,e){let t=new Date(Date.parse(s));if(isNaN(t))throw new Error("Invalid ISO8601 passed to timezone parser.");let r=s.substring(9);return r.includes("Z")||r.includes("+")||r.includes("-")?w(t.getUTCFullYear(),t.getUTCMonth()+1,t.getUTCDate(),t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds(),"Etc/UTC"):w(t.getFullYear(),t.getMonth()+1,t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),e)}function k(s,e,t){return O(F(s,e),t)}function O(s,e){let t=new Date(C(s)),r=g(t,s.tz),n=C(s),i=C(r),a=n-i,o=new Date(t.getTime()+a),h=g(o,s.tz);if(v(h,s)){let u=new Date(o.getTime()-36e5),d=g(u,s.tz);return v(d,s)?u:o}let l=new Date(o.getTime()+C(s)-C(h)),y=g(l,s.tz);if(v(y,s))return l;if(e)throw new Error("Invalid date passed to fromTZ()");return o.getTime()>l.getTime()?o:l}function g(s,e){let t,r;try{t=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!1}),r=t.formatToParts(s)}catch(i){let a=i instanceof Error?i.message:String(i);throw new RangeError(`toTZ: Invalid timezone '${e}' or date. Please provide a valid IANA timezone (e.g., 'America/New_York', 'Europe/Stockholm'). Original error: ${a}`)}let n={year:0,month:0,day:0,hour:0,minute:0,second:0};for(let i of r)(i.type==="year"||i.type==="month"||i.type==="day"||i.type==="hour"||i.type==="minute"||i.type==="second")&&(n[i.type]=parseInt(i.value,10));if(isNaN(n.year)||isNaN(n.month)||isNaN(n.day)||isNaN(n.hour)||isNaN(n.minute)||isNaN(n.second))throw new Error(`toTZ: Failed to parse all date components from timezone '${e}'. This may indicate an invalid date or timezone configuration. Parsed components: ${JSON.stringify(n)}`);return n.hour===24&&(n.hour=0),{y:n.year,m:n.month,d:n.day,h:n.hour,i:n.minute,s:n.second,tz:e}}function w(s,e,t,r,n,i,a){return{y:s,m:e,d:t,h:r,i:n,s:i,tz:a}}var N=[1,2,4,8,16],p=class{pattern;timezone;mode;alternativeWeekdays;sloppyRanges;second;minute;hour;day;month;dayOfWeek;year;lastDayOfMonth;lastWeekday;nearestWeekdays;starDOM;starDOW;starYear;useAndLogic;constructor(e,t,r){this.pattern=e,this.timezone=t,this.mode=r?.mode??"auto",this.alternativeWeekdays=r?.alternativeWeekdays??!1,this.sloppyRanges=r?.sloppyRanges??!1,this.second=Array(60).fill(0),this.minute=Array(60).fill(0),this.hour=Array(24).fill(0),this.day=Array(31).fill(0),this.month=Array(12).fill(0),this.dayOfWeek=Array(7).fill(0),this.year=Array(1e4).fill(0),this.lastDayOfMonth=!1,this.lastWeekday=!1,this.nearestWeekdays=Array(31).fill(0),this.starDOM=!1,this.starDOW=!1,this.starYear=!1,this.useAndLogic=!1,this.parse()}parse(){if(!(typeof this.pattern=="string"||this.pattern instanceof String))throw new TypeError("CronPattern: Pattern has to be of type string.");this.pattern.indexOf("@")>=0&&(this.pattern=this.handleNicknames(this.pattern).trim());let e=this.pattern.match(/\S+/g)||[""],t=e.length;if(e.length<5||e.length>7)throw new TypeError("CronPattern: invalid configuration format ('"+this.pattern+"'), exactly five, six, or seven space separated parts are required.");if(this.mode!=="auto"){let n;switch(this.mode){case"5-part":n=5;break;case"6-part":n=6;break;case"7-part":n=7;break;case"5-or-6-parts":n=[5,6];break;case"6-or-7-parts":n=[6,7];break;default:n=0}if(!(Array.isArray(n)?n.includes(t):t===n)){let a=Array.isArray(n)?n.join(" or "):n.toString();throw new TypeError(`CronPattern: mode '${this.mode}' requires exactly ${a} parts, but pattern '${this.pattern}' has ${t} parts.`)}}if(e.length===5&&e.unshift("0"),e.length===6&&e.push("*"),e[3].toUpperCase()==="LW"?(this.lastWeekday=!0,e[3]=""):e[3].toUpperCase().indexOf("L")>=0&&(e[3]=e[3].replace(/L/gi,""),this.lastDayOfMonth=!0),e[3]=="*"&&(this.starDOM=!0),e[6]=="*"&&(this.starYear=!0),e[4].length>=3&&(e[4]=this.replaceAlphaMonths(e[4])),e[5].length>=3&&(e[5]=this.alternativeWeekdays?this.replaceAlphaDaysQuartz(e[5]):this.replaceAlphaDays(e[5])),e[5].startsWith("+")&&(this.useAndLogic=!0,e[5]=e[5].substring(1),e[5]===""))throw new TypeError("CronPattern: Day-of-week field cannot be empty after '+' modifier.");switch(e[5]=="*"&&(this.starDOW=!0),this.pattern.indexOf("?")>=0&&(e[0]=e[0].replace(/\?/g,"*"),e[1]=e[1].replace(/\?/g,"*"),e[2]=e[2].replace(/\?/g,"*"),e[3]=e[3].replace(/\?/g,"*"),e[4]=e[4].replace(/\?/g,"*"),e[5]=e[5].replace(/\?/g,"*"),e[6]&&(e[6]=e[6].replace(/\?/g,"*"))),this.mode){case"5-part":e[0]="0",e[6]="*";break;case"6-part":e[6]="*";break;case"5-or-6-parts":e[6]="*";break;case"6-or-7-parts":break;case"7-part":case"auto":break}this.throwAtIllegalCharacters(e),this.partToArray("second",e[0],0,1),this.partToArray("minute",e[1],0,1),this.partToArray("hour",e[2],0,1),this.partToArray("day",e[3],-1,1),this.partToArray("month",e[4],-1,1);let r=this.alternativeWeekdays?-1:0;this.partToArray("dayOfWeek",e[5],r,63),this.partToArray("year",e[6],0,1),!this.alternativeWeekdays&&this.dayOfWeek[7]&&(this.dayOfWeek[0]=this.dayOfWeek[7])}partToArray(e,t,r,n){let i=this[e],a=e==="day"&&this.lastDayOfMonth,o=e==="day"&&this.lastWeekday;if(t===""&&!a&&!o)throw new TypeError("CronPattern: configuration entry "+e+" ("+t+") is empty, check for trailing spaces.");if(t==="*")return i.fill(n);let h=t.split(",");if(h.length>1)for(let l=0;l<h.length;l++)this.partToArray(e,h[l],r,n);else t.indexOf("-")!==-1&&t.indexOf("/")!==-1?this.handleRangeWithStepping(t,e,r,n):t.indexOf("-")!==-1?this.handleRange(t,e,r,n):t.indexOf("/")!==-1?this.handleStepping(t,e,r,n):t!==""&&this.handleNumber(t,e,r,n)}throwAtIllegalCharacters(e){for(let t=0;t<e.length;t++)if((t===3?/[^/*0-9,\-WwLl]+/:t===5?/[^/*0-9,\-#Ll]+/:/[^/*0-9,\-]+/).test(e[t]))throw new TypeError("CronPattern: configuration entry "+t+" ("+e[t]+") contains illegal characters.")}handleNumber(e,t,r,n){let i=this.extractNth(e,t),a=e.toUpperCase().includes("W");if(t!=="day"&&a)throw new TypeError("CronPattern: Nearest weekday modifier (W) only allowed in day-of-month.");a&&(t="nearestWeekdays");let o=parseInt(i[0],10)+r;if(isNaN(o))throw new TypeError("CronPattern: "+t+" is not a number: '"+e+"'");this.setPart(t,o,i[1]||n)}setPart(e,t,r){if(!Object.prototype.hasOwnProperty.call(this,e))throw new TypeError("CronPattern: Invalid part specified: "+e);if(e==="dayOfWeek"){if(t===7&&(t=0),t<0||t>6)throw new RangeError("CronPattern: Invalid value for dayOfWeek: "+t);this.setNthWeekdayOfMonth(t,r);return}if(e==="second"||e==="minute"){if(t<0||t>=60)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="hour"){if(t<0||t>=24)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="day"||e==="nearestWeekdays"){if(t<0||t>=31)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="month"){if(t<0||t>=12)throw new RangeError("CronPattern: Invalid value for "+e+": "+t)}else if(e==="year"&&(t<1||t>=1e4))throw new RangeError("CronPattern: Invalid value for "+e+": "+t+" (supported range: 1-9999)");this[e][t]=r}validateNotNaN(e,t){if(isNaN(e))throw new TypeError(t)}validateRange(e,t,r,n,i){if(e>t)throw new TypeError("CronPattern: From value is larger than to value: '"+i+"'");if(r!==void 0){if(r===0)throw new TypeError("CronPattern: Syntax error, illegal stepping: 0");if(r>this[n].length)throw new TypeError("CronPattern: Syntax error, steps cannot be greater than maximum value of part ("+this[n].length+")")}}handleRangeWithStepping(e,t,r,n){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in ranges with stepping.");let i=this.extractNth(e,t),a=i[0].match(/^(\d+)-(\d+)\/(\d+)$/);if(a===null)throw new TypeError("CronPattern: Syntax error, illegal range with stepping: '"+e+"'");let[,o,h,l]=a,y=parseInt(o,10)+r,u=parseInt(h,10)+r,d=parseInt(l,10);this.validateNotNaN(y,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(u,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateNotNaN(d,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(y,u,d,t,e);for(let c=y;c<=u;c+=d)this.setPart(t,c,i[1]||n)}extractNth(e,t){let r=e,n;if(r.includes("#")){if(t!=="dayOfWeek")throw new Error("CronPattern: nth (#) only allowed in day-of-week field");n=r.split("#")[1],r=r.split("#")[0]}else if(r.toUpperCase().endsWith("L")){if(t!=="dayOfWeek")throw new Error("CronPattern: L modifier only allowed in day-of-week field (use L alone for day-of-month)");n="L",r=r.slice(0,-1)}return[r,n]}handleRange(e,t,r,n){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in a range.");let i=this.extractNth(e,t),a=i[0].split("-");if(a.length!==2)throw new TypeError("CronPattern: Syntax error, illegal range: '"+e+"'");let o=parseInt(a[0],10)+r,h=parseInt(a[1],10)+r;this.validateNotNaN(o,"CronPattern: Syntax error, illegal lower range (NaN)"),this.validateNotNaN(h,"CronPattern: Syntax error, illegal upper range (NaN)"),this.validateRange(o,h,void 0,t,e);for(let l=o;l<=h;l++)this.setPart(t,l,i[1]||n)}handleStepping(e,t,r,n){if(e.toUpperCase().includes("W"))throw new TypeError("CronPattern: Syntax error, W is not allowed in parts with stepping.");let i=this.extractNth(e,t),a=i[0].split("/");if(a.length!==2)throw new TypeError("CronPattern: Syntax error, illegal stepping: '"+e+"'");if(this.sloppyRanges)a[0]===""&&(a[0]="*");else{if(a[0]==="")throw new TypeError("CronPattern: Syntax error, stepping with missing prefix ('"+e+"') is not allowed. Use wildcard (*/step) or range (min-max/step) instead.");if(a[0]!=="*")throw new TypeError("CronPattern: Syntax error, stepping with numeric prefix ('"+e+"') is not allowed. Use wildcard (*/step) or range (min-max/step) instead.")}let o=0;a[0]!=="*"&&(o=parseInt(a[0],10)+r);let h=parseInt(a[1],10);this.validateNotNaN(h,"CronPattern: Syntax error, illegal stepping: (NaN)"),this.validateRange(0,this[t].length-1,h,t,e);for(let l=o;l<this[t].length;l+=h)this.setPart(t,l,i[1]||n)}replaceAlphaDays(e){return e.replace(/-sun/gi,"-7").replace(/sun/gi,"0").replace(/mon/gi,"1").replace(/tue/gi,"2").replace(/wed/gi,"3").replace(/thu/gi,"4").replace(/fri/gi,"5").replace(/sat/gi,"6")}replaceAlphaDaysQuartz(e){return e.replace(/sun/gi,"1").replace(/mon/gi,"2").replace(/tue/gi,"3").replace(/wed/gi,"4").replace(/thu/gi,"5").replace(/fri/gi,"6").replace(/sat/gi,"7")}replaceAlphaMonths(e){return e.replace(/jan/gi,"1").replace(/feb/gi,"2").replace(/mar/gi,"3").replace(/apr/gi,"4").replace(/may/gi,"5").replace(/jun/gi,"6").replace(/jul/gi,"7").replace(/aug/gi,"8").replace(/sep/gi,"9").replace(/oct/gi,"10").replace(/nov/gi,"11").replace(/dec/gi,"12")}handleNicknames(e){let t=e.trim().toLowerCase();if(t==="@yearly"||t==="@annually")return"0 0 1 1 *";if(t==="@monthly")return"0 0 1 * *";if(t==="@weekly")return"0 0 * * 0";if(t==="@daily"||t==="@midnight")return"0 0 * * *";if(t==="@hourly")return"0 * * * *";if(t==="@reboot")throw new TypeError("CronPattern: @reboot is not supported in this environment. This is an event-based trigger that requires system startup detection.");return e}setNthWeekdayOfMonth(e,t){if(typeof t!="number"&&t.toUpperCase()==="L")this.dayOfWeek[e]=this.dayOfWeek[e]|32;else if(t===63)this.dayOfWeek[e]=63;else if(t<6&&t>0)this.dayOfWeek[e]=this.dayOfWeek[e]|N[t-1];else throw new TypeError(`CronPattern: nth weekday out of range, should be 1-5 or L. Value: ${t}, Type: ${typeof t}`)}};var M=[31,28,31,30,31,30,31,31,30,31,30,31],f=[["month","year",0],["day","month",-1],["hour","day",0],["minute","hour",0],["second","minute",0]],m=class s{tz;ms;second;minute;hour;day;month;year;constructor(e,t){if(this.tz=t,e&&e instanceof Date)if(!isNaN(e))this.fromDate(e);else throw new TypeError("CronDate: Invalid date passed to CronDate constructor");else if(e==null)this.fromDate(new Date);else if(e&&typeof e=="string")this.fromString(e);else if(e instanceof s)this.fromCronDate(e);else throw new TypeError("CronDate: Invalid type ("+typeof e+") passed to CronDate constructor")}getLastDayOfMonth(e,t){return t!==1?M[t]:new Date(Date.UTC(e,t+1,0)).getUTCDate()}getLastWeekday(e,t){let r=this.getLastDayOfMonth(e,t),i=new Date(Date.UTC(e,t,r)).getUTCDay();return i===0?r-2:i===6?r-1:r}getNearestWeekday(e,t,r){let n=this.getLastDayOfMonth(e,t);if(r>n)return-1;let a=new Date(Date.UTC(e,t,r)).getUTCDay();return a===0?r===n?r-2:r+1:a===6?r===1?r+2:r-1:r}isNthWeekdayOfMonth(e,t,r,n){let a=new Date(Date.UTC(e,t,r)).getUTCDay(),o=0;for(let h=1;h<=r;h++)new Date(Date.UTC(e,t,h)).getUTCDay()===a&&o++;if(n&63&&N[o-1]&n)return!0;if(n&32){let h=this.getLastDayOfMonth(e,t);for(let l=r+1;l<=h;l++)if(new Date(Date.UTC(e,t,l)).getUTCDay()===a)return!1;return!0}return!1}fromDate(e){if(this.tz!==void 0)if(typeof this.tz=="number")this.ms=e.getUTCMilliseconds(),this.second=e.getUTCSeconds(),this.minute=e.getUTCMinutes()+this.tz,this.hour=e.getUTCHours(),this.day=e.getUTCDate(),this.month=e.getUTCMonth(),this.year=e.getUTCFullYear(),this.apply();else try{let t=g(e,this.tz);this.ms=e.getMilliseconds(),this.second=t.s,this.minute=t.i,this.hour=t.h,this.day=t.d,this.month=t.m-1,this.year=t.y}catch(t){let r=t instanceof Error?t.message:String(t);throw new TypeError(`CronDate: Failed to convert date to timezone '${this.tz}'. This may happen with invalid timezone names or dates. Original error: ${r}`)}else this.ms=e.getMilliseconds(),this.second=e.getSeconds(),this.minute=e.getMinutes(),this.hour=e.getHours(),this.day=e.getDate(),this.month=e.getMonth(),this.year=e.getFullYear()}fromCronDate(e){this.tz=e.tz,this.year=e.year,this.month=e.month,this.day=e.day,this.hour=e.hour,this.minute=e.minute,this.second=e.second,this.ms=e.ms}apply(){if(this.month>11||this.month<0||this.day>M[this.month]||this.day<1||this.hour>59||this.minute>59||this.second>59||this.hour<0||this.minute<0||this.second<0){let e=new Date(Date.UTC(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms));return this.ms=e.getUTCMilliseconds(),this.second=e.getUTCSeconds(),this.minute=e.getUTCMinutes(),this.hour=e.getUTCHours(),this.day=e.getUTCDate(),this.month=e.getUTCMonth(),this.year=e.getUTCFullYear(),!0}else return!1}fromString(e){if(typeof this.tz=="number"){let t=k(e);this.ms=t.getUTCMilliseconds(),this.second=t.getUTCSeconds(),this.minute=t.getUTCMinutes(),this.hour=t.getUTCHours(),this.day=t.getUTCDate(),this.month=t.getUTCMonth(),this.year=t.getUTCFullYear(),this.apply()}else return this.fromDate(k(e,this.tz))}findNext(e,t,r,n){return this._findMatch(e,t,r,n,1)}_findMatch(e,t,r,n,i){let a=this[t],o;r.lastDayOfMonth&&(o=this.getLastDayOfMonth(this.year,this.month));let h=!r.starDOW&&t=="day"?new Date(Date.UTC(this.year,this.month,1,0,0,0,0)).getUTCDay():void 0,l=this[t]+n,y=i===1?u=>u<r[t].length:u=>u>=0;for(let u=l;y(u);u+=i){let d=r[t][u];if(t==="day"&&!d){for(let c=0;c<r.nearestWeekdays.length;c++)if(r.nearestWeekdays[c]){let _=this.getNearestWeekday(this.year,this.month,c-n);if(_===-1)continue;if(_===u-n){d=1;break}}}if(t==="day"&&r.lastWeekday){let c=this.getLastWeekday(this.year,this.month);u-n===c&&(d=1)}if(t==="day"&&r.lastDayOfMonth&&u-n==o&&(d=1),t==="day"&&!r.starDOW){let c=r.dayOfWeek[(h+(u-n-1))%7];if(c&&c&63)c=this.isNthWeekdayOfMonth(this.year,this.month,u-n,c)?1:0;else if(c)throw new Error(`CronDate: Invalid value for dayOfWeek encountered. ${c}`);r.useAndLogic?d=d&&c:!e.domAndDow&&!r.starDOM?d=d||c:d=d&&c}if(d)return this[t]=u-n,a!==this[t]?2:1}return 3}recurse(e,t,r){if(r===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let i=-1;for(let a=this.year+1;a<e.year.length&&a<1e4;a++)if(e.year[a]===1){i=a;break}if(i===-1)return null;this.year=i,this.month=0,this.day=1,this.hour=0,this.minute=0,this.second=0,this.ms=0}if(this.year>=1e4)return null}let n=this.findNext(t,f[r][0],e,f[r][2]);if(n>1){let i=r+1;for(;i<f.length;)this[f[i][0]]=-f[i][2],i++;if(n===3){if(this[f[r][1]]++,this[f[r][0]]=-f[r][2],this.apply(),r===0&&!e.starYear){for(;this.year>=0&&this.year<e.year.length&&e.year[this.year]===0&&this.year<1e4;)this.year++;if(this.year>=1e4||this.year>=e.year.length)return null}return this.recurse(e,t,0)}else if(this.apply())return this.recurse(e,t,r-1)}return r+=1,r>=f.length?this:(e.starYear?this.year>=3e3:this.year>=1e4)?null:this.recurse(e,t,r)}increment(e,t,r){return this.second+=t.interval!==void 0&&t.interval>1&&r?t.interval:1,this.ms=0,this.apply(),this.recurse(e,t,0)}decrement(e,t){return this.second-=t.interval!==void 0&&t.interval>1?t.interval:1,this.ms=0,this.apply(),this.recurseBackward(e,t,0,0)}recurseBackward(e,t,r,n=0){if(n>1e4)return null;if(r===0&&!e.starYear){if(this.year>=0&&this.year<e.year.length&&e.year[this.year]===0){let a=-1;for(let o=this.year-1;o>=0;o--)if(e.year[o]===1){a=o;break}if(a===-1)return null;this.year=a,this.month=11,this.day=31,this.hour=23,this.minute=59,this.second=59,this.ms=0}if(this.year<0)return null}let i=this.findPrevious(t,f[r][0],e,f[r][2]);if(i>1){let a=r+1;for(;a<f.length;){let o=f[a][0],h=f[a][2],l=this.getMaxPatternValue(o,e,h);this[o]=l,a++}if(i===3){if(this[f[r][1]]--,r===0){let y=this.getLastDayOfMonth(this.year,this.month);this.day>y&&(this.day=y)}if(r===1)if(this.day<=0)this.day=1;else{let y=this.year,u=this.month;for(;u<0;)u+=12,y--;for(;u>11;)u-=12,y++;let d=u!==1?M[u]:new Date(Date.UTC(y,u+1,0)).getUTCDate();this.day>d&&(this.day=d)}this.apply();let o=f[r][0],h=f[r][2],l=this.getMaxPatternValue(o,e,h);if(o==="day"){let y=this.getLastDayOfMonth(this.year,this.month);this[o]=Math.min(l,y)}else this[o]=l;if(this.apply(),r===0){let y=f[1][2],u=this.getMaxPatternValue("day",e,y),d=this.getLastDayOfMonth(this.year,this.month),c=Math.min(u,d);c!==this.day&&(this.day=c,this.hour=this.getMaxPatternValue("hour",e,f[2][2]),this.minute=this.getMaxPatternValue("minute",e,f[3][2]),this.second=this.getMaxPatternValue("second",e,f[4][2]))}if(r===0&&!e.starYear){for(;this.year>=0&&this.year<e.year.length&&e.year[this.year]===0;)this.year--;if(this.year<0)return null}return this.recurseBackward(e,t,0,n+1)}else if(this.apply())return this.recurseBackward(e,t,r-1,n+1)}return r+=1,r>=f.length?this:this.year<0?null:this.recurseBackward(e,t,r,n+1)}getMaxPatternValue(e,t,r){if(e==="day"&&t.lastDayOfMonth)return this.getLastDayOfMonth(this.year,this.month);if(e==="day"&&!t.starDOW)return this.getLastDayOfMonth(this.year,this.month);for(let n=t[e].length-1;n>=0;n--)if(t[e][n])return n-r;return t[e].length-1-r}findPrevious(e,t,r,n){return this._findMatch(e,t,r,n,-1)}getDate(e){return e||this.tz===void 0?new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.ms):typeof this.tz=="number"?new Date(Date.UTC(this.year,this.month,this.day,this.hour,this.minute-this.tz,this.second,this.ms)):O(w(this.year,this.month+1,this.day,this.hour,this.minute,this.second,this.tz),!1)}getTime(){return this.getDate(!1).getTime()}match(e,t){if(!e.starYear&&(this.year<0||this.year>=e.year.length||e.year[this.year]===0))return!1;for(let r=0;r<f.length;r++){let n=f[r][0],i=f[r][2],a=this[n];if(a+i<0||a+i>=e[n].length)return!1;let o=e[n][a+i];if(n==="day"){if(!o){for(let h=0;h<e.nearestWeekdays.length;h++)if(e.nearestWeekdays[h]){let l=this.getNearestWeekday(this.year,this.month,h-i);if(l!==-1&&l===a){o=1;break}}}if(e.lastWeekday){let h=this.getLastWeekday(this.year,this.month);a===h&&(o=1)}if(e.lastDayOfMonth){let h=this.getLastDayOfMonth(this.year,this.month);a===h&&(o=1)}if(!e.starDOW){let h=new Date(Date.UTC(this.year,this.month,1,0,0,0,0)).getUTCDay(),l=e.dayOfWeek[(h+(a-1))%7];l&&l&63&&(l=this.isNthWeekdayOfMonth(this.year,this.month,a,l)?1:0),e.useAndLogic?o=o&&l:!t.domAndDow&&!e.starDOM?o=o||l:o=o&&l}}if(!o)return!1}return!0}};function x(s){if(s===void 0&&(s={}),delete s.name,s.legacyMode!==void 0&&s.domAndDow===void 0?s.domAndDow=!s.legacyMode:s.domAndDow===void 0&&(s.domAndDow=!1),s.legacyMode=!s.domAndDow,s.paused=s.paused===void 0?!1:s.paused,s.maxRuns=s.maxRuns===void 0?1/0:s.maxRuns,s.catch=s.catch===void 0?!1:s.catch,s.interval=s.interval===void 0?0:parseInt(s.interval.toString(),10),s.utcOffset=s.utcOffset===void 0?void 0:parseInt(s.utcOffset.toString(),10),s.dayOffset=s.dayOffset===void 0?0:parseInt(s.dayOffset.toString(),10),s.unref=s.unref===void 0?!1:s.unref,s.mode=s.mode===void 0?"auto":s.mode,s.alternativeWeekdays=s.alternativeWeekdays===void 0?!1:s.alternativeWeekdays,s.sloppyRanges=s.sloppyRanges===void 0?!1:s.sloppyRanges,!["auto","5-part","6-part","7-part","5-or-6-parts","6-or-7-parts"].includes(s.mode))throw new Error("CronOptions: mode must be one of 'auto', '5-part', '6-part', '7-part', '5-or-6-parts', or '6-or-7-parts'.");if(s.startAt&&(s.startAt=new m(s.startAt,s.timezone)),s.stopAt&&(s.stopAt=new m(s.stopAt,s.timezone)),s.interval!==null){if(isNaN(s.interval))throw new Error("CronOptions: Supplied value for interval is not a number");if(s.interval<0)throw new Error("CronOptions: Supplied value for interval can not be negative")}if(s.utcOffset!==void 0){if(isNaN(s.utcOffset))throw new Error("CronOptions: Invalid value passed for utcOffset, should be number representing minutes offset from UTC.");if(s.utcOffset<-870||s.utcOffset>870)throw new Error("CronOptions: utcOffset out of bounds.");if(s.utcOffset!==void 0&&s.timezone)throw new Error("CronOptions: Combining 'utcOffset' with 'timezone' is not allowed.")}if(s.unref!==!0&&s.unref!==!1)throw new Error("CronOptions: Unref should be either true, false or undefined(false).");if(s.dayOffset!==void 0&&s.dayOffset!==0&&isNaN(s.dayOffset))throw new Error("CronOptions: Invalid value passed for dayOffset, should be a number representing days to offset.");return s}function T(s){return Object.prototype.toString.call(s)==="[object Function]"||typeof s=="function"||s instanceof Function}function W(s){return T(s)}function E(s){typeof Deno<"u"&&typeof Deno.unrefTimer<"u"?Deno.unrefTimer(s):s&&typeof s.unref<"u"&&s.unref()}var A=30*1e3,b=[],R=class{name;options;_states;fn;getTz(){return this.options.timezone||this.options.utcOffset}applyDayOffset(e){if(this.options.dayOffset!==void 0&&this.options.dayOffset!==0){let t=this.options.dayOffset*24*60*60*1e3;return new Date(e.getTime()+t)}return e}constructor(e,t,r){let n,i;if(T(t))i=t;else if(typeof t=="object")n=t;else if(t!==void 0)throw new Error("Cron: Invalid argument passed for optionsIn. Should be one of function, or object (options).");if(T(r))i=r;else if(typeof r=="object")n=r;else if(r!==void 0)throw new Error("Cron: Invalid argument passed for funcIn. Should be one of function, or object (options).");if(this.name=n?.name,this.options=x(n),this._states={kill:!1,blocking:!1,previousRun:void 0,currentRun:void 0,once:void 0,currentTimeout:void 0,maxRuns:n?n.maxRuns:void 0,paused:n?n.paused:!1,pattern:new p("* * * * *",void 0,{mode:"auto"})},e&&(e instanceof Date||typeof e=="string"&&e.indexOf(":")>0)?this._states.once=new m(e,this.getTz()):this._states.pattern=new p(e,this.options.timezone,{mode:this.options.mode,alternativeWeekdays:this.options.alternativeWeekdays,sloppyRanges:this.options.sloppyRanges}),this.name){if(b.find(o=>o.name===this.name))throw new Error("Cron: Tried to initialize new named job '"+this.name+"', but name already taken.");b.push(this)}return i!==void 0&&W(i)&&(this.fn=i,this.schedule()),this}nextRun(e){let t=this._next(e);return t?this.applyDayOffset(t.getDate(!1)):null}nextRuns(e,t){this._states.maxRuns!==void 0&&e>this._states.maxRuns&&(e=this._states.maxRuns);let r=t||this._states.currentRun||void 0;return this._enumerateRuns(e,r,"next")}previousRuns(e,t){return this._enumerateRuns(e,t||void 0,"previous")}_enumerateRuns(e,t,r){let n=[],i=t?new m(t,this.getTz()):null,a=r==="next"?this._next:this._previous;for(;e--;){let o=a.call(this,i);if(!o)break;let h=o.getDate(!1);n.push(this.applyDayOffset(h)),i=o}return n}match(e){if(this._states.once){let r=new m(e,this.getTz());r.ms=0;let n=new m(this._states.once,this.getTz());return n.ms=0,r.getTime()===n.getTime()}let t=new m(e,this.getTz());return t.ms=0,t.match(this._states.pattern,this.options)}getPattern(){if(!this._states.once)return this._states.pattern?this._states.pattern.pattern:void 0}getOnce(){return this._states.once?this._states.once.getDate():null}isRunning(){let e=this.nextRun(this._states.currentRun),t=!this._states.paused,r=this.fn!==void 0,n=!this._states.kill;return t&&r&&n&&e!==null}isStopped(){return this._states.kill}isBusy(){return this._states.blocking}currentRun(){return this._states.currentRun?this._states.currentRun.getDate():null}previousRun(){return this._states.previousRun?this._states.previousRun.getDate():null}msToNext(e){let t=this._next(e);return t?e instanceof m||e instanceof Date?t.getTime()-e.getTime():t.getTime()-new m(e).getTime():null}stop(){this._states.kill=!0,this._states.currentTimeout&&clearTimeout(this._states.currentTimeout);let e=b.indexOf(this);e>=0&&b.splice(e,1)}pause(){return this._states.paused=!0,!this._states.kill}resume(){return this._states.paused=!1,!this._states.kill}schedule(e){if(e&&this.fn)throw new Error("Cron: It is not allowed to schedule two functions using the same Croner instance.");e&&(this.fn=e);let t=this.msToNext(),r=this.nextRun(this._states.currentRun);return t==null||isNaN(t)||r===null?this:(t>A&&(t=A),this._states.currentTimeout=setTimeout(()=>this._checkTrigger(r),t),this._states.currentTimeout&&this.options.unref&&E(this._states.currentTimeout),this)}async _trigger(e){this._states.blocking=!0,this._states.currentRun=new m(void 0,this.getTz());try{if(this.options.catch)try{this.fn!==void 0&&await this.fn(this,this.options.context)}catch(t){if(T(this.options.catch))try{this.options.catch(t,this)}catch{}}else this.fn!==void 0&&await this.fn(this,this.options.context)}finally{this._states.previousRun=new m(e,this.getTz()),this._states.blocking=!1}}async trigger(){await this._trigger()}runsLeft(){return this._states.maxRuns}_checkTrigger(e){let t=new Date,r=!this._states.paused&&t.getTime()>=e.getTime(),n=this._states.blocking&&this.options.protect;r&&!n?(this._states.maxRuns!==void 0&&this._states.maxRuns--,this._trigger()):r&&n&&T(this.options.protect)&&setTimeout(()=>this.options.protect(this),0),this.schedule()}_next(e){let t=!!(e||this._states.currentRun),r=!1;!e&&this.options.startAt&&this.options.interval&&([e,t]=this._calculatePreviousRun(e,t),r=!e),e=new m(e,this.getTz()),this.options.startAt&&e&&e.getTime()<this.options.startAt.getTime()&&(e=this.options.startAt);let n=this._states.once||new m(e,this.getTz());return!r&&n!==this._states.once&&(n=n.increment(this._states.pattern,this.options,t)),this._states.once&&this._states.once.getTime()<=e.getTime()||n===null||this._states.maxRuns!==void 0&&this._states.maxRuns<=0||this._states.kill||this.options.stopAt&&n.getTime()>=this.options.stopAt.getTime()?null:n}_previous(e){let t=new m(e,this.getTz());this.options.stopAt&&t.getTime()>this.options.stopAt.getTime()&&(t=this.options.stopAt);let r=new m(t,this.getTz());return this._states.once?this._states.once.getTime()<t.getTime()?this._states.once:null:(r=r.decrement(this._states.pattern,this.options),r===null||this.options.startAt&&r.getTime()<this.options.startAt.getTime()?null:r)}_calculatePreviousRun(e,t){let r=new m(void 0,this.getTz()),n=e;if(this.options.startAt.getTime()<=r.getTime()){n=this.options.startAt;let i=n.getTime()+this.options.interval*1e3;for(;i<=r.getTime();)n=new m(n,this.getTz()).increment(this._states.pattern,this.options,!0),i=n.getTime()+this.options.interval*1e3;t=!0}return n===null&&(n=void 0),[n,t]}};0&&(module.exports={Cron,CronDate,CronPattern,scheduledJobs});