@sapphire/cron 1.2.0-pr-601.2f2c308a.0 → 1.2.1-next.624d18f9

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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,46 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ # [@sapphire/cron@1.2.0](https://github.com/sapphiredev/utilities/compare/@sapphire/cron@1.1.3...@sapphire/cron@1.2.0) - (2024-11-02)
6
+
7
+ ## 🐛 Bug Fixes
8
+
9
+ - Move browser imports ([100ffb0](https://github.com/sapphiredev/utilities/commit/100ffb0a2471bb9f74cc580d282d11059e1a0a68)) ([#826](https://github.com/sapphiredev/utilities/pull/826) by @kyranet)
10
+ - **deps:** Update all non-major dependencies ([083376a](https://github.com/sapphiredev/utilities/commit/083376aac55094dbeddb5194e8a8f0d794b8cceb)) ([#763](https://github.com/sapphiredev/utilities/pull/763) by @renovate[bot])
11
+ - **deps:** Update all non-major dependencies ([e7fdc5d](https://github.com/sapphiredev/utilities/commit/e7fdc5db3632a7f90292ef3978898da32730343a)) ([#752](https://github.com/sapphiredev/utilities/pull/752) by @renovate[bot])
12
+
13
+ ## 📝 Documentation
14
+
15
+ - **readme:** Fix readme table of contents ([c60e8bd](https://github.com/sapphiredev/utilities/commit/c60e8bd9fc89156cf973871597ec3f0ef0308c08))
16
+
17
+ ## 🚀 Features
18
+
19
+ - **cron:** Add `toString()` method ([db356eb](https://github.com/sapphiredev/utilities/commit/db356eb06d5dfc0013534417a332a0cd7b9bea4c)) ([#783](https://github.com/sapphiredev/utilities/pull/783) by @kyranet)
20
+
21
+ # [@sapphire/cron@1.1.3](https://github.com/sapphiredev/utilities/compare/@sapphire/cron@1.1.3...@sapphire/cron@1.1.3) - (2024-01-19)
22
+
23
+ ## 🐛 Bug Fixes
24
+
25
+ - Fixed commonjs typings export mapping (#707) ([216ff02](https://github.com/sapphiredev/utilities/commit/216ff0260d63a9590357f9a5069f1ae2b34eaf5d))
26
+
27
+ # [@sapphire/cron@1.1.2](https://github.com/sapphiredev/utilities/compare/@sapphire/cron@1.1.2...@sapphire/cron@1.1.2) - (2023-12-04)
28
+
29
+ ## 🐛 Bug Fixes
30
+
31
+ - **cron:** Properly split CJS, ESM and IIFE ([2b119af](https://github.com/sapphiredev/utilities/commit/2b119afcf745cd00a41d9fe8ec1f7e639b67e693))
32
+ - Update export mapping for proper ESM/CJS split ([dd0cff8](https://github.com/sapphiredev/utilities/commit/dd0cff8e9b03a15812f25f7a1180501a92422629))
33
+
34
+ # [@sapphire/cron@1.1.1](https://github.com/sapphiredev/utilities/compare/@sapphire/cron@1.1.0...@sapphire/cron@1.1.1) - (2023-07-21)
35
+
36
+ ## 🐛 Bug Fixes
37
+
38
+ - **deps:** Update all non-major dependencies (#607) ([9cc8bd0](https://github.com/sapphiredev/utilities/commit/9cc8bd0d4b5d650deab2c913e6c3d713861bae28))
39
+ - **deps:** Update all non-major dependencies (#577) ([291dd67](https://github.com/sapphiredev/utilities/commit/291dd6783e57d8f075ce566218ba076ef6c4bbbd))
40
+
41
+ ## 🧪 Testing
42
+
43
+ - Update vitest to coverage v8 ([a4bc6e4](https://github.com/sapphiredev/utilities/commit/a4bc6e4f24ea60143a150ecc76fda6484f172ab9))
44
+
5
45
  # [@sapphire/cron@1.1.0](https://github.com/sapphiredev/utilities/compare/@sapphire/cron@1.0.0...@sapphire/cron@1.1.0) - (2023-03-15)
6
46
 
7
47
  ## 🏠 Refactor
package/README.md CHANGED
@@ -7,7 +7,6 @@
7
7
  **Cron utilities for JavaScript.**
8
8
 
9
9
  [![GitHub](https://img.shields.io/github/license/sapphiredev/utilities)](https://github.com/sapphiredev/utilities/blob/main/LICENSE.md)
10
- [![codecov](https://codecov.io/gh/sapphiredev/utilities/branch/main/graph/badge.svg?token=OEGIV6RFDO)](https://codecov.io/gh/sapphiredev/utilities)
11
10
  [![npm bundle size](https://img.shields.io/bundlephobia/min/@sapphire/cron?logo=webpack&style=flat-square)](https://bundlephobia.com/result?p=@sapphire/cron)
12
11
  [![npm](https://img.shields.io/npm/v/@sapphire/cron?color=crimson&logo=npm&style=flat-square)](https://www.npmjs.com/package/@sapphire/cron)
13
12
 
@@ -17,10 +16,8 @@
17
16
 
18
17
  - [Features](#features)
19
18
  - [Installation](#installation)
20
- - [Usage](#usage)
21
- - [Basic Usage](#basic-usage)
22
19
  - [Buy us some doughnuts](#buy-us-some-doughnuts)
23
- - [Contributors](#contributors-%E2%9C%A8)
20
+ - [Contributors](#contributors)
24
21
 
25
22
  ## Features
26
23
 
@@ -5,10 +5,7 @@ var utilities = require('@sapphire/utilities');
5
5
  var __defProp = Object.defineProperty;
6
6
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
7
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
- var __publicField = (obj, key, value) => {
9
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
10
- return value;
11
- };
8
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
12
9
 
13
10
  // src/lib/constants.ts
14
11
  var Time = /* @__PURE__ */ ((Time2) => {
@@ -63,7 +60,7 @@ var cronTokens = {
63
60
  sat: 6
64
61
  };
65
62
  var tokensRegex = new RegExp(Object.keys(cronTokens).join("|"), "g");
66
- var Cron = class {
63
+ var _Cron = class _Cron {
67
64
  /**
68
65
  * @param cron The cron pattern to use
69
66
  */
@@ -76,8 +73,8 @@ var Cron = class {
76
73
  __publicField(this, "months");
77
74
  __publicField(this, "dows");
78
75
  this.cron = cron.toLowerCase();
79
- this.normalized = Cron.normalize(this.cron);
80
- [this.minutes, this.hours, this.days, this.months, this.dows] = Cron.parseString(this.normalized);
76
+ this.normalized = _Cron.normalize(this.cron);
77
+ [this.minutes, this.hours, this.days, this.months, this.dows] = _Cron.parseString(this.normalized);
81
78
  }
82
79
  /**
83
80
  * Get the next date that matches with the current pattern
@@ -88,32 +85,35 @@ var Cron = class {
88
85
  if (!this.days.includes(outset.getUTCDate()) || !this.months.includes(outset.getUTCMonth() + 1) || !this.dows.includes(outset.getUTCDay())) {
89
86
  return this.next(new Date(outset.getTime() + 864e5 /* Day */), false);
90
87
  }
91
- if (!origin)
92
- return new Date(Date.UTC(outset.getUTCFullYear(), outset.getUTCMonth(), outset.getUTCDate(), this.hours[0], this.minutes[0]));
88
+ if (!origin) return new Date(Date.UTC(outset.getUTCFullYear(), outset.getUTCMonth(), outset.getUTCDate(), this.hours[0], this.minutes[0]));
93
89
  const now = new Date(outset.getTime() + 6e4);
94
90
  for (const hour of this.hours) {
95
- if (hour < now.getUTCHours())
96
- continue;
91
+ if (hour < now.getUTCHours()) continue;
97
92
  for (const minute of this.minutes) {
98
- if (hour === now.getUTCHours() && minute < now.getUTCMinutes())
99
- continue;
93
+ if (hour === now.getUTCHours() && minute < now.getUTCMinutes()) continue;
100
94
  return new Date(Date.UTC(outset.getUTCFullYear(), outset.getUTCMonth(), outset.getUTCDate(), hour, minute));
101
95
  }
102
96
  }
103
97
  return this.next(new Date(outset.getTime() + 864e5 /* Day */), false);
104
98
  }
99
+ /**
100
+ * Returns the string that represents this cron pattern
101
+ *
102
+ * @returns The string that represents this cron pattern
103
+ */
104
+ toString() {
105
+ return this.cron;
106
+ }
105
107
  /**
106
108
  * Normalize the pattern
107
109
  * @param cron The pattern to normalize
108
110
  */
109
111
  static normalize(cron) {
110
- if (Reflect.has(predefined, cron))
111
- return Reflect.get(predefined, cron);
112
+ if (Reflect.has(predefined, cron)) return Reflect.get(predefined, cron);
112
113
  const now = /* @__PURE__ */ new Date();
113
114
  cron = cron.split(" ").map(
114
115
  (val, i) => val.replace(wildcardRegex, (match) => {
115
- if (match === "h")
116
- return (Math.floor(Math.random() * allowedNum[i][1]) + allowedNum[i][0]).toString();
116
+ if (match === "h") return (Math.floor(Math.random() * allowedNum[i][1]) + allowedNum[i][0]).toString();
117
117
  if (match === "?") {
118
118
  switch (i) {
119
119
  case 0:
@@ -139,9 +139,8 @@ var Cron = class {
139
139
  */
140
140
  static parseString(cron) {
141
141
  const parts = cron.split(" ");
142
- if (parts.length !== 5)
143
- throw new Error("Invalid Cron Provided");
144
- return parts.map((part, i) => Cron.parsePart(part, i));
142
+ if (parts.length !== 5) throw new Error("Invalid Cron Provided");
143
+ return parts.map((part, i) => _Cron.parsePart(part, i));
145
144
  }
146
145
  /**
147
146
  * Parse the current part
@@ -151,21 +150,19 @@ var Cron = class {
151
150
  static parsePart(cronPart, id) {
152
151
  if (cronPart.includes(",")) {
153
152
  const res = [];
154
- for (const part of cronPart.split(","))
155
- res.push(...Cron.parsePart(part, id));
153
+ for (const part of cronPart.split(",")) res.push(..._Cron.parsePart(part, id));
156
154
  return [...new Set(res)].sort((a, b) => a - b);
157
155
  }
158
156
  const [, wild, minStr, maxStr, step] = partRegex.exec(cronPart);
159
157
  let [min, max] = [parseInt(minStr, 10), parseInt(maxStr, 10)];
160
- if (wild)
161
- [min, max] = allowedNum[id];
162
- else if (!max && !step)
163
- return [min];
158
+ if (wild) [min, max] = allowedNum[id];
159
+ else if (!max && !step) return [min];
164
160
  [min, max] = [min, max || allowedNum[id][1]].sort((a, b) => a - b);
165
161
  return utilities.range(min, max, parseInt(step, 10) || 1);
166
162
  }
167
163
  };
168
- __name(Cron, "Cron");
164
+ __name(_Cron, "Cron");
165
+ var Cron = _Cron;
169
166
 
170
167
  exports.Cron = Cron;
171
168
  exports.Time = Time;
@@ -175,5 +172,5 @@ exports.partRegex = partRegex;
175
172
  exports.predefined = predefined;
176
173
  exports.tokensRegex = tokensRegex;
177
174
  exports.wildcardRegex = wildcardRegex;
178
- //# sourceMappingURL=out.js.map
179
- //# sourceMappingURL=index.js.map
175
+ //# sourceMappingURL=index.cjs.map
176
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/lib/constants.ts","../../src/lib/Cron.ts"],"names":["Time","range"],"mappings":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AA,CAAI,GAAG,CAAC,CAAE,CAAA,IAAA,CAAK,CAAC,CAAA,EAAG,CAAM,KAAA,CAAA,GAAI,CAAC,CAAA;AAAA;AAG9C,IAAM,MAAA,GAAG,IAAM,EAAA,MAAA,EAAQ,QAAQ,IAAI,CAAA,GAAI,SAAU,CAAA,IAAA,CAAK,QAAQ,CAAA;AAC9D,IAAA,IAAI,CAAC,GAAA,EAAK,GAAG,CAAA,GAAI,CAAC,QAAA,CAAS,MAAQ,EAAA,EAAE,CAAG,EAAA,QAAA,CAAS,MAAQ,EAAA,EAAE,CAAC,CAAA;AAG5D,IAAA,IAAI,MAAO,CAAA,GAAA,EAAK,GAAG,CAAA,GAAI,WAAW,EAAE,CAAA;AAAA,SAAA,IAG3B,CAAC,GAAO,IAAA,CAAC,IAAM,EAAA,OAAO,CAAC,GAAG,CAAA;AAQnC,IAAA,CAAC,KAAK,GAAG,CAAA,GAAI,CAAC,GAAA,EAAK,OAAO,UAAW,CAAA,EAAE,CAAE,CAAA,CAAC,CAAC,CAAE,CAAA,IAAA,CAAK,CAAC,CAAG,EAAA,CAAA,KAAM,IAAI,CAAC,CAAA;AAGjE,IAAA,OAAOC,gBAAM,GAAK,EAAA,GAAA,EAAK,SAAS,IAAM,EAAA,EAAE,KAAK,CAAC,CAAA;AAAA;AAEhD,CAAA;AAhIkB,MAAA,CAAA,KAAA,EAAA,MAAA,CAAA;AAAX,IAAM,IAAN,GAAA","file":"index.cjs","sourcesContent":["export enum Time {\n\tNanosecond = 1 / 1_000_000,\n\tMicrosecond = 1 / 1000,\n\tMillisecond = 1,\n\tSecond = 1000,\n\tMinute = Second * 60,\n\tHour = Minute * 60,\n\tDay = Hour * 24,\n\tWeek = Day * 7,\n\tMonth = Day * (365 / 12),\n\tYear = Day * 365\n}\n\nexport const partRegex = /^(?:(\\*)|(\\d+)(?:-(\\d+))?)(?:\\/(\\d+))?$/;\n\nexport const wildcardRegex = /\\bh\\b|\\B\\?\\B/g;\n\nexport const allowedNum = [\n\t[0, 59],\n\t[0, 23],\n\t[1, 31],\n\t[1, 12],\n\t[0, 6]\n];\n\nexport const predefined = {\n\t'@annually': '0 0 1 1 *',\n\t'@yearly': '0 0 1 1 *',\n\t'@monthly': '0 0 1 * *',\n\t'@weekly': '0 0 * * 0',\n\t'@daily': '0 0 * * *',\n\t'@hourly': '0 * * * *'\n} as const;\n\nexport const cronTokens = {\n\tjan: 1,\n\tfeb: 2,\n\tmar: 3,\n\tapr: 4,\n\tmay: 5,\n\tjun: 6,\n\tjul: 7,\n\taug: 8,\n\tsep: 9,\n\toct: 10,\n\tnov: 11,\n\tdec: 12,\n\tsun: 0,\n\tmon: 1,\n\ttue: 2,\n\twed: 3,\n\tthu: 4,\n\tfri: 5,\n\tsat: 6\n} as const;\n\nexport const tokensRegex = new RegExp(Object.keys(cronTokens).join('|'), 'g');\n","import { range } from '@sapphire/utilities';\nimport { allowedNum, cronTokens, partRegex, predefined, Time, tokensRegex, wildcardRegex } from './constants';\n\n/**\n * Handles Cron strings and generates dates based on the cron string provided.\n * @see https://en.wikipedia.org/wiki/Cron\n */\nexport class Cron {\n\tpublic cron: string;\n\tpublic normalized: string;\n\tpublic minutes: number[];\n\tpublic hours: number[];\n\tpublic days: number[];\n\tpublic months: number[];\n\tpublic dows: number[];\n\n\t/**\n\t * @param cron The cron pattern to use\n\t */\n\tpublic constructor(cron: string) {\n\t\tthis.cron = cron.toLowerCase();\n\t\tthis.normalized = Cron.normalize(this.cron);\n\t\t[this.minutes, this.hours, this.days, this.months, this.dows] = Cron.parseString(this.normalized);\n\t}\n\n\t/**\n\t * Get the next date that matches with the current pattern\n\t * @param outset The Date instance to compare with\n\t * @param origin Whether this next call is origin\n\t */\n\tpublic next(outset: Date = new Date(), origin = true): Date {\n\t\tif (!this.days.includes(outset.getUTCDate()) || !this.months.includes(outset.getUTCMonth() + 1) || !this.dows.includes(outset.getUTCDay())) {\n\t\t\treturn this.next(new Date(outset.getTime() + Time.Day), false);\n\t\t}\n\t\tif (!origin) return new Date(Date.UTC(outset.getUTCFullYear(), outset.getUTCMonth(), outset.getUTCDate(), this.hours[0], this.minutes[0]));\n\n\t\tconst now = new Date(outset.getTime() + 60000);\n\n\t\tfor (const hour of this.hours) {\n\t\t\tif (hour < now.getUTCHours()) continue;\n\t\t\tfor (const minute of this.minutes) {\n\t\t\t\tif (hour === now.getUTCHours() && minute < now.getUTCMinutes()) continue;\n\t\t\t\treturn new Date(Date.UTC(outset.getUTCFullYear(), outset.getUTCMonth(), outset.getUTCDate(), hour, minute));\n\t\t\t}\n\t\t}\n\n\t\treturn this.next(new Date(outset.getTime() + Time.Day), false);\n\t}\n\n\t/**\n\t * Returns the string that represents this cron pattern\n\t *\n\t * @returns The string that represents this cron pattern\n\t */\n\tpublic toString() {\n\t\treturn this.cron;\n\t}\n\n\t/**\n\t * Normalize the pattern\n\t * @param cron The pattern to normalize\n\t */\n\tprivate static normalize(cron: string): string {\n\t\tif (Reflect.has(predefined, cron)) return Reflect.get(predefined, cron);\n\t\tconst now = new Date();\n\t\tcron = cron\n\t\t\t.split(' ')\n\t\t\t.map((val, i) =>\n\t\t\t\tval.replace(wildcardRegex, (match) => {\n\t\t\t\t\tif (match === 'h') return (Math.floor(Math.random() * allowedNum[i][1]) + allowedNum[i][0]).toString();\n\n\t\t\t\t\tif (match === '?') {\n\t\t\t\t\t\tswitch (i) {\n\t\t\t\t\t\t\tcase 0:\n\t\t\t\t\t\t\t\treturn now.getUTCMinutes().toString();\n\t\t\t\t\t\t\tcase 1:\n\t\t\t\t\t\t\t\treturn now.getUTCHours().toString();\n\t\t\t\t\t\t\tcase 2:\n\t\t\t\t\t\t\t\treturn now.getUTCDate().toString();\n\t\t\t\t\t\t\tcase 3:\n\t\t\t\t\t\t\t\treturn now.getUTCMonth().toString();\n\t\t\t\t\t\t\tcase 4:\n\t\t\t\t\t\t\t\treturn now.getUTCDay().toString();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\treturn match;\n\t\t\t\t})\n\t\t\t)\n\t\t\t.join(' ');\n\t\treturn cron.replace(tokensRegex, (match) => String(Reflect.get(cronTokens, match)));\n\t}\n\n\t/**\n\t * Parse the pattern\n\t * @param cron The pattern to parse\n\t */\n\tprivate static parseString(cron: string): Array<number[]> {\n\t\tconst parts = cron.split(' ');\n\t\tif (parts.length !== 5) throw new Error('Invalid Cron Provided');\n\t\treturn parts.map((part, i) => Cron.parsePart(part, i));\n\t}\n\n\t/**\n\t * Parse the current part\n\t * @param cronPart The part of the pattern to parse\n\t * @param id The id that identifies the current part\n\t */\n\tprivate static parsePart(cronPart: string, id: number): number[] {\n\t\tif (cronPart.includes(',')) {\n\t\t\tconst res: number[] = [];\n\t\t\tfor (const part of cronPart.split(',')) res.push(...Cron.parsePart(part, id));\n\t\t\treturn [...new Set(res)].sort((a, b) => a - b);\n\t\t}\n\n\t\tconst [, wild, minStr, maxStr, step] = partRegex.exec(cronPart)!;\n\t\tlet [min, max] = [parseInt(minStr, 10), parseInt(maxStr, 10)];\n\n\t\t// If '*', set min and max as the minimum and maximum allowed numbers:\n\t\tif (wild) [min, max] = allowedNum[id];\n\t\t// Else if a number was given, but not a maximum nor a step, return it\n\t\t// as only allowed value:\n\t\telse if (!max && !step) return [min];\n\n\t\t// Set min and max as the given numbers, defaulting max to the maximum\n\t\t// allowed, so min is never bigger than max:\n\t\t// This makes min and max be, in the following cases (considering minutes):\n\t\t// -> 1-2 | 1..2\n\t\t// -> 2-1 | 1..2\n\t\t// -> 1/7 | 1, 8, 15, 22, 29, 36, 43, 50, 57\n\t\t[min, max] = [min, max || allowedNum[id][1]].sort((a, b) => a - b);\n\n\t\t// Generate a range\n\t\treturn range(min, max, parseInt(step, 10) || 1);\n\t}\n}\n"]}
@@ -66,6 +66,12 @@ declare class Cron {
66
66
  * @param origin Whether this next call is origin
67
67
  */
68
68
  next(outset?: Date, origin?: boolean): Date;
69
+ /**
70
+ * Returns the string that represents this cron pattern
71
+ *
72
+ * @returns The string that represents this cron pattern
73
+ */
74
+ toString(): string;
69
75
  /**
70
76
  * Normalize the pattern
71
77
  * @param cron The pattern to normalize
@@ -0,0 +1,93 @@
1
+ declare enum Time {
2
+ Nanosecond = 0.000001,
3
+ Microsecond = 0.001,
4
+ Millisecond = 1,
5
+ Second = 1000,
6
+ Minute = 60000,
7
+ Hour = 3600000,
8
+ Day = 86400000,
9
+ Week = 604800000,
10
+ Month = 2628000000,
11
+ Year = 31536000000
12
+ }
13
+ declare const partRegex: RegExp;
14
+ declare const wildcardRegex: RegExp;
15
+ declare const allowedNum: number[][];
16
+ declare const predefined: {
17
+ readonly '@annually': "0 0 1 1 *";
18
+ readonly '@yearly': "0 0 1 1 *";
19
+ readonly '@monthly': "0 0 1 * *";
20
+ readonly '@weekly': "0 0 * * 0";
21
+ readonly '@daily': "0 0 * * *";
22
+ readonly '@hourly': "0 * * * *";
23
+ };
24
+ declare const cronTokens: {
25
+ readonly jan: 1;
26
+ readonly feb: 2;
27
+ readonly mar: 3;
28
+ readonly apr: 4;
29
+ readonly may: 5;
30
+ readonly jun: 6;
31
+ readonly jul: 7;
32
+ readonly aug: 8;
33
+ readonly sep: 9;
34
+ readonly oct: 10;
35
+ readonly nov: 11;
36
+ readonly dec: 12;
37
+ readonly sun: 0;
38
+ readonly mon: 1;
39
+ readonly tue: 2;
40
+ readonly wed: 3;
41
+ readonly thu: 4;
42
+ readonly fri: 5;
43
+ readonly sat: 6;
44
+ };
45
+ declare const tokensRegex: RegExp;
46
+
47
+ /**
48
+ * Handles Cron strings and generates dates based on the cron string provided.
49
+ * @see https://en.wikipedia.org/wiki/Cron
50
+ */
51
+ declare class Cron {
52
+ cron: string;
53
+ normalized: string;
54
+ minutes: number[];
55
+ hours: number[];
56
+ days: number[];
57
+ months: number[];
58
+ dows: number[];
59
+ /**
60
+ * @param cron The cron pattern to use
61
+ */
62
+ constructor(cron: string);
63
+ /**
64
+ * Get the next date that matches with the current pattern
65
+ * @param outset The Date instance to compare with
66
+ * @param origin Whether this next call is origin
67
+ */
68
+ next(outset?: Date, origin?: boolean): Date;
69
+ /**
70
+ * Returns the string that represents this cron pattern
71
+ *
72
+ * @returns The string that represents this cron pattern
73
+ */
74
+ toString(): string;
75
+ /**
76
+ * Normalize the pattern
77
+ * @param cron The pattern to normalize
78
+ */
79
+ private static normalize;
80
+ /**
81
+ * Parse the pattern
82
+ * @param cron The pattern to parse
83
+ */
84
+ private static parseString;
85
+ /**
86
+ * Parse the current part
87
+ * @param cronPart The part of the pattern to parse
88
+ * @param id The id that identifies the current part
89
+ */
90
+ private static parsePart;
91
+ }
92
+
93
+ export { Cron, Time, allowedNum, cronTokens, partRegex, predefined, tokensRegex, wildcardRegex };
@@ -3,10 +3,7 @@ import { range } from '@sapphire/utilities';
3
3
  var __defProp = Object.defineProperty;
4
4
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5
5
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
- var __publicField = (obj, key, value) => {
7
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
8
- return value;
9
- };
6
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
10
7
 
11
8
  // src/lib/constants.ts
12
9
  var Time = /* @__PURE__ */ ((Time2) => {
@@ -61,7 +58,7 @@ var cronTokens = {
61
58
  sat: 6
62
59
  };
63
60
  var tokensRegex = new RegExp(Object.keys(cronTokens).join("|"), "g");
64
- var Cron = class {
61
+ var _Cron = class _Cron {
65
62
  /**
66
63
  * @param cron The cron pattern to use
67
64
  */
@@ -74,8 +71,8 @@ var Cron = class {
74
71
  __publicField(this, "months");
75
72
  __publicField(this, "dows");
76
73
  this.cron = cron.toLowerCase();
77
- this.normalized = Cron.normalize(this.cron);
78
- [this.minutes, this.hours, this.days, this.months, this.dows] = Cron.parseString(this.normalized);
74
+ this.normalized = _Cron.normalize(this.cron);
75
+ [this.minutes, this.hours, this.days, this.months, this.dows] = _Cron.parseString(this.normalized);
79
76
  }
80
77
  /**
81
78
  * Get the next date that matches with the current pattern
@@ -86,32 +83,35 @@ var Cron = class {
86
83
  if (!this.days.includes(outset.getUTCDate()) || !this.months.includes(outset.getUTCMonth() + 1) || !this.dows.includes(outset.getUTCDay())) {
87
84
  return this.next(new Date(outset.getTime() + 864e5 /* Day */), false);
88
85
  }
89
- if (!origin)
90
- return new Date(Date.UTC(outset.getUTCFullYear(), outset.getUTCMonth(), outset.getUTCDate(), this.hours[0], this.minutes[0]));
86
+ if (!origin) return new Date(Date.UTC(outset.getUTCFullYear(), outset.getUTCMonth(), outset.getUTCDate(), this.hours[0], this.minutes[0]));
91
87
  const now = new Date(outset.getTime() + 6e4);
92
88
  for (const hour of this.hours) {
93
- if (hour < now.getUTCHours())
94
- continue;
89
+ if (hour < now.getUTCHours()) continue;
95
90
  for (const minute of this.minutes) {
96
- if (hour === now.getUTCHours() && minute < now.getUTCMinutes())
97
- continue;
91
+ if (hour === now.getUTCHours() && minute < now.getUTCMinutes()) continue;
98
92
  return new Date(Date.UTC(outset.getUTCFullYear(), outset.getUTCMonth(), outset.getUTCDate(), hour, minute));
99
93
  }
100
94
  }
101
95
  return this.next(new Date(outset.getTime() + 864e5 /* Day */), false);
102
96
  }
97
+ /**
98
+ * Returns the string that represents this cron pattern
99
+ *
100
+ * @returns The string that represents this cron pattern
101
+ */
102
+ toString() {
103
+ return this.cron;
104
+ }
103
105
  /**
104
106
  * Normalize the pattern
105
107
  * @param cron The pattern to normalize
106
108
  */
107
109
  static normalize(cron) {
108
- if (Reflect.has(predefined, cron))
109
- return Reflect.get(predefined, cron);
110
+ if (Reflect.has(predefined, cron)) return Reflect.get(predefined, cron);
110
111
  const now = /* @__PURE__ */ new Date();
111
112
  cron = cron.split(" ").map(
112
113
  (val, i) => val.replace(wildcardRegex, (match) => {
113
- if (match === "h")
114
- return (Math.floor(Math.random() * allowedNum[i][1]) + allowedNum[i][0]).toString();
114
+ if (match === "h") return (Math.floor(Math.random() * allowedNum[i][1]) + allowedNum[i][0]).toString();
115
115
  if (match === "?") {
116
116
  switch (i) {
117
117
  case 0:
@@ -137,9 +137,8 @@ var Cron = class {
137
137
  */
138
138
  static parseString(cron) {
139
139
  const parts = cron.split(" ");
140
- if (parts.length !== 5)
141
- throw new Error("Invalid Cron Provided");
142
- return parts.map((part, i) => Cron.parsePart(part, i));
140
+ if (parts.length !== 5) throw new Error("Invalid Cron Provided");
141
+ return parts.map((part, i) => _Cron.parsePart(part, i));
143
142
  }
144
143
  /**
145
144
  * Parse the current part
@@ -149,22 +148,20 @@ var Cron = class {
149
148
  static parsePart(cronPart, id) {
150
149
  if (cronPart.includes(",")) {
151
150
  const res = [];
152
- for (const part of cronPart.split(","))
153
- res.push(...Cron.parsePart(part, id));
151
+ for (const part of cronPart.split(",")) res.push(..._Cron.parsePart(part, id));
154
152
  return [...new Set(res)].sort((a, b) => a - b);
155
153
  }
156
154
  const [, wild, minStr, maxStr, step] = partRegex.exec(cronPart);
157
155
  let [min, max] = [parseInt(minStr, 10), parseInt(maxStr, 10)];
158
- if (wild)
159
- [min, max] = allowedNum[id];
160
- else if (!max && !step)
161
- return [min];
156
+ if (wild) [min, max] = allowedNum[id];
157
+ else if (!max && !step) return [min];
162
158
  [min, max] = [min, max || allowedNum[id][1]].sort((a, b) => a - b);
163
159
  return range(min, max, parseInt(step, 10) || 1);
164
160
  }
165
161
  };
166
- __name(Cron, "Cron");
162
+ __name(_Cron, "Cron");
163
+ var Cron = _Cron;
167
164
 
168
165
  export { Cron, Time, allowedNum, cronTokens, partRegex, predefined, tokensRegex, wildcardRegex };
169
- //# sourceMappingURL=out.js.map
166
+ //# sourceMappingURL=index.mjs.map
170
167
  //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/lib/constants.ts","../../src/lib/Cron.ts"],"names":["Time"],"mappings":";;;;;;;;AAAY,IAAA,IAAA,qBAAAA,KAAL,KAAA;AACN,EAAAA,KAAAA,C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AAA,CAAA,GAAI,CAAC,CAAA;AAAA;AAG9C,IAAM,MAAA,GAAG,IAAM,EAAA,MAAA,EAAQ,QAAQ,IAAI,CAAA,GAAI,SAAU,CAAA,IAAA,CAAK,QAAQ,CAAA;AAC9D,IAAA,IAAI,CAAC,GAAA,EAAK,GAAG,CAAA,GAAI,CAAC,QAAA,CAAS,MAAQ,EAAA,EAAE,CAAG,EAAA,QAAA,CAAS,MAAQ,EAAA,EAAE,CAAC,CAAA;AAG5D,IAAA,IAAI,MAAO,CAAA,GAAA,EAAK,GAAG,CAAA,GAAI,WAAW,EAAE,CAAA;AAAA,SAAA,IAG3B,CAAC,GAAO,IAAA,CAAC,IAAM,EAAA,OAAO,CAAC,GAAG,CAAA;AAQnC,IAAA,CAAC,KAAK,GAAG,CAAA,GAAI,CAAC,GAAA,EAAK,OAAO,UAAW,CAAA,EAAE,CAAE,CAAA,CAAC,CAAC,CAAE,CAAA,IAAA,CAAK,CAAC,CAAG,EAAA,CAAA,KAAM,IAAI,CAAC,CAAA;AAGjE,IAAA,OAAO,MAAM,GAAK,EAAA,GAAA,EAAK,SAAS,IAAM,EAAA,EAAE,KAAK,CAAC,CAAA;AAAA;AAEhD,CAAA;AAhIkB,MAAA,CAAA,KAAA,EAAA,MAAA,CAAA;AAAX,IAAM,IAAN,GAAA","file":"index.mjs","sourcesContent":["export enum Time {\n\tNanosecond = 1 / 1_000_000,\n\tMicrosecond = 1 / 1000,\n\tMillisecond = 1,\n\tSecond = 1000,\n\tMinute = Second * 60,\n\tHour = Minute * 60,\n\tDay = Hour * 24,\n\tWeek = Day * 7,\n\tMonth = Day * (365 / 12),\n\tYear = Day * 365\n}\n\nexport const partRegex = /^(?:(\\*)|(\\d+)(?:-(\\d+))?)(?:\\/(\\d+))?$/;\n\nexport const wildcardRegex = /\\bh\\b|\\B\\?\\B/g;\n\nexport const allowedNum = [\n\t[0, 59],\n\t[0, 23],\n\t[1, 31],\n\t[1, 12],\n\t[0, 6]\n];\n\nexport const predefined = {\n\t'@annually': '0 0 1 1 *',\n\t'@yearly': '0 0 1 1 *',\n\t'@monthly': '0 0 1 * *',\n\t'@weekly': '0 0 * * 0',\n\t'@daily': '0 0 * * *',\n\t'@hourly': '0 * * * *'\n} as const;\n\nexport const cronTokens = {\n\tjan: 1,\n\tfeb: 2,\n\tmar: 3,\n\tapr: 4,\n\tmay: 5,\n\tjun: 6,\n\tjul: 7,\n\taug: 8,\n\tsep: 9,\n\toct: 10,\n\tnov: 11,\n\tdec: 12,\n\tsun: 0,\n\tmon: 1,\n\ttue: 2,\n\twed: 3,\n\tthu: 4,\n\tfri: 5,\n\tsat: 6\n} as const;\n\nexport const tokensRegex = new RegExp(Object.keys(cronTokens).join('|'), 'g');\n","import { range } from '@sapphire/utilities';\nimport { allowedNum, cronTokens, partRegex, predefined, Time, tokensRegex, wildcardRegex } from './constants';\n\n/**\n * Handles Cron strings and generates dates based on the cron string provided.\n * @see https://en.wikipedia.org/wiki/Cron\n */\nexport class Cron {\n\tpublic cron: string;\n\tpublic normalized: string;\n\tpublic minutes: number[];\n\tpublic hours: number[];\n\tpublic days: number[];\n\tpublic months: number[];\n\tpublic dows: number[];\n\n\t/**\n\t * @param cron The cron pattern to use\n\t */\n\tpublic constructor(cron: string) {\n\t\tthis.cron = cron.toLowerCase();\n\t\tthis.normalized = Cron.normalize(this.cron);\n\t\t[this.minutes, this.hours, this.days, this.months, this.dows] = Cron.parseString(this.normalized);\n\t}\n\n\t/**\n\t * Get the next date that matches with the current pattern\n\t * @param outset The Date instance to compare with\n\t * @param origin Whether this next call is origin\n\t */\n\tpublic next(outset: Date = new Date(), origin = true): Date {\n\t\tif (!this.days.includes(outset.getUTCDate()) || !this.months.includes(outset.getUTCMonth() + 1) || !this.dows.includes(outset.getUTCDay())) {\n\t\t\treturn this.next(new Date(outset.getTime() + Time.Day), false);\n\t\t}\n\t\tif (!origin) return new Date(Date.UTC(outset.getUTCFullYear(), outset.getUTCMonth(), outset.getUTCDate(), this.hours[0], this.minutes[0]));\n\n\t\tconst now = new Date(outset.getTime() + 60000);\n\n\t\tfor (const hour of this.hours) {\n\t\t\tif (hour < now.getUTCHours()) continue;\n\t\t\tfor (const minute of this.minutes) {\n\t\t\t\tif (hour === now.getUTCHours() && minute < now.getUTCMinutes()) continue;\n\t\t\t\treturn new Date(Date.UTC(outset.getUTCFullYear(), outset.getUTCMonth(), outset.getUTCDate(), hour, minute));\n\t\t\t}\n\t\t}\n\n\t\treturn this.next(new Date(outset.getTime() + Time.Day), false);\n\t}\n\n\t/**\n\t * Returns the string that represents this cron pattern\n\t *\n\t * @returns The string that represents this cron pattern\n\t */\n\tpublic toString() {\n\t\treturn this.cron;\n\t}\n\n\t/**\n\t * Normalize the pattern\n\t * @param cron The pattern to normalize\n\t */\n\tprivate static normalize(cron: string): string {\n\t\tif (Reflect.has(predefined, cron)) return Reflect.get(predefined, cron);\n\t\tconst now = new Date();\n\t\tcron = cron\n\t\t\t.split(' ')\n\t\t\t.map((val, i) =>\n\t\t\t\tval.replace(wildcardRegex, (match) => {\n\t\t\t\t\tif (match === 'h') return (Math.floor(Math.random() * allowedNum[i][1]) + allowedNum[i][0]).toString();\n\n\t\t\t\t\tif (match === '?') {\n\t\t\t\t\t\tswitch (i) {\n\t\t\t\t\t\t\tcase 0:\n\t\t\t\t\t\t\t\treturn now.getUTCMinutes().toString();\n\t\t\t\t\t\t\tcase 1:\n\t\t\t\t\t\t\t\treturn now.getUTCHours().toString();\n\t\t\t\t\t\t\tcase 2:\n\t\t\t\t\t\t\t\treturn now.getUTCDate().toString();\n\t\t\t\t\t\t\tcase 3:\n\t\t\t\t\t\t\t\treturn now.getUTCMonth().toString();\n\t\t\t\t\t\t\tcase 4:\n\t\t\t\t\t\t\t\treturn now.getUTCDay().toString();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\treturn match;\n\t\t\t\t})\n\t\t\t)\n\t\t\t.join(' ');\n\t\treturn cron.replace(tokensRegex, (match) => String(Reflect.get(cronTokens, match)));\n\t}\n\n\t/**\n\t * Parse the pattern\n\t * @param cron The pattern to parse\n\t */\n\tprivate static parseString(cron: string): Array<number[]> {\n\t\tconst parts = cron.split(' ');\n\t\tif (parts.length !== 5) throw new Error('Invalid Cron Provided');\n\t\treturn parts.map((part, i) => Cron.parsePart(part, i));\n\t}\n\n\t/**\n\t * Parse the current part\n\t * @param cronPart The part of the pattern to parse\n\t * @param id The id that identifies the current part\n\t */\n\tprivate static parsePart(cronPart: string, id: number): number[] {\n\t\tif (cronPart.includes(',')) {\n\t\t\tconst res: number[] = [];\n\t\t\tfor (const part of cronPart.split(',')) res.push(...Cron.parsePart(part, id));\n\t\t\treturn [...new Set(res)].sort((a, b) => a - b);\n\t\t}\n\n\t\tconst [, wild, minStr, maxStr, step] = partRegex.exec(cronPart)!;\n\t\tlet [min, max] = [parseInt(minStr, 10), parseInt(maxStr, 10)];\n\n\t\t// If '*', set min and max as the minimum and maximum allowed numbers:\n\t\tif (wild) [min, max] = allowedNum[id];\n\t\t// Else if a number was given, but not a maximum nor a step, return it\n\t\t// as only allowed value:\n\t\telse if (!max && !step) return [min];\n\n\t\t// Set min and max as the given numbers, defaulting max to the maximum\n\t\t// allowed, so min is never bigger than max:\n\t\t// This makes min and max be, in the following cases (considering minutes):\n\t\t// -> 1-2 | 1..2\n\t\t// -> 2-1 | 1..2\n\t\t// -> 1/7 | 1, 8, 15, 22, 29, 36, 43, 50, 57\n\t\t[min, max] = [min, max || allowedNum[id][1]].sort((a, b) => a - b);\n\n\t\t// Generate a range\n\t\treturn range(min, max, parseInt(step, 10) || 1);\n\t}\n}\n"]}
@@ -4,10 +4,7 @@ var SapphireCron = (function (exports) {
4
4
  var __defProp = Object.defineProperty;
5
5
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
6
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
- var __publicField = (obj, key, value) => {
8
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
9
- return value;
10
- };
7
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
11
8
 
12
9
  // src/lib/constants.ts
13
10
  var Time = /* @__PURE__ */ ((Time2) => {
@@ -63,11 +60,11 @@ var SapphireCron = (function (exports) {
63
60
  };
64
61
  var tokensRegex = new RegExp(Object.keys(cronTokens).join("|"), "g");
65
62
 
66
- // ../utilities/dist/chunk-AZHX2MBF.mjs
63
+ // ../utilities/dist/esm/chunk-PAWJFY3S.mjs
67
64
  var __defProp2 = Object.defineProperty;
68
65
  var __name2 = /* @__PURE__ */ __name((target, value) => __defProp2(target, "name", { value, configurable: true }), "__name");
69
66
 
70
- // ../utilities/dist/lib/range.mjs
67
+ // ../utilities/dist/esm/lib/range.mjs
71
68
  function range(min, max, step) {
72
69
  return new Array(Math.floor((max - min) / step) + 1).fill(0).map((_val, i) => min + i * step);
73
70
  }
@@ -75,7 +72,7 @@ var SapphireCron = (function (exports) {
75
72
  __name2(range, "range");
76
73
 
77
74
  // src/lib/Cron.ts
78
- var Cron = class {
75
+ var _Cron = class _Cron {
79
76
  /**
80
77
  * @param cron The cron pattern to use
81
78
  */
@@ -88,8 +85,8 @@ var SapphireCron = (function (exports) {
88
85
  __publicField(this, "months");
89
86
  __publicField(this, "dows");
90
87
  this.cron = cron.toLowerCase();
91
- this.normalized = Cron.normalize(this.cron);
92
- [this.minutes, this.hours, this.days, this.months, this.dows] = Cron.parseString(this.normalized);
88
+ this.normalized = _Cron.normalize(this.cron);
89
+ [this.minutes, this.hours, this.days, this.months, this.dows] = _Cron.parseString(this.normalized);
93
90
  }
94
91
  /**
95
92
  * Get the next date that matches with the current pattern
@@ -100,32 +97,35 @@ var SapphireCron = (function (exports) {
100
97
  if (!this.days.includes(outset.getUTCDate()) || !this.months.includes(outset.getUTCMonth() + 1) || !this.dows.includes(outset.getUTCDay())) {
101
98
  return this.next(new Date(outset.getTime() + 864e5 /* Day */), false);
102
99
  }
103
- if (!origin)
104
- return new Date(Date.UTC(outset.getUTCFullYear(), outset.getUTCMonth(), outset.getUTCDate(), this.hours[0], this.minutes[0]));
100
+ if (!origin) return new Date(Date.UTC(outset.getUTCFullYear(), outset.getUTCMonth(), outset.getUTCDate(), this.hours[0], this.minutes[0]));
105
101
  const now = new Date(outset.getTime() + 6e4);
106
102
  for (const hour of this.hours) {
107
- if (hour < now.getUTCHours())
108
- continue;
103
+ if (hour < now.getUTCHours()) continue;
109
104
  for (const minute of this.minutes) {
110
- if (hour === now.getUTCHours() && minute < now.getUTCMinutes())
111
- continue;
105
+ if (hour === now.getUTCHours() && minute < now.getUTCMinutes()) continue;
112
106
  return new Date(Date.UTC(outset.getUTCFullYear(), outset.getUTCMonth(), outset.getUTCDate(), hour, minute));
113
107
  }
114
108
  }
115
109
  return this.next(new Date(outset.getTime() + 864e5 /* Day */), false);
116
110
  }
111
+ /**
112
+ * Returns the string that represents this cron pattern
113
+ *
114
+ * @returns The string that represents this cron pattern
115
+ */
116
+ toString() {
117
+ return this.cron;
118
+ }
117
119
  /**
118
120
  * Normalize the pattern
119
121
  * @param cron The pattern to normalize
120
122
  */
121
123
  static normalize(cron) {
122
- if (Reflect.has(predefined, cron))
123
- return Reflect.get(predefined, cron);
124
+ if (Reflect.has(predefined, cron)) return Reflect.get(predefined, cron);
124
125
  const now = /* @__PURE__ */ new Date();
125
126
  cron = cron.split(" ").map(
126
127
  (val, i) => val.replace(wildcardRegex, (match) => {
127
- if (match === "h")
128
- return (Math.floor(Math.random() * allowedNum[i][1]) + allowedNum[i][0]).toString();
128
+ if (match === "h") return (Math.floor(Math.random() * allowedNum[i][1]) + allowedNum[i][0]).toString();
129
129
  if (match === "?") {
130
130
  switch (i) {
131
131
  case 0:
@@ -151,9 +151,8 @@ var SapphireCron = (function (exports) {
151
151
  */
152
152
  static parseString(cron) {
153
153
  const parts = cron.split(" ");
154
- if (parts.length !== 5)
155
- throw new Error("Invalid Cron Provided");
156
- return parts.map((part, i) => Cron.parsePart(part, i));
154
+ if (parts.length !== 5) throw new Error("Invalid Cron Provided");
155
+ return parts.map((part, i) => _Cron.parsePart(part, i));
157
156
  }
158
157
  /**
159
158
  * Parse the current part
@@ -163,21 +162,19 @@ var SapphireCron = (function (exports) {
163
162
  static parsePart(cronPart, id) {
164
163
  if (cronPart.includes(",")) {
165
164
  const res = [];
166
- for (const part of cronPart.split(","))
167
- res.push(...Cron.parsePart(part, id));
165
+ for (const part of cronPart.split(",")) res.push(..._Cron.parsePart(part, id));
168
166
  return [...new Set(res)].sort((a, b) => a - b);
169
167
  }
170
168
  const [, wild, minStr, maxStr, step] = partRegex.exec(cronPart);
171
169
  let [min, max] = [parseInt(minStr, 10), parseInt(maxStr, 10)];
172
- if (wild)
173
- [min, max] = allowedNum[id];
174
- else if (!max && !step)
175
- return [min];
170
+ if (wild) [min, max] = allowedNum[id];
171
+ else if (!max && !step) return [min];
176
172
  [min, max] = [min, max || allowedNum[id][1]].sort((a, b) => a - b);
177
173
  return range(min, max, parseInt(step, 10) || 1);
178
174
  }
179
175
  };
180
- __name(Cron, "Cron");
176
+ __name(_Cron, "Cron");
177
+ var Cron = _Cron;
181
178
 
182
179
  exports.Cron = Cron;
183
180
  exports.Time = Time;
@@ -191,5 +188,5 @@ var SapphireCron = (function (exports) {
191
188
  return exports;
192
189
 
193
190
  })({});
194
- //# sourceMappingURL=out.js.map
191
+ //# sourceMappingURL=index.global.js.map
195
192
  //# sourceMappingURL=index.global.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/lib/constants.ts","../../../utilities/dist/esm/chunk-PAWJFY3S.mjs","../../../utilities/src/lib/range.ts","../../src/lib/Cron.ts"],"names":["Time","__defProp","__name"],"mappings":";;;;;;;;;AAAY,MAAA,IAAA,qBAAAA,KAAL,KAAA;EACN,EAAAA,KAAAA,CAAAA,KAAAA,CAAA,gBAAa,IAAb,CAAA,GAAA,YAAA;EACA,EAAAA,KAAAA,CAAAA,KAAAA,CAAA,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kB,MAAA,CAAA,KAAA,EAAA,MAAA,CAAA;AAAX,MAAM,IAAN,GAAA","file":"index.global.js","sourcesContent":["export enum Time {\n\tNanosecond = 1 / 1_000_000,\n\tMicrosecond = 1 / 1000,\n\tMillisecond = 1,\n\tSecond = 1000,\n\tMinute = Second * 60,\n\tHour = Minute * 60,\n\tDay = Hour * 24,\n\tWeek = Day * 7,\n\tMonth = Day * (365 / 12),\n\tYear = Day * 365\n}\n\nexport const partRegex = /^(?:(\\*)|(\\d+)(?:-(\\d+))?)(?:\\/(\\d+))?$/;\n\nexport const wildcardRegex = /\\bh\\b|\\B\\?\\B/g;\n\nexport const allowedNum = [\n\t[0, 59],\n\t[0, 23],\n\t[1, 31],\n\t[1, 12],\n\t[0, 6]\n];\n\nexport const predefined = {\n\t'@annually': '0 0 1 1 *',\n\t'@yearly': '0 0 1 1 *',\n\t'@monthly': '0 0 1 * *',\n\t'@weekly': '0 0 * * 0',\n\t'@daily': '0 0 * * *',\n\t'@hourly': '0 * * * *'\n} as const;\n\nexport const cronTokens = {\n\tjan: 1,\n\tfeb: 2,\n\tmar: 3,\n\tapr: 4,\n\tmay: 5,\n\tjun: 6,\n\tjul: 7,\n\taug: 8,\n\tsep: 9,\n\toct: 10,\n\tnov: 11,\n\tdec: 12,\n\tsun: 0,\n\tmon: 1,\n\ttue: 2,\n\twed: 3,\n\tthu: 4,\n\tfri: 5,\n\tsat: 6\n} as const;\n\nexport const tokensRegex = new RegExp(Object.keys(cronTokens).join('|'), 'g');\n","var __defProp = Object.defineProperty;\nvar __name = (target, value) => __defProp(target, \"name\", { value, configurable: true });\n\nexport { __name };\n//# sourceMappingURL=chunk-PAWJFY3S.mjs.map\n//# sourceMappingURL=chunk-PAWJFY3S.mjs.map","/**\n * Get an array of numbers with the selected range\n * @param min The minimum value\n * @param max The maximum value\n * @param step The step value\n */\nexport function range(min: number, max: number, step: number): number[] {\n\treturn new Array(Math.floor((max - min) / step) + 1).fill(0).map((_val, i) => min + i * step);\n}\n","import { range } from '@sapphire/utilities';\nimport { allowedNum, cronTokens, partRegex, predefined, Time, tokensRegex, wildcardRegex } from './constants';\n\n/**\n * Handles Cron strings and generates dates based on the cron string provided.\n * @see https://en.wikipedia.org/wiki/Cron\n */\nexport class Cron {\n\tpublic cron: string;\n\tpublic normalized: string;\n\tpublic minutes: number[];\n\tpublic hours: number[];\n\tpublic days: number[];\n\tpublic months: number[];\n\tpublic dows: number[];\n\n\t/**\n\t * @param cron The cron pattern to use\n\t */\n\tpublic constructor(cron: string) {\n\t\tthis.cron = cron.toLowerCase();\n\t\tthis.normalized = Cron.normalize(this.cron);\n\t\t[this.minutes, this.hours, this.days, this.months, this.dows] = Cron.parseString(this.normalized);\n\t}\n\n\t/**\n\t * Get the next date that matches with the current pattern\n\t * @param outset The Date instance to compare with\n\t * @param origin Whether this next call is origin\n\t */\n\tpublic next(outset: Date = new Date(), origin = true): Date {\n\t\tif (!this.days.includes(outset.getUTCDate()) || !this.months.includes(outset.getUTCMonth() + 1) || !this.dows.includes(outset.getUTCDay())) {\n\t\t\treturn this.next(new Date(outset.getTime() + Time.Day), false);\n\t\t}\n\t\tif (!origin) return new Date(Date.UTC(outset.getUTCFullYear(), outset.getUTCMonth(), outset.getUTCDate(), this.hours[0], this.minutes[0]));\n\n\t\tconst now = new Date(outset.getTime() + 60000);\n\n\t\tfor (const hour of this.hours) {\n\t\t\tif (hour < now.getUTCHours()) continue;\n\t\t\tfor (const minute of this.minutes) {\n\t\t\t\tif (hour === now.getUTCHours() && minute < now.getUTCMinutes()) continue;\n\t\t\t\treturn new Date(Date.UTC(outset.getUTCFullYear(), outset.getUTCMonth(), outset.getUTCDate(), hour, minute));\n\t\t\t}\n\t\t}\n\n\t\treturn this.next(new Date(outset.getTime() + Time.Day), false);\n\t}\n\n\t/**\n\t * Returns the string that represents this cron pattern\n\t *\n\t * @returns The string that represents this cron pattern\n\t */\n\tpublic toString() {\n\t\treturn this.cron;\n\t}\n\n\t/**\n\t * Normalize the pattern\n\t * @param cron The pattern to normalize\n\t */\n\tprivate static normalize(cron: string): string {\n\t\tif (Reflect.has(predefined, cron)) return Reflect.get(predefined, cron);\n\t\tconst now = new Date();\n\t\tcron = cron\n\t\t\t.split(' ')\n\t\t\t.map((val, i) =>\n\t\t\t\tval.replace(wildcardRegex, (match) => {\n\t\t\t\t\tif (match === 'h') return (Math.floor(Math.random() * allowedNum[i][1]) + allowedNum[i][0]).toString();\n\n\t\t\t\t\tif (match === '?') {\n\t\t\t\t\t\tswitch (i) {\n\t\t\t\t\t\t\tcase 0:\n\t\t\t\t\t\t\t\treturn now.getUTCMinutes().toString();\n\t\t\t\t\t\t\tcase 1:\n\t\t\t\t\t\t\t\treturn now.getUTCHours().toString();\n\t\t\t\t\t\t\tcase 2:\n\t\t\t\t\t\t\t\treturn now.getUTCDate().toString();\n\t\t\t\t\t\t\tcase 3:\n\t\t\t\t\t\t\t\treturn now.getUTCMonth().toString();\n\t\t\t\t\t\t\tcase 4:\n\t\t\t\t\t\t\t\treturn now.getUTCDay().toString();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\treturn match;\n\t\t\t\t})\n\t\t\t)\n\t\t\t.join(' ');\n\t\treturn cron.replace(tokensRegex, (match) => String(Reflect.get(cronTokens, match)));\n\t}\n\n\t/**\n\t * Parse the pattern\n\t * @param cron The pattern to parse\n\t */\n\tprivate static parseString(cron: string): Array<number[]> {\n\t\tconst parts = cron.split(' ');\n\t\tif (parts.length !== 5) throw new Error('Invalid Cron Provided');\n\t\treturn parts.map((part, i) => Cron.parsePart(part, i));\n\t}\n\n\t/**\n\t * Parse the current part\n\t * @param cronPart The part of the pattern to parse\n\t * @param id The id that identifies the current part\n\t */\n\tprivate static parsePart(cronPart: string, id: number): number[] {\n\t\tif (cronPart.includes(',')) {\n\t\t\tconst res: number[] = [];\n\t\t\tfor (const part of cronPart.split(',')) res.push(...Cron.parsePart(part, id));\n\t\t\treturn [...new Set(res)].sort((a, b) => a - b);\n\t\t}\n\n\t\tconst [, wild, minStr, maxStr, step] = partRegex.exec(cronPart)!;\n\t\tlet [min, max] = [parseInt(minStr, 10), parseInt(maxStr, 10)];\n\n\t\t// If '*', set min and max as the minimum and maximum allowed numbers:\n\t\tif (wild) [min, max] = allowedNum[id];\n\t\t// Else if a number was given, but not a maximum nor a step, return it\n\t\t// as only allowed value:\n\t\telse if (!max && !step) return [min];\n\n\t\t// Set min and max as the given numbers, defaulting max to the maximum\n\t\t// allowed, so min is never bigger than max:\n\t\t// This makes min and max be, in the following cases (considering minutes):\n\t\t// -> 1-2 | 1..2\n\t\t// -> 2-1 | 1..2\n\t\t// -> 1/7 | 1, 8, 15, 22, 29, 36, 43, 50, 57\n\t\t[min, max] = [min, max || allowedNum[id][1]].sort((a, b) => a - b);\n\n\t\t// Generate a range\n\t\treturn range(min, max, parseInt(step, 10) || 1);\n\t}\n}\n"]}
package/package.json CHANGED
@@ -1,29 +1,37 @@
1
1
  {
2
2
  "name": "@sapphire/cron",
3
- "version": "1.2.0-pr-601.2f2c308a.0",
3
+ "version": "1.2.1-next.624d18f9",
4
4
  "description": "A cron utility library for JavaScript.",
5
5
  "author": "@sapphire",
6
6
  "license": "MIT",
7
- "main": "dist/index.js",
8
- "module": "dist/index.mjs",
9
- "browser": "dist/index.global.js",
10
- "unpkg": "dist/index.global.js",
11
- "types": "dist/index.d.ts",
7
+ "main": "dist/cjs/index.cjs",
8
+ "module": "dist/esm/index.mjs",
9
+ "browser": "dist/iife/index.global.js",
10
+ "unpkg": "dist/iife/index.global.js",
11
+ "types": "dist/cjs/index.d.cts",
12
12
  "exports": {
13
- "import": "./dist/index.mjs",
14
- "require": "./dist/index.js",
15
- "types": "./dist/index.d.ts"
13
+ "browser": "./dist/iife/index.global.js",
14
+ "import": {
15
+ "types": "./dist/esm/index.d.mts",
16
+ "default": "./dist/esm/index.mjs"
17
+ },
18
+ "require": {
19
+ "types": "./dist/cjs/index.d.cts",
20
+ "default": "./dist/cjs/index.cjs"
21
+ }
16
22
  },
17
23
  "sideEffects": false,
18
24
  "homepage": "https://github.com/sapphiredev/utilities/tree/main/packages/cron",
19
25
  "scripts": {
20
26
  "test": "vitest run",
21
27
  "lint": "eslint src tests --ext ts --fix -c ../../.eslintrc",
22
- "build": "tsup",
28
+ "build": "yarn gen-index && tsup && yarn build:rename-cjs-index",
29
+ "build:rename-cjs-index": "tsx ../../scripts/rename-cjs-index.cts",
23
30
  "docs": "typedoc-json-parser",
24
31
  "prepack": "yarn build",
25
32
  "bump": "cliff-jumper",
26
- "check-update": "cliff-jumper --dry-run"
33
+ "check-update": "cliff-jumper --dry-run",
34
+ "gen-index": "tsx ../../scripts/gen-index.cts cron --write"
27
35
  },
28
36
  "repository": {
29
37
  "type": "git",
@@ -31,9 +39,7 @@
31
39
  "directory": "packages/cron"
32
40
  },
33
41
  "files": [
34
- "dist/**/*.js*",
35
- "dist/**/*.mjs*",
36
- "dist/**/*.d*"
42
+ "dist/"
37
43
  ],
38
44
  "engines": {
39
45
  "node": ">=v14.0.0",
@@ -57,15 +63,16 @@
57
63
  "access": "public"
58
64
  },
59
65
  "dependencies": {
60
- "@sapphire/utilities": "^3.11.2"
66
+ "@sapphire/utilities": "^3.18.0"
61
67
  },
62
68
  "devDependencies": {
63
- "@favware/cliff-jumper": "^2.0.1",
64
- "@vitest/coverage-c8": "^0.31.1",
65
- "tsup": "^6.7.0",
66
- "typedoc": "^0.24.7",
67
- "typedoc-json-parser": "^8.1.2",
68
- "typescript": "^5.0.4",
69
- "vitest": "^0.31.1"
69
+ "@favware/cliff-jumper": "^5.0.0",
70
+ "@vitest/coverage-v8": "^2.1.4",
71
+ "tsup": "^8.3.5",
72
+ "tsx": "^4.19.2",
73
+ "typedoc": "^0.25.13",
74
+ "typedoc-json-parser": "^10.1.6",
75
+ "typescript": "~5.4.5",
76
+ "vitest": "^2.1.4"
70
77
  }
71
78
  }
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/lib/constants.ts","../../utilities/dist/chunk-AZHX2MBF.m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AAI,CAAC,MAAM,MAAM,KAAK,UAAU,MAAM,CAAC,CAAC;AAAA,EACtD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,OAAe,UAAU,UAAkB,IAAsB;AAChE,QAAI,SAAS,SAAS,GAAG,GAAG;AAC3B,YAAM,MAAgB,CAAC;AACvB,iBAAW,QAAQ,SAAS,MAAM,GAAG;AAAG,YAAI,KAAK,GAAG,KAAK,UAAU,MAAM,EAAE,CAAC;AAC5E,aAAO,CAAC,GAAG,IAAI,IAAI,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,MAAM,IAAI,CAAC;AAAA,IAC9C;AAEA,UAAM,CAAC,EAAE,MAAM,QAAQ,QAAQ,IAAI,IAAI,UAAU,KAAK,QAAQ;AAC9D,QAAI,CAAC,KAAK,GAAG,IAAI,CAAC,SAAS,QAAQ,EAAE,GAAG,SAAS,QAAQ,EAAE,CAAC;AAG5D,QAAI;AAAM,OAAC,KAAK,GAAG,IAAI,WAAW,EAAE;AAAA,aAG3B,CAAC,OAAO,CAAC;AAAM,aAAO,CAAC,GAAG;AAQnC,KAAC,KAAK,GAAG,IAAI,CAAC,KAAK,OAAO,WAAW,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,MAAM,IAAI,CAAC;AAGjE,WAAO,MAAM,KAAK,KAAK,SAAS,MAAM,EAAE,KAAK,CAAC;AAAA,EAC/C;AACD;AAvHa","sourcesContent":["export enum Time {\n\tNanosecond = 1 / 1_000_000,\n\tMicrosecond = 1 / 1000,\n\tMillisecond = 1,\n\tSecond = 1000,\n\tMinute = Second * 60,\n\tHour = Minute * 60,\n\tDay = Hour * 24,\n\tWeek = Day * 7,\n\tMonth = Day * (365 / 12),\n\tYear = Day * 365\n}\n\nexport const partRegex = /^(?:(\\*)|(\\d+)(?:-(\\d+))?)(?:\\/(\\d+))?$/;\n\nexport const wildcardRegex = /\\bh\\b|\\B\\?\\B/g;\n\nexport const allowedNum = [\n\t[0, 59],\n\t[0, 23],\n\t[1, 31],\n\t[1, 12],\n\t[0, 6]\n];\n\nexport const predefined = {\n\t'@annually': '0 0 1 1 *',\n\t'@yearly': '0 0 1 1 *',\n\t'@monthly': '0 0 1 * *',\n\t'@weekly': '0 0 * * 0',\n\t'@daily': '0 0 * * *',\n\t'@hourly': '0 * * * *'\n} as const;\n\nexport const cronTokens = {\n\tjan: 1,\n\tfeb: 2,\n\tmar: 3,\n\tapr: 4,\n\tmay: 5,\n\tjun: 6,\n\tjul: 7,\n\taug: 8,\n\tsep: 9,\n\toct: 10,\n\tnov: 11,\n\tdec: 12,\n\tsun: 0,\n\tmon: 1,\n\ttue: 2,\n\twed: 3,\n\tthu: 4,\n\tfri: 5,\n\tsat: 6\n} as const;\n\nexport const tokensRegex = new RegExp(Object.keys(cronTokens).join('|'), 'g');\n","var __defProp = Object.defineProperty;\nvar __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;\nvar __name = (target, value) => __defProp(target, \"name\", { value, configurable: true });\nvar __publicField = (obj, key, value) => {\n __defNormalProp(obj, typeof key !== \"symbol\" ? key + \"\" : key, value);\n return value;\n};\n\nexport { __name, __publicField };\n//# sourceMappingURL=out.js.map\n//# sourceMappingURL=chunk-AZHX2MBF.mjs.map","/**\n * Get an array of numbers with the selected range\n * @param min The minimum value\n * @param max The maximum value\n * @param step The step value\n */\nexport function range(min: number, max: number, step: number): number[] {\n\treturn new Array(Math.floor((max - min) / step) + 1).fill(0).map((_val, i) => min + i * step);\n}\n","import { range } from '@sapphire/utilities';\nimport { allowedNum, cronTokens, partRegex, predefined, Time, tokensRegex, wildcardRegex } from './constants';\n\n/**\n * Handles Cron strings and generates dates based on the cron string provided.\n * @see https://en.wikipedia.org/wiki/Cron\n */\nexport class Cron {\n\tpublic cron: string;\n\tpublic normalized: string;\n\tpublic minutes: number[];\n\tpublic hours: number[];\n\tpublic days: number[];\n\tpublic months: number[];\n\tpublic dows: number[];\n\n\t/**\n\t * @param cron The cron pattern to use\n\t */\n\tpublic constructor(cron: string) {\n\t\tthis.cron = cron.toLowerCase();\n\t\tthis.normalized = Cron.normalize(this.cron);\n\t\t[this.minutes, this.hours, this.days, this.months, this.dows] = Cron.parseString(this.normalized);\n\t}\n\n\t/**\n\t * Get the next date that matches with the current pattern\n\t * @param outset The Date instance to compare with\n\t * @param origin Whether this next call is origin\n\t */\n\tpublic next(outset: Date = new Date(), origin = true): Date {\n\t\tif (!this.days.includes(outset.getUTCDate()) || !this.months.includes(outset.getUTCMonth() + 1) || !this.dows.includes(outset.getUTCDay())) {\n\t\t\treturn this.next(new Date(outset.getTime() + Time.Day), false);\n\t\t}\n\t\tif (!origin) return new Date(Date.UTC(outset.getUTCFullYear(), outset.getUTCMonth(), outset.getUTCDate(), this.hours[0], this.minutes[0]));\n\n\t\tconst now = new Date(outset.getTime() + 60000);\n\n\t\tfor (const hour of this.hours) {\n\t\t\tif (hour < now.getUTCHours()) continue;\n\t\t\tfor (const minute of this.minutes) {\n\t\t\t\tif (hour === now.getUTCHours() && minute < now.getUTCMinutes()) continue;\n\t\t\t\treturn new Date(Date.UTC(outset.getUTCFullYear(), outset.getUTCMonth(), outset.getUTCDate(), hour, minute));\n\t\t\t}\n\t\t}\n\n\t\treturn this.next(new Date(outset.getTime() + Time.Day), false);\n\t}\n\n\t/**\n\t * Normalize the pattern\n\t * @param cron The pattern to normalize\n\t */\n\tprivate static normalize(cron: string): string {\n\t\tif (Reflect.has(predefined, cron)) return Reflect.get(predefined, cron);\n\t\tconst now = new Date();\n\t\tcron = cron\n\t\t\t.split(' ')\n\t\t\t.map((val, i) =>\n\t\t\t\tval.replace(wildcardRegex, (match) => {\n\t\t\t\t\tif (match === 'h') return (Math.floor(Math.random() * allowedNum[i][1]) + allowedNum[i][0]).toString();\n\n\t\t\t\t\tif (match === '?') {\n\t\t\t\t\t\tswitch (i) {\n\t\t\t\t\t\t\tcase 0:\n\t\t\t\t\t\t\t\treturn now.getUTCMinutes().toString();\n\t\t\t\t\t\t\tcase 1:\n\t\t\t\t\t\t\t\treturn now.getUTCHours().toString();\n\t\t\t\t\t\t\tcase 2:\n\t\t\t\t\t\t\t\treturn now.getUTCDate().toString();\n\t\t\t\t\t\t\tcase 3:\n\t\t\t\t\t\t\t\treturn now.getUTCMonth().toString();\n\t\t\t\t\t\t\tcase 4:\n\t\t\t\t\t\t\t\treturn now.getUTCDay().toString();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\treturn match;\n\t\t\t\t})\n\t\t\t)\n\t\t\t.join(' ');\n\t\treturn cron.replace(tokensRegex, (match) => String(Reflect.get(cronTokens, match)));\n\t}\n\n\t/**\n\t * Parse the pattern\n\t * @param cron The pattern to parse\n\t */\n\tprivate static parseString(cron: string): Array<number[]> {\n\t\tconst parts = cron.split(' ');\n\t\tif (parts.length !== 5) throw new Error('Invalid Cron Provided');\n\t\treturn parts.map((part, i) => Cron.parsePart(part, i));\n\t}\n\n\t/**\n\t * Parse the current part\n\t * @param cronPart The part of the pattern to parse\n\t * @param id The id that identifies the current part\n\t */\n\tprivate static parsePart(cronPart: string, id: number): number[] {\n\t\tif (cronPart.includes(',')) {\n\t\t\tconst res: number[] = [];\n\t\t\tfor (const part of cronPart.split(',')) res.push(...Cron.parsePart(part, id));\n\t\t\treturn [...new Set(res)].sort((a, b) => a - b);\n\t\t}\n\n\t\tconst [, wild, minStr, maxStr, step] = partRegex.exec(cronPart)!;\n\t\tlet [min, max] = [parseInt(minStr, 10), parseInt(maxStr, 10)];\n\n\t\t// If '*', set min and max as the minimum and maximum allowed numbers:\n\t\tif (wild) [min, max] = allowedNum[id];\n\t\t// Else if a number was given, but not a maximum nor a step, return it\n\t\t// as only allowed value:\n\t\telse if (!max && !step) return [min];\n\n\t\t// Set min and max as the given numbers, defaulting max to the maximum\n\t\t// allowed, so min is never bigger than max:\n\t\t// This makes min and max be, in the following cases (considering minutes):\n\t\t// -> 1-2 | 1..2\n\t\t// -> 2-1 | 1..2\n\t\t// -> 1/7 | 1, 8, 15, 22, 29, 36, 43, 50, 57\n\t\t[min, max] = [min, max || allowedNum[id][1]].sort((a, b) => a - b);\n\n\t\t// Generate a range\n\t\treturn range(min, max, parseInt(step, 10) || 1);\n\t}\n}\n"]}
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/lib/constants.ts","../src/lib/Cron.ts"],"names":["Time"],"mappings":";;;;;;;;;AAAO,IAAK,OAAL,kBAAKA,UAAL;AACN,EAAAA,YAAA,gBAAa,QAAb;AACA,EAAAA,YAAA,iBAAc,QAAd;AACA,EAAAA,YAAA,iBAAc,KAAd;AACA,EAAAA,YAAA,YAAS,OAAT;AACA,EAAAA,YAAA,YAAS,OAAT;AACA,EAAAA,YAAA,UAAO,QAAP;AACA,EAAAA,YAAA,SAAM,SAAN;AACA,EAAAA,YAAA,UAAO,UAAP;AACA,EAAAA,YAAA,WAAQ,UAAR;AACA,EAAAA,YAAA,UAAO,WAAP;AAVW,SAAAA;AAAA,GAAA;AAaL,IAAM,YAAY;AAElB,IAAM,gBAAgB;AAEtB,IAAM,aAAa;AAAA,EACzB,CAAC,GAAG,EAAE;AAAA,EACN,CAAC,GAAG,EAAE;AAAA,EACN,CAAC,GAAG,EAAE;AAAA,EACN,CAAC,GAAG,EAAE;AAAA,EACN,CAAC,GAAG,CAAC;AACN;AAEO,IAAM,aAAa;AAAA,EACzB,aAAa;AAAA,EACb,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,WAAW;AAAA,EACX,UAAU;AAAA,EACV,WAAW;AACZ;AAEO,IAAM,aAAa;AAAA,EACzB,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK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AAW;AAAG,YAAM,IAAI,MAAM,uBAAuB;AAC/D,WAAO,MAAM,IAAI,CAAC,MAAM,MAAM,KAAK,UAAU,MAAM,CAAC,CAAC;AAAA,EACtD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,OAAe,UAAU,UAAkB,IAAsB;AAChE,QAAI,SAAS,SAAS,GAAG,GAAG;AAC3B,YAAM,MAAgB,CAAC;AACvB,iBAAW,QAAQ,SAAS,MAAM,GAAG;AAAG,YAAI,KAAK,GAAG,KAAK,UAAU,MAAM,EAAE,CAAC;AAC5E,aAAO,CAAC,GAAG,IAAI,IAAI,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,MAAM,IAAI,CAAC;AAAA,IAC9C;AAEA,UAAM,CAAC,EAAE,MAAM,QAAQ,QAAQ,IAAI,IAAI,UAAU,KAAK,QAAQ;AAC9D,QAAI,CAAC,KAAK,GAAG,IAAI,CAAC,SAAS,QAAQ,EAAE,GAAG,SAAS,QAAQ,EAAE,CAAC;AAG5D,QAAI;AAAM,OAAC,KAAK,GAAG,IAAI,WAAW,EAAE;AAAA,aAG3B,CAAC,OAAO,CAAC;AAAM,aAAO,CAAC,GAAG;AAQnC,KAAC,KAAK,GAAG,IAAI,CAAC,KAAK,OAAO,WAAW,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,MAAM,IAAI,CAAC;AAGjE,WAAO,MAAM,KAAK,KAAK,SAAS,MAAM,EAAE,KAAK,CAAC;AAAA,EAC/C;AACD;AAvHa","sourcesContent":["export enum Time {\n\tNanosecond = 1 / 1_000_000,\n\tMicrosecond = 1 / 1000,\n\tMillisecond = 1,\n\tSecond = 1000,\n\tMinute = Second * 60,\n\tHour = Minute * 60,\n\tDay = Hour * 24,\n\tWeek = Day * 7,\n\tMonth = Day * (365 / 12),\n\tYear = Day * 365\n}\n\nexport const partRegex = /^(?:(\\*)|(\\d+)(?:-(\\d+))?)(?:\\/(\\d+))?$/;\n\nexport const wildcardRegex = /\\bh\\b|\\B\\?\\B/g;\n\nexport const allowedNum = [\n\t[0, 59],\n\t[0, 23],\n\t[1, 31],\n\t[1, 12],\n\t[0, 6]\n];\n\nexport const predefined = {\n\t'@annually': '0 0 1 1 *',\n\t'@yearly': '0 0 1 1 *',\n\t'@monthly': '0 0 1 * *',\n\t'@weekly': '0 0 * * 0',\n\t'@daily': '0 0 * * *',\n\t'@hourly': '0 * * * *'\n} as const;\n\nexport const cronTokens = {\n\tjan: 1,\n\tfeb: 2,\n\tmar: 3,\n\tapr: 4,\n\tmay: 5,\n\tjun: 6,\n\tjul: 7,\n\taug: 8,\n\tsep: 9,\n\toct: 10,\n\tnov: 11,\n\tdec: 12,\n\tsun: 0,\n\tmon: 1,\n\ttue: 2,\n\twed: 3,\n\tthu: 4,\n\tfri: 5,\n\tsat: 6\n} as const;\n\nexport const tokensRegex = new RegExp(Object.keys(cronTokens).join('|'), 'g');\n","import { range } from '@sapphire/utilities';\nimport { allowedNum, cronTokens, partRegex, predefined, Time, tokensRegex, wildcardRegex } from './constants';\n\n/**\n * Handles Cron strings and generates dates based on the cron string provided.\n * @see https://en.wikipedia.org/wiki/Cron\n */\nexport class Cron {\n\tpublic cron: string;\n\tpublic normalized: string;\n\tpublic minutes: number[];\n\tpublic hours: number[];\n\tpublic days: number[];\n\tpublic months: number[];\n\tpublic dows: number[];\n\n\t/**\n\t * @param cron The cron pattern to use\n\t */\n\tpublic constructor(cron: string) {\n\t\tthis.cron = cron.toLowerCase();\n\t\tthis.normalized = Cron.normalize(this.cron);\n\t\t[this.minutes, this.hours, this.days, this.months, this.dows] = Cron.parseString(this.normalized);\n\t}\n\n\t/**\n\t * Get the next date that matches with the current pattern\n\t * @param outset The Date instance to compare with\n\t * @param origin Whether this next call is origin\n\t */\n\tpublic next(outset: Date = new Date(), origin = true): Date {\n\t\tif (!this.days.includes(outset.getUTCDate()) || !this.months.includes(outset.getUTCMonth() + 1) || !this.dows.includes(outset.getUTCDay())) {\n\t\t\treturn this.next(new Date(outset.getTime() + Time.Day), false);\n\t\t}\n\t\tif (!origin) return new Date(Date.UTC(outset.getUTCFullYear(), outset.getUTCMonth(), outset.getUTCDate(), this.hours[0], this.minutes[0]));\n\n\t\tconst now = new Date(outset.getTime() + 60000);\n\n\t\tfor (const hour of this.hours) {\n\t\t\tif (hour < now.getUTCHours()) continue;\n\t\t\tfor (const minute of this.minutes) {\n\t\t\t\tif (hour === now.getUTCHours() && minute < now.getUTCMinutes()) continue;\n\t\t\t\treturn new Date(Date.UTC(outset.getUTCFullYear(), outset.getUTCMonth(), outset.getUTCDate(), hour, minute));\n\t\t\t}\n\t\t}\n\n\t\treturn this.next(new Date(outset.getTime() + Time.Day), false);\n\t}\n\n\t/**\n\t * Normalize the pattern\n\t * @param cron The pattern to normalize\n\t */\n\tprivate static normalize(cron: string): string {\n\t\tif (Reflect.has(predefined, cron)) return Reflect.get(predefined, cron);\n\t\tconst now = new Date();\n\t\tcron = cron\n\t\t\t.split(' ')\n\t\t\t.map((val, i) =>\n\t\t\t\tval.replace(wildcardRegex, (match) => {\n\t\t\t\t\tif (match === 'h') return (Math.floor(Math.random() * allowedNum[i][1]) + allowedNum[i][0]).toString();\n\n\t\t\t\t\tif (match === '?') {\n\t\t\t\t\t\tswitch (i) {\n\t\t\t\t\t\t\tcase 0:\n\t\t\t\t\t\t\t\treturn now.getUTCMinutes().toString();\n\t\t\t\t\t\t\tcase 1:\n\t\t\t\t\t\t\t\treturn now.getUTCHours().toString();\n\t\t\t\t\t\t\tcase 2:\n\t\t\t\t\t\t\t\treturn now.getUTCDate().toString();\n\t\t\t\t\t\t\tcase 3:\n\t\t\t\t\t\t\t\treturn now.getUTCMonth().toString();\n\t\t\t\t\t\t\tcase 4:\n\t\t\t\t\t\t\t\treturn now.getUTCDay().toString();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\treturn match;\n\t\t\t\t})\n\t\t\t)\n\t\t\t.join(' ');\n\t\treturn cron.replace(tokensRegex, (match) => String(Reflect.get(cronTokens, match)));\n\t}\n\n\t/**\n\t * Parse the pattern\n\t * @param cron The pattern to parse\n\t */\n\tprivate static parseString(cron: string): Array<number[]> {\n\t\tconst parts = cron.split(' ');\n\t\tif (parts.length !== 5) throw new Error('Invalid Cron Provided');\n\t\treturn parts.map((part, i) => Cron.parsePart(part, i));\n\t}\n\n\t/**\n\t * Parse the current part\n\t * @param cronPart The part of the pattern to parse\n\t * @param id The id that identifies the current part\n\t */\n\tprivate static parsePart(cronPart: string, id: number): number[] {\n\t\tif (cronPart.includes(',')) {\n\t\t\tconst res: number[] = [];\n\t\t\tfor (const part of cronPart.split(',')) res.push(...Cron.parsePart(part, id));\n\t\t\treturn [...new Set(res)].sort((a, b) => a - b);\n\t\t}\n\n\t\tconst [, wild, minStr, maxStr, step] = partRegex.exec(cronPart)!;\n\t\tlet [min, max] = [parseInt(minStr, 10), parseInt(maxStr, 10)];\n\n\t\t// If '*', set min and max as the minimum and maximum allowed numbers:\n\t\tif (wild) [min, max] = allowedNum[id];\n\t\t// Else if a number was given, but not a maximum nor a step, return it\n\t\t// as only allowed value:\n\t\telse if (!max && !step) return [min];\n\n\t\t// Set min and max as the given numbers, defaulting max to the maximum\n\t\t// allowed, so min is never bigger than max:\n\t\t// This makes min and max be, in the following cases (considering minutes):\n\t\t// -> 1-2 | 1..2\n\t\t// -> 2-1 | 1..2\n\t\t// -> 1/7 | 1, 8, 15, 22, 29, 36, 43, 50, 57\n\t\t[min, max] = [min, max || allowedNum[id][1]].sort((a, b) => a - b);\n\n\t\t// Generate a range\n\t\treturn range(min, max, parseInt(step, 10) || 1);\n\t}\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/lib/constants.ts","../src/lib/Cron.ts"],"names":["Time"],"mappings":";;;;;;;;;AAAO,IAAK,OAAL,kBAAKA,UAAL;AACN,EAAAA,YAAA,gBAAa,QAAb;AACA,EAAAA,YAAA,iBAAc,QAAd;AACA,EAAAA,YAAA,iBAAc,KAAd;AACA,E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C,GAAG,MAAM,IAAI,CAAC;AAAA,IAC9C;AAEA,UAAM,CAAC,EAAE,MAAM,QAAQ,QAAQ,IAAI,IAAI,UAAU,KAAK,QAAQ;AAC9D,QAAI,CAAC,KAAK,GAAG,IAAI,CAAC,SAAS,QAAQ,EAAE,GAAG,SAAS,QAAQ,EAAE,CAAC;AAG5D,QAAI;AAAM,OAAC,KAAK,GAAG,IAAI,WAAW,EAAE;AAAA,aAG3B,CAAC,OAAO,CAAC;AAAM,aAAO,CAAC,GAAG;AAQnC,KAAC,KAAK,GAAG,IAAI,CAAC,KAAK,OAAO,WAAW,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,MAAM,IAAI,CAAC;AAGjE,WAAO,MAAM,KAAK,KAAK,SAAS,MAAM,EAAE,KAAK,CAAC;AAAA,EAC/C;AACD;AAvHa","sourcesContent":["export enum Time {\n\tNanosecond = 1 / 1_000_000,\n\tMicrosecond = 1 / 1000,\n\tMillisecond = 1,\n\tSecond = 1000,\n\tMinute = Second * 60,\n\tHour = Minute * 60,\n\tDay = Hour * 24,\n\tWeek = Day * 7,\n\tMonth = Day * (365 / 12),\n\tYear = Day * 365\n}\n\nexport const partRegex = /^(?:(\\*)|(\\d+)(?:-(\\d+))?)(?:\\/(\\d+))?$/;\n\nexport const wildcardRegex = /\\bh\\b|\\B\\?\\B/g;\n\nexport const allowedNum = [\n\t[0, 59],\n\t[0, 23],\n\t[1, 31],\n\t[1, 12],\n\t[0, 6]\n];\n\nexport const predefined = {\n\t'@annually': '0 0 1 1 *',\n\t'@yearly': '0 0 1 1 *',\n\t'@monthly': '0 0 1 * *',\n\t'@weekly': '0 0 * * 0',\n\t'@daily': '0 0 * * *',\n\t'@hourly': '0 * * * *'\n} as const;\n\nexport const cronTokens = {\n\tjan: 1,\n\tfeb: 2,\n\tmar: 3,\n\tapr: 4,\n\tmay: 5,\n\tjun: 6,\n\tjul: 7,\n\taug: 8,\n\tsep: 9,\n\toct: 10,\n\tnov: 11,\n\tdec: 12,\n\tsun: 0,\n\tmon: 1,\n\ttue: 2,\n\twed: 3,\n\tthu: 4,\n\tfri: 5,\n\tsat: 6\n} as const;\n\nexport const tokensRegex = new RegExp(Object.keys(cronTokens).join('|'), 'g');\n","import { range } from '@sapphire/utilities';\nimport { allowedNum, cronTokens, partRegex, predefined, Time, tokensRegex, wildcardRegex } from './constants';\n\n/**\n * Handles Cron strings and generates dates based on the cron string provided.\n * @see https://en.wikipedia.org/wiki/Cron\n */\nexport class Cron {\n\tpublic cron: string;\n\tpublic normalized: string;\n\tpublic minutes: number[];\n\tpublic hours: number[];\n\tpublic days: number[];\n\tpublic months: number[];\n\tpublic dows: number[];\n\n\t/**\n\t * @param cron The cron pattern to use\n\t */\n\tpublic constructor(cron: string) {\n\t\tthis.cron = cron.toLowerCase();\n\t\tthis.normalized = Cron.normalize(this.cron);\n\t\t[this.minutes, this.hours, this.days, this.months, this.dows] = Cron.parseString(this.normalized);\n\t}\n\n\t/**\n\t * Get the next date that matches with the current pattern\n\t * @param outset The Date instance to compare with\n\t * @param origin Whether this next call is origin\n\t */\n\tpublic next(outset: Date = new Date(), origin = true): Date {\n\t\tif (!this.days.includes(outset.getUTCDate()) || !this.months.includes(outset.getUTCMonth() + 1) || !this.dows.includes(outset.getUTCDay())) {\n\t\t\treturn this.next(new Date(outset.getTime() + Time.Day), false);\n\t\t}\n\t\tif (!origin) return new Date(Date.UTC(outset.getUTCFullYear(), outset.getUTCMonth(), outset.getUTCDate(), this.hours[0], this.minutes[0]));\n\n\t\tconst now = new Date(outset.getTime() + 60000);\n\n\t\tfor (const hour of this.hours) {\n\t\t\tif (hour < now.getUTCHours()) continue;\n\t\t\tfor (const minute of this.minutes) {\n\t\t\t\tif (hour === now.getUTCHours() && minute < now.getUTCMinutes()) continue;\n\t\t\t\treturn new Date(Date.UTC(outset.getUTCFullYear(), outset.getUTCMonth(), outset.getUTCDate(), hour, minute));\n\t\t\t}\n\t\t}\n\n\t\treturn this.next(new Date(outset.getTime() + Time.Day), false);\n\t}\n\n\t/**\n\t * Normalize the pattern\n\t * @param cron The pattern to normalize\n\t */\n\tprivate static normalize(cron: string): string {\n\t\tif (Reflect.has(predefined, cron)) return Reflect.get(predefined, cron);\n\t\tconst now = new Date();\n\t\tcron = cron\n\t\t\t.split(' ')\n\t\t\t.map((val, i) =>\n\t\t\t\tval.replace(wildcardRegex, (match) => {\n\t\t\t\t\tif (match === 'h') return (Math.floor(Math.random() * allowedNum[i][1]) + allowedNum[i][0]).toString();\n\n\t\t\t\t\tif (match === '?') {\n\t\t\t\t\t\tswitch (i) {\n\t\t\t\t\t\t\tcase 0:\n\t\t\t\t\t\t\t\treturn now.getUTCMinutes().toString();\n\t\t\t\t\t\t\tcase 1:\n\t\t\t\t\t\t\t\treturn now.getUTCHours().toString();\n\t\t\t\t\t\t\tcase 2:\n\t\t\t\t\t\t\t\treturn now.getUTCDate().toString();\n\t\t\t\t\t\t\tcase 3:\n\t\t\t\t\t\t\t\treturn now.getUTCMonth().toString();\n\t\t\t\t\t\t\tcase 4:\n\t\t\t\t\t\t\t\treturn now.getUTCDay().toString();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\treturn match;\n\t\t\t\t})\n\t\t\t)\n\t\t\t.join(' ');\n\t\treturn cron.replace(tokensRegex, (match) => String(Reflect.get(cronTokens, match)));\n\t}\n\n\t/**\n\t * Parse the pattern\n\t * @param cron The pattern to parse\n\t */\n\tprivate static parseString(cron: string): Array<number[]> {\n\t\tconst parts = cron.split(' ');\n\t\tif (parts.length !== 5) throw new Error('Invalid Cron Provided');\n\t\treturn parts.map((part, i) => Cron.parsePart(part, i));\n\t}\n\n\t/**\n\t * Parse the current part\n\t * @param cronPart The part of the pattern to parse\n\t * @param id The id that identifies the current part\n\t */\n\tprivate static parsePart(cronPart: string, id: number): number[] {\n\t\tif (cronPart.includes(',')) {\n\t\t\tconst res: number[] = [];\n\t\t\tfor (const part of cronPart.split(',')) res.push(...Cron.parsePart(part, id));\n\t\t\treturn [...new Set(res)].sort((a, b) => a - b);\n\t\t}\n\n\t\tconst [, wild, minStr, maxStr, step] = partRegex.exec(cronPart)!;\n\t\tlet [min, max] = [parseInt(minStr, 10), parseInt(maxStr, 10)];\n\n\t\t// If '*', set min and max as the minimum and maximum allowed numbers:\n\t\tif (wild) [min, max] = allowedNum[id];\n\t\t// Else if a number was given, but not a maximum nor a step, return it\n\t\t// as only allowed value:\n\t\telse if (!max && !step) return [min];\n\n\t\t// Set min and max as the given numbers, defaulting max to the maximum\n\t\t// allowed, so min is never bigger than max:\n\t\t// This makes min and max be, in the following cases (considering minutes):\n\t\t// -> 1-2 | 1..2\n\t\t// -> 2-1 | 1..2\n\t\t// -> 1/7 | 1, 8, 15, 22, 29, 36, 43, 50, 57\n\t\t[min, max] = [min, max || allowedNum[id][1]].sort((a, b) => a - b);\n\n\t\t// Generate a range\n\t\treturn range(min, max, parseInt(step, 10) || 1);\n\t}\n}\n"]}