cron-converter-u2q 1.3.0 → 1.3.1
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/README.md +52 -90
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,131 +1,93 @@
|
|
|
1
1
|
# cron-converter-u2q
|
|
2
2
|
|
|
3
|
-
[](https://github.com/rahu619/cron-converter-u2q)
|
|
4
3
|
[](https://www.npmjs.com/package/cron-converter-u2q)
|
|
4
|
+
[](https://www.npmjs.com/package/cron-converter-u2q)
|
|
5
5
|
[](LICENSE)
|
|
6
6
|
[](https://github.com/rahu619/cron-converter-u2q/actions)
|
|
7
|
-
[](https://github.com/rahu619/cron-converter-u2q/actions)
|
|
8
|
-
[](https://www.typescriptlang.org/)
|
|
9
|
-
[](https://www.npmjs.com/package/cron-converter-u2q)
|
|
10
|
-
|
|
11
|
-
[](https://www.npmjs.com/package/cron-converter-u2q)
|
|
12
7
|
|
|
13
|
-
A
|
|
8
|
+
A lightweight, zero-dependency TypeScript utility to convert, validate, and describe cron expressions. Seamlessly translate between Unix and Quartz schedules, perform boundary checks, and render human-readable descriptions.
|
|
14
9
|
|
|
15
|
-
|
|
10
|
+
---
|
|
16
11
|
|
|
17
|
-
|
|
18
|
-
- **Unix to Quartz**: Convert standard Unix cron expressions to Quartz format
|
|
19
|
-
- **Quartz to Unix**: Convert Quartz cron expressions to standard Unix format
|
|
20
|
-
- **Format Validation**: Built-in validation for both formats
|
|
21
|
-
- **Error Handling**: Clear error messages for invalid expressions
|
|
12
|
+
## 💡 Unix vs. Quartz Cron
|
|
22
13
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
- **Detailed**: Includes all schedule details (minutes, hours, days, etc.)
|
|
14
|
+
| Specification | Fields | Format | Support |
|
|
15
|
+
| :--- | :--- | :--- | :--- |
|
|
16
|
+
| **Unix Cron** | 5 fields | `min hour dom month dow` | Standard POSIX (Linux, Crontab) |
|
|
17
|
+
| **Quartz Cron** | 6–7 fields | `sec min hour dom month dow [year]` | Java/Spring, AWS EventBridge, Azure |
|
|
28
18
|
|
|
29
|
-
|
|
30
|
-
-
|
|
31
|
-
- **Zero Dependencies**: Lightweight and fast
|
|
32
|
-
- **Well Tested**: Comprehensive test coverage
|
|
33
|
-
- **ES6 Modules**: Support for both CommonJS and ES6 imports
|
|
19
|
+
> [!NOTE]
|
|
20
|
+
> Quartz cron requires exactly one of `day-of-month` or `day-of-week` to contain `?` (when specifying a constraint on the other field) to prevent scheduling conflicts.
|
|
34
21
|
|
|
35
|
-
|
|
36
|
-
- **Format Validation**: Ensures cron expressions are valid
|
|
37
|
-
- **Range Checking**: Validates field values within acceptable ranges
|
|
38
|
-
- **Clear Errors**: Descriptive error messages for debugging
|
|
39
|
-
- **Type Safety**: TypeScript types for better development experience
|
|
22
|
+
---
|
|
40
23
|
|
|
41
24
|
## 📦 Installation
|
|
42
25
|
|
|
43
26
|
```bash
|
|
44
|
-
# Using npm
|
|
45
27
|
npm install cron-converter-u2q
|
|
46
|
-
|
|
47
|
-
# Using yarn
|
|
28
|
+
# or
|
|
48
29
|
yarn add cron-converter-u2q
|
|
49
|
-
|
|
50
|
-
# Using pnpm
|
|
30
|
+
# or
|
|
51
31
|
pnpm add cron-converter-u2q
|
|
52
32
|
```
|
|
53
33
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
```typescript
|
|
57
|
-
import { CronConverterU2Q, CronDescriberU2Q } from 'cron-converter-u2q';
|
|
58
|
-
|
|
59
|
-
// Convert Unix to Quartz
|
|
60
|
-
const quartzExpression = CronConverterU2Q.unixToQuartz('5 * * * *');
|
|
61
|
-
console.log(quartzExpression); // "0 5 * * * ? *"
|
|
62
|
-
|
|
63
|
-
// Convert Quartz to Unix
|
|
64
|
-
const unixExpression = CronConverterU2Q.quartzToUnix('0 0 8 * * ?');
|
|
65
|
-
console.log(unixExpression); // "0 8 * * *"
|
|
66
|
-
// Get human-readable description
|
|
67
|
-
const description = CronDescriberU2Q.describeUnix('*/5 * * * *');
|
|
68
|
-
console.log(description); // "Every 5 minutes"
|
|
69
|
-
```
|
|
34
|
+
---
|
|
70
35
|
|
|
71
|
-
##
|
|
36
|
+
## 🚀 Usage
|
|
72
37
|
|
|
73
|
-
###
|
|
38
|
+
### 1. Two-Way Conversion
|
|
39
|
+
Convert seamlessly between formats. Wildcards and aliases are normalized automatically.
|
|
74
40
|
|
|
75
41
|
```typescript
|
|
76
|
-
|
|
77
|
-
CronConverterU2Q.unixToQuartz('0 12 * * *'); // "0 0 12 * * ? *"
|
|
78
|
-
CronConverterU2Q.unixToQuartz('*/15 * * * *'); // "0 */15 * * * ? *"
|
|
79
|
-
// Quartz to Unix
|
|
80
|
-
CronConverterU2Q.quartzToUnix('0 0 8 * * ?'); // "0 8 * * *"
|
|
81
|
-
CronConverterU2Q.quartzToUnix('0 */5 * * * ?'); // "*/5 * * * *"
|
|
82
|
-
```
|
|
42
|
+
import { CronConverterU2Q } from 'cron-converter-u2q';
|
|
83
43
|
|
|
84
|
-
|
|
44
|
+
// Unix -> Quartz (adds 0 seconds)
|
|
45
|
+
CronConverterU2Q.unixToQuartz('*/15 * * * *'); // "0 */15 * * * * *"
|
|
46
|
+
CronConverterU2Q.unixToQuartz('0 12 * * 1'); // "0 0 12 ? * 2 *"
|
|
85
47
|
|
|
86
|
-
|
|
87
|
-
//
|
|
88
|
-
|
|
89
|
-
CronDescriberU2Q.describeUnix('*/15 * * * *'); // "Every 15 minutes"
|
|
90
|
-
|
|
91
|
-
// Quartz format descriptions
|
|
92
|
-
CronDescriberU2Q.describeQuartz('0 0 8 * * ?'); // "At 8 o'clock"
|
|
93
|
-
CronDescriberU2Q.describeQuartz('0 */5 * * * ?'); // "Every 5 minutes"
|
|
48
|
+
// Quartz -> Unix (drops seconds/year)
|
|
49
|
+
CronConverterU2Q.quartzToUnix('0 0 8 * * ?'); // "0 8 * * *"
|
|
50
|
+
CronConverterU2Q.quartzToUnix('0 */5 * ? * 2'); // "*/5 * * * 1"
|
|
94
51
|
```
|
|
95
52
|
|
|
96
|
-
|
|
53
|
+
### 2. Validation
|
|
54
|
+
Perform boundary checks, detect syntax errors, and validate range limits.
|
|
97
55
|
|
|
98
|
-
|
|
56
|
+
```typescript
|
|
57
|
+
import { CronValidatorU2Q } from 'cron-converter-u2q';
|
|
99
58
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
104
|
-
5. Open a Pull Request
|
|
59
|
+
// Validate and throw detailed error messages
|
|
60
|
+
CronValidatorU2Q.validateUnix('60 * * * *'); // Throws: "Value 60 is out of range (0-59) for Minute"
|
|
61
|
+
CronValidatorU2Q.validateQuartz('0 */0 * ? * *'); // Throws: "Invalid step value in Minute: 0"
|
|
105
62
|
|
|
106
|
-
|
|
63
|
+
// Boolean check
|
|
64
|
+
CronValidatorU2Q.isValidUnix('*/5 * * * *'); // true
|
|
65
|
+
CronValidatorU2Q.isValidQuartz('0 0 12 * * * *'); // true (both are allowed to be '*' in this package)
|
|
66
|
+
```
|
|
107
67
|
|
|
108
|
-
|
|
68
|
+
### 3. Human-Readable Descriptions
|
|
69
|
+
Render cron schedules into clear, natural English. Fully supports lists, ranges, step modifiers, and Quartz special symbols.
|
|
109
70
|
|
|
110
|
-
|
|
71
|
+
```typescript
|
|
72
|
+
import { CronDescriberU2Q } from 'cron-converter-u2q';
|
|
111
73
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
-
|
|
74
|
+
// Unix
|
|
75
|
+
CronDescriberU2Q.describeUnix('*/15 * * * *'); // "Every 15 minutes"
|
|
76
|
+
CronDescriberU2Q.describeUnix('0 12 1-5 * *'); // "At 12 o'clock from the 1st to the 5th of the month"
|
|
115
77
|
|
|
116
|
-
|
|
78
|
+
// Quartz
|
|
79
|
+
CronDescriberU2Q.describeQuartz('0 0 8,12 ? * 2-6 *'); // "At 8 and 12 o'clock from Monday to Friday"
|
|
80
|
+
CronDescriberU2Q.describeQuartz('0 0 0 L * ?'); // "At 0 o'clock on the last day of the month"
|
|
81
|
+
```
|
|
117
82
|
|
|
118
|
-
|
|
119
|
-
- Inspired by the need for a simple, reliable cron expression converter
|
|
120
|
-
- Built with TypeScript for better developer experience
|
|
83
|
+
---
|
|
121
84
|
|
|
122
|
-
##
|
|
85
|
+
## 🤝 Contributing
|
|
123
86
|
|
|
124
|
-
|
|
87
|
+
Contributions are welcome! Please feel free to open issues or submit Pull Requests.
|
|
125
88
|
|
|
126
|
-
|
|
127
|
-
[https://pubs.opengroup.org/onlinepubs/9699919799/utilities/crontab.html](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/crontab.html)
|
|
89
|
+
---
|
|
128
90
|
|
|
129
|
-
|
|
130
|
-
[https://www.quartz-scheduler.org/documentation/quartz-2.3.0/tutorials/crontrigger.html](https://www.quartz-scheduler.org/documentation/quartz-2.3.0/tutorials/crontrigger.html)
|
|
91
|
+
## 📄 License
|
|
131
92
|
|
|
93
|
+
This project is licensed under the MIT License.
|