cron-converter-u2q 0.1.15 → 0.1.16
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/.github/workflows/integration.yml +33 -33
- package/.github/workflows/release.yml +55 -55
- package/LICENSE +21 -21
- package/README.md +61 -61
- package/jest.config.ts +9 -9
- package/package.json +1 -1
- package/src/__tests__/index.test.ts +81 -81
- package/src/converter.ts +65 -65
- package/src/index.ts +3 -3
- package/tsconfig.json +20 -20
- package/types/index.d.ts +6 -6
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
name: Build
|
|
2
|
-
on:
|
|
3
|
-
push:
|
|
4
|
-
branches: [main]
|
|
5
|
-
pull_request:
|
|
6
|
-
branches: [main]
|
|
7
|
-
jobs:
|
|
8
|
-
build:
|
|
9
|
-
name: Build and Test
|
|
10
|
-
runs-on: ubuntu-latest
|
|
11
|
-
strategy:
|
|
12
|
-
matrix:
|
|
13
|
-
node-version: [16.x, 18.x, 20.x]
|
|
14
|
-
steps:
|
|
15
|
-
- name: Checkout code
|
|
16
|
-
uses: actions/checkout@v3
|
|
17
|
-
|
|
18
|
-
- name: Setup Node.js ${{ matrix.node-version }}
|
|
19
|
-
uses: actions/setup-node@v3
|
|
20
|
-
with:
|
|
21
|
-
node-version: ${{ matrix.node-version }}
|
|
22
|
-
|
|
23
|
-
- name: Clean Install Dependencies
|
|
24
|
-
run: npm ci
|
|
25
|
-
|
|
26
|
-
- name: Run Tests
|
|
27
|
-
run: npm test
|
|
28
|
-
|
|
29
|
-
- name: Linting
|
|
30
|
-
run: npm run lint
|
|
31
|
-
|
|
32
|
-
- name: Run build
|
|
33
|
-
run: npm run build --if-present
|
|
1
|
+
name: Build
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
branches: [main]
|
|
5
|
+
pull_request:
|
|
6
|
+
branches: [main]
|
|
7
|
+
jobs:
|
|
8
|
+
build:
|
|
9
|
+
name: Build and Test
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
strategy:
|
|
12
|
+
matrix:
|
|
13
|
+
node-version: [16.x, 18.x, 20.x]
|
|
14
|
+
steps:
|
|
15
|
+
- name: Checkout code
|
|
16
|
+
uses: actions/checkout@v3
|
|
17
|
+
|
|
18
|
+
- name: Setup Node.js ${{ matrix.node-version }}
|
|
19
|
+
uses: actions/setup-node@v3
|
|
20
|
+
with:
|
|
21
|
+
node-version: ${{ matrix.node-version }}
|
|
22
|
+
|
|
23
|
+
- name: Clean Install Dependencies
|
|
24
|
+
run: npm ci
|
|
25
|
+
|
|
26
|
+
- name: Run Tests
|
|
27
|
+
run: npm test
|
|
28
|
+
|
|
29
|
+
- name: Linting
|
|
30
|
+
run: npm run lint
|
|
31
|
+
|
|
32
|
+
- name: Run build
|
|
33
|
+
run: npm run build --if-present
|
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
name: Release
|
|
2
|
-
on:
|
|
3
|
-
workflow_run:
|
|
4
|
-
workflows: ["Build"]
|
|
5
|
-
types:
|
|
6
|
-
- completed
|
|
7
|
-
jobs:
|
|
8
|
-
release:
|
|
9
|
-
permissions: write-all
|
|
10
|
-
runs-on: ubuntu-latest
|
|
11
|
-
steps:
|
|
12
|
-
- uses: actions/checkout@v3
|
|
13
|
-
- name: Setup node.js
|
|
14
|
-
uses: actions/setup-node@v3
|
|
15
|
-
with:
|
|
16
|
-
node-version: "18.x"
|
|
17
|
-
registry-url: "https://registry.npmjs.org"
|
|
18
|
-
|
|
19
|
-
- name: Publish to NPM
|
|
20
|
-
run: npm publish
|
|
21
|
-
env:
|
|
22
|
-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
23
|
-
|
|
24
|
-
- name: Get package version
|
|
25
|
-
id: pkgver
|
|
26
|
-
run: echo "::set-output name=version::$(node -p "require('./package.json').version")"
|
|
27
|
-
|
|
28
|
-
# Creates a .tgz file in your working directory
|
|
29
|
-
- name: Package NPM tarball
|
|
30
|
-
run: npm pack
|
|
31
|
-
|
|
32
|
-
# - name: Debug GitHub event
|
|
33
|
-
# run: echo "${{ toJson(github.event.release) }}"
|
|
34
|
-
|
|
35
|
-
- name: Create Release
|
|
36
|
-
id: create_release
|
|
37
|
-
uses: actions/create-release@v1
|
|
38
|
-
env:
|
|
39
|
-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
40
|
-
with:
|
|
41
|
-
tag_name: ${{ steps.pkgver.outputs.version }}
|
|
42
|
-
release_name: Release ${{ steps.pkgver.outputs.version }}
|
|
43
|
-
draft: false
|
|
44
|
-
prerelease: false
|
|
45
|
-
|
|
46
|
-
- name: Upload Release Asset
|
|
47
|
-
id: upload-release-asset
|
|
48
|
-
uses: actions/upload-release-asset@v1
|
|
49
|
-
env:
|
|
50
|
-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
51
|
-
with:
|
|
52
|
-
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`.
|
|
53
|
-
asset_path: ./cron-converter-u2q-${{ steps.pkgver.outputs.version }}.tgz
|
|
54
|
-
asset_name: cron-converter-u2q-${{ steps.pkgver.outputs.version }}.tgz
|
|
55
|
-
asset_content_type: application/gzip
|
|
1
|
+
name: Release
|
|
2
|
+
on:
|
|
3
|
+
workflow_run:
|
|
4
|
+
workflows: ["Build"]
|
|
5
|
+
types:
|
|
6
|
+
- completed
|
|
7
|
+
jobs:
|
|
8
|
+
release:
|
|
9
|
+
permissions: write-all
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v3
|
|
13
|
+
- name: Setup node.js
|
|
14
|
+
uses: actions/setup-node@v3
|
|
15
|
+
with:
|
|
16
|
+
node-version: "18.x"
|
|
17
|
+
registry-url: "https://registry.npmjs.org"
|
|
18
|
+
|
|
19
|
+
- name: Publish to NPM
|
|
20
|
+
run: npm publish
|
|
21
|
+
env:
|
|
22
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
23
|
+
|
|
24
|
+
- name: Get package version
|
|
25
|
+
id: pkgver
|
|
26
|
+
run: echo "::set-output name=version::$(node -p "require('./package.json').version")"
|
|
27
|
+
|
|
28
|
+
# Creates a .tgz file in your working directory
|
|
29
|
+
- name: Package NPM tarball
|
|
30
|
+
run: npm pack
|
|
31
|
+
|
|
32
|
+
# - name: Debug GitHub event
|
|
33
|
+
# run: echo "${{ toJson(github.event.release) }}"
|
|
34
|
+
|
|
35
|
+
- name: Create Release
|
|
36
|
+
id: create_release
|
|
37
|
+
uses: actions/create-release@v1
|
|
38
|
+
env:
|
|
39
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
40
|
+
with:
|
|
41
|
+
tag_name: ${{ steps.pkgver.outputs.version }}
|
|
42
|
+
release_name: Release ${{ steps.pkgver.outputs.version }}
|
|
43
|
+
draft: false
|
|
44
|
+
prerelease: false
|
|
45
|
+
|
|
46
|
+
- name: Upload Release Asset
|
|
47
|
+
id: upload-release-asset
|
|
48
|
+
uses: actions/upload-release-asset@v1
|
|
49
|
+
env:
|
|
50
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
51
|
+
with:
|
|
52
|
+
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`.
|
|
53
|
+
asset_path: ./cron-converter-u2q-${{ steps.pkgver.outputs.version }}.tgz
|
|
54
|
+
asset_name: cron-converter-u2q-${{ steps.pkgver.outputs.version }}.tgz
|
|
55
|
+
asset_content_type: application/gzip
|
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2023 Rahul
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Rahul
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
# cron-converter-u2q
|
|
2
|
-
|
|
3
|
-
Easily convert cron expressions between Unix and Quartz formats with the `cron-converter-u2q` package
|
|
4
|
-
|
|
5
|
-

|
|
6
|
-

|
|
7
|
-
[](https://www.npmjs.com/package/cron-converter-u2q)
|
|
8
|
-
|
|
9
|
-
### Features
|
|
10
|
-
|
|
11
|
-
:arrows_counterclockwise: Two-way conversion: from Unix to Quartz and Quartz to Unix.
|
|
12
|
-
|
|
13
|
-
### Installation
|
|
14
|
-
|
|
15
|
-
Using npm:
|
|
16
|
-
|
|
17
|
-
```bash
|
|
18
|
-
npm install cron-converter
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
Using yarn:
|
|
22
|
-
|
|
23
|
-
```bash
|
|
24
|
-
yarn add cron-converter
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
### Usage
|
|
28
|
-
|
|
29
|
-
Firstly, import the CronConverterU2Q module:
|
|
30
|
-
|
|
31
|
-
```javascript
|
|
32
|
-
var cron_converter_u2q = require("cron-converter-u2q");
|
|
33
|
-
|
|
34
|
-
var c2q = cron_converter_u2q.CronConverterU2Q;
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
If you're using ES6 Modules
|
|
38
|
-
|
|
39
|
-
```javascript
|
|
40
|
-
import { CronConverterU2QModule as c2q } from "cron-converter-u2q";
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
Convert from Unix to Quartz
|
|
44
|
-
|
|
45
|
-
```javascript
|
|
46
|
-
const quartzExpression = c2q.unixToQuartz("5 * * * *");
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
Convert from Quartz to Unix
|
|
50
|
-
|
|
51
|
-
```javascript
|
|
52
|
-
const unixExpression = c2q.quartzToUnix("* */5 * ? * * *");
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
### Development Notice
|
|
56
|
-
|
|
57
|
-
This package is still under active development. Some methods and features might not be stable yet. We're working diligently to improve and stabilize the package. Any feedback, suggestions, or contributions are highly appreciated!
|
|
58
|
-
|
|
59
|
-
## License
|
|
60
|
-
|
|
61
|
-
This project is licensed under the [MIT License](https://opensource.org/license/mit/)
|
|
1
|
+
# cron-converter-u2q
|
|
2
|
+
|
|
3
|
+
Easily convert cron expressions between Unix and Quartz formats with the `cron-converter-u2q` package
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+
[](https://www.npmjs.com/package/cron-converter-u2q)
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
:arrows_counterclockwise: Two-way conversion: from Unix to Quartz and Quartz to Unix.
|
|
12
|
+
|
|
13
|
+
### Installation
|
|
14
|
+
|
|
15
|
+
Using npm:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install cron-converter-u2q
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Using yarn:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
yarn add cron-converter-u2q
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Usage
|
|
28
|
+
|
|
29
|
+
Firstly, import the CronConverterU2Q module:
|
|
30
|
+
|
|
31
|
+
```javascript
|
|
32
|
+
var cron_converter_u2q = require("cron-converter-u2q");
|
|
33
|
+
|
|
34
|
+
var c2q = cron_converter_u2q.CronConverterU2Q;
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
If you're using ES6 Modules
|
|
38
|
+
|
|
39
|
+
```javascript
|
|
40
|
+
import { CronConverterU2QModule as c2q } from "cron-converter-u2q";
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Convert from Unix to Quartz
|
|
44
|
+
|
|
45
|
+
```javascript
|
|
46
|
+
const quartzExpression = c2q.unixToQuartz("5 * * * *");
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Convert from Quartz to Unix
|
|
50
|
+
|
|
51
|
+
```javascript
|
|
52
|
+
const unixExpression = c2q.quartzToUnix("* */5 * ? * * *");
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Development Notice
|
|
56
|
+
|
|
57
|
+
This package is still under active development. Some methods and features might not be stable yet. We're working diligently to improve and stabilize the package. Any feedback, suggestions, or contributions are highly appreciated!
|
|
58
|
+
|
|
59
|
+
## License
|
|
60
|
+
|
|
61
|
+
This project is licensed under the [MIT License](https://opensource.org/license/mit/)
|
package/jest.config.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
preset: 'ts-jest',
|
|
3
|
-
testEnvironment: 'node',
|
|
4
|
-
roots: ['./src/'],
|
|
5
|
-
transform: {
|
|
6
|
-
'^.+\\.tsx?$': 'ts-jest'
|
|
7
|
-
},
|
|
8
|
-
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$',
|
|
9
|
-
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
|
|
1
|
+
module.exports = {
|
|
2
|
+
preset: 'ts-jest',
|
|
3
|
+
testEnvironment: 'node',
|
|
4
|
+
roots: ['./src/'],
|
|
5
|
+
transform: {
|
|
6
|
+
'^.+\\.tsx?$': 'ts-jest'
|
|
7
|
+
},
|
|
8
|
+
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$',
|
|
9
|
+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
|
|
10
10
|
};
|
package/package.json
CHANGED
|
@@ -1,82 +1,82 @@
|
|
|
1
|
-
import { CronConverterU2Q as c2q } from '../index';
|
|
2
|
-
|
|
3
|
-
//Basic suite of tests
|
|
4
|
-
describe('Unix2Quartz Conversion', () => {
|
|
5
|
-
|
|
6
|
-
test('Every 5 minutes', () => {
|
|
7
|
-
const result = c2q.unixToQuartz('*/5 * * * *');
|
|
8
|
-
expect(result).toBe("0 */5 * ? * *");
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
test('Everyday at 12pm', () => {
|
|
12
|
-
const result = c2q.unixToQuartz('0 12 * * *');
|
|
13
|
-
expect(result).toBe("0 0 12 ? * *");
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
test('Every Monday at 12pm conversion', () => {
|
|
17
|
-
const result = c2q.unixToQuartz('0 12 * * 1');
|
|
18
|
-
expect(result).toBe("0 0 12 ? * 1");
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
test('Every 10th day of the month conversion', () => {
|
|
22
|
-
const result = c2q.unixToQuartz('0 0 10 * *');
|
|
23
|
-
expect(result).toBe("0 0 0 10 * ?");
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
test('Every January 1st at 12am conversion', () => {
|
|
27
|
-
const result = c2q.unixToQuartz('0 0 1 1 *');
|
|
28
|
-
expect(result).toBe("0 0 0 1 1 ?");
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test('Every last day of the month conversion', () => {
|
|
32
|
-
const result = c2q.unixToQuartz('59 23 L * *');
|
|
33
|
-
expect(result).toBe("0 59 23 L * ?");
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
//Failing test case
|
|
37
|
-
// test('Every last Friday of the month conversion', () => {
|
|
38
|
-
// const result = c2q.unixToQuartz('0 0 L * 5');
|
|
39
|
-
// expect(result).toBe("0 0 0 ? * 5L");
|
|
40
|
-
// });
|
|
41
|
-
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
describe('Quartz2Unix Conversion', () => {
|
|
46
|
-
|
|
47
|
-
test('Every 5 minutes conversion', () => {
|
|
48
|
-
const result = c2q.quartzToUnix('0 */5 * ? * *');
|
|
49
|
-
expect(result).toBe("*/5 * * * *");
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
test('Everyday at 12pm conversion', () => {
|
|
53
|
-
const result = c2q.quartzToUnix('0 0 12 ? * *');
|
|
54
|
-
expect(result).toBe("0 12 * * *");
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
test('Every Monday at 12pm conversion', () => {
|
|
58
|
-
const result = c2q.quartzToUnix('0 0 12 ? * 1');
|
|
59
|
-
expect(result).toBe("0 12 * * 1");
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test('Every 10th day of the month conversion', () => {
|
|
63
|
-
const result = c2q.quartzToUnix('0 0 0 10 * ?');
|
|
64
|
-
expect(result).toBe("0 0 10 * *");
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
test('Every January 1st at 12am conversion', () => {
|
|
68
|
-
const result = c2q.quartzToUnix('0 0 0 1 1 ?');
|
|
69
|
-
expect(result).toBe("0 0 1 1 *");
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test('Every last day of the month conversion', () => {
|
|
73
|
-
const result = c2q.quartzToUnix('0 59 23 L * ?');
|
|
74
|
-
expect(result).toBe("59 23 L * *");
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
//Failing test case
|
|
78
|
-
// test('Every last Friday of the month conversion', () => {
|
|
79
|
-
// const result = c2q.quartzToUnix('0 0 0 ? * 5L');
|
|
80
|
-
// expect(result).toBe("0 0 L * 5");
|
|
81
|
-
// });
|
|
1
|
+
import { CronConverterU2Q as c2q } from '../index';
|
|
2
|
+
|
|
3
|
+
//Basic suite of tests
|
|
4
|
+
describe('Unix2Quartz Conversion', () => {
|
|
5
|
+
|
|
6
|
+
test('Every 5 minutes', () => {
|
|
7
|
+
const result = c2q.unixToQuartz('*/5 * * * *');
|
|
8
|
+
expect(result).toBe("0 */5 * ? * *");
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test('Everyday at 12pm', () => {
|
|
12
|
+
const result = c2q.unixToQuartz('0 12 * * *');
|
|
13
|
+
expect(result).toBe("0 0 12 ? * *");
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('Every Monday at 12pm conversion', () => {
|
|
17
|
+
const result = c2q.unixToQuartz('0 12 * * 1');
|
|
18
|
+
expect(result).toBe("0 0 12 ? * 1");
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test('Every 10th day of the month conversion', () => {
|
|
22
|
+
const result = c2q.unixToQuartz('0 0 10 * *');
|
|
23
|
+
expect(result).toBe("0 0 0 10 * ?");
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('Every January 1st at 12am conversion', () => {
|
|
27
|
+
const result = c2q.unixToQuartz('0 0 1 1 *');
|
|
28
|
+
expect(result).toBe("0 0 0 1 1 ?");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('Every last day of the month conversion', () => {
|
|
32
|
+
const result = c2q.unixToQuartz('59 23 L * *');
|
|
33
|
+
expect(result).toBe("0 59 23 L * ?");
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
//Failing test case
|
|
37
|
+
// test('Every last Friday of the month conversion', () => {
|
|
38
|
+
// const result = c2q.unixToQuartz('0 0 L * 5');
|
|
39
|
+
// expect(result).toBe("0 0 0 ? * 5L");
|
|
40
|
+
// });
|
|
41
|
+
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
describe('Quartz2Unix Conversion', () => {
|
|
46
|
+
|
|
47
|
+
test('Every 5 minutes conversion', () => {
|
|
48
|
+
const result = c2q.quartzToUnix('0 */5 * ? * *');
|
|
49
|
+
expect(result).toBe("*/5 * * * *");
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('Everyday at 12pm conversion', () => {
|
|
53
|
+
const result = c2q.quartzToUnix('0 0 12 ? * *');
|
|
54
|
+
expect(result).toBe("0 12 * * *");
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('Every Monday at 12pm conversion', () => {
|
|
58
|
+
const result = c2q.quartzToUnix('0 0 12 ? * 1');
|
|
59
|
+
expect(result).toBe("0 12 * * 1");
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('Every 10th day of the month conversion', () => {
|
|
63
|
+
const result = c2q.quartzToUnix('0 0 0 10 * ?');
|
|
64
|
+
expect(result).toBe("0 0 10 * *");
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('Every January 1st at 12am conversion', () => {
|
|
68
|
+
const result = c2q.quartzToUnix('0 0 0 1 1 ?');
|
|
69
|
+
expect(result).toBe("0 0 1 1 *");
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('Every last day of the month conversion', () => {
|
|
73
|
+
const result = c2q.quartzToUnix('0 59 23 L * ?');
|
|
74
|
+
expect(result).toBe("59 23 L * *");
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
//Failing test case
|
|
78
|
+
// test('Every last Friday of the month conversion', () => {
|
|
79
|
+
// const result = c2q.quartzToUnix('0 0 0 ? * 5L');
|
|
80
|
+
// expect(result).toBe("0 0 L * 5");
|
|
81
|
+
// });
|
|
82
82
|
});
|
package/src/converter.ts
CHANGED
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
export class CronConverterU2Q {
|
|
2
|
-
|
|
3
|
-
static readonly delimiter = ' ';
|
|
4
|
-
static readonly unixExpressionLength = 5;
|
|
5
|
-
static readonly quartzExpressionLengths = [6, 7];
|
|
6
|
-
static readonly everyXUnitsReplacePlaceholder = `%s`
|
|
7
|
-
static readonly quartzEveryXUnitsRegex = /^0\/(\d+)$/; // For handling 0/5 units
|
|
8
|
-
static readonly unixEveryXUnitsRegex = /^\/(\d+)$/; // For handling */5 units
|
|
9
|
-
static readonly quartzEveryXUnitsReplacePattern = `0/${this.everyXUnitsReplacePlaceholder}`;
|
|
10
|
-
static readonly unixEveryXUnitsReplacePattern = `*/${this.everyXUnitsReplacePlaceholder}`;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Converts a unix cron expression to a quartz cron expression by adding '0' seconds
|
|
14
|
-
* @param unixExpression - the unix expression
|
|
15
|
-
* @returns the corresponding quartz expression
|
|
16
|
-
*/
|
|
17
|
-
public static unixToQuartz(unixExpression: string): string {
|
|
18
|
-
|
|
19
|
-
this.validateIfNullOrEmpty(unixExpression);
|
|
20
|
-
const parts = unixExpression.split(this.delimiter);
|
|
21
|
-
if (parts.length !== this.unixExpressionLength) throw new Error(`Invalid unix cron format`);
|
|
22
|
-
|
|
23
|
-
const [min, hour, dom, month, dow] = parts.map(part => this.convertIntervalParts(part));
|
|
24
|
-
let quartzDom = dom;
|
|
25
|
-
let quartzDow = dow;
|
|
26
|
-
|
|
27
|
-
if (dom !== '*' && dow === '*') quartzDow = '?';
|
|
28
|
-
else if (dom === '*') quartzDom = '?';
|
|
29
|
-
|
|
30
|
-
return `0 ${min} ${hour} ${quartzDom} ${month} ${quartzDow}`;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Converts a quartz cron expression to a unix cron expression
|
|
35
|
-
* @param quartzExpression - the quartz expression
|
|
36
|
-
* @returns the corresponding unix expression
|
|
37
|
-
*/
|
|
38
|
-
public static quartzToUnix(quartzExpression: string): string {
|
|
39
|
-
|
|
40
|
-
this.validateIfNullOrEmpty(quartzExpression);
|
|
41
|
-
const parts = quartzExpression.replace('?', '*').split(this.delimiter);
|
|
42
|
-
if (!this.quartzExpressionLengths.includes(parts.length)) throw new Error(`Invalid quartz cron format`);
|
|
43
|
-
|
|
44
|
-
const [_, min, hour, dom, month, dow] = parts.map(part => this.convertIntervalParts(part, true));
|
|
45
|
-
|
|
46
|
-
return `${min} ${hour} ${dom} ${month} ${dow}`;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
private static validateIfNullOrEmpty(cronExpression: string | undefined | null): void {
|
|
50
|
-
if (!cronExpression || cronExpression.trim() === '') throw new Error('Empty or null expression');
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
private static convertIntervalParts(part: string, isQuartz = false): string {
|
|
54
|
-
part = part.trim();
|
|
55
|
-
|
|
56
|
-
const everyXUnitsPattern = isQuartz ? this.quartzEveryXUnitsRegex : this.unixEveryXUnitsRegex;
|
|
57
|
-
const matches = part.match(everyXUnitsPattern);
|
|
58
|
-
const everyXUnitsReplacePattern = isQuartz ? this.quartzEveryXUnitsReplacePattern : this.unixEveryXUnitsReplacePattern;
|
|
59
|
-
|
|
60
|
-
if (matches) return `${everyXUnitsReplacePattern.replace(this.everyXUnitsReplacePlaceholder, matches[1])}`;
|
|
61
|
-
|
|
62
|
-
return part;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
}
|
|
1
|
+
export class CronConverterU2Q {
|
|
2
|
+
|
|
3
|
+
static readonly delimiter = ' ';
|
|
4
|
+
static readonly unixExpressionLength = 5;
|
|
5
|
+
static readonly quartzExpressionLengths = [6, 7];
|
|
6
|
+
static readonly everyXUnitsReplacePlaceholder = `%s`
|
|
7
|
+
static readonly quartzEveryXUnitsRegex = /^0\/(\d+)$/; // For handling 0/5 units
|
|
8
|
+
static readonly unixEveryXUnitsRegex = /^\/(\d+)$/; // For handling */5 units
|
|
9
|
+
static readonly quartzEveryXUnitsReplacePattern = `0/${this.everyXUnitsReplacePlaceholder}`;
|
|
10
|
+
static readonly unixEveryXUnitsReplacePattern = `*/${this.everyXUnitsReplacePlaceholder}`;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Converts a unix cron expression to a quartz cron expression by adding '0' seconds
|
|
14
|
+
* @param unixExpression - the unix expression
|
|
15
|
+
* @returns the corresponding quartz expression
|
|
16
|
+
*/
|
|
17
|
+
public static unixToQuartz(unixExpression: string): string {
|
|
18
|
+
|
|
19
|
+
this.validateIfNullOrEmpty(unixExpression);
|
|
20
|
+
const parts = unixExpression.split(this.delimiter);
|
|
21
|
+
if (parts.length !== this.unixExpressionLength) throw new Error(`Invalid unix cron format`);
|
|
22
|
+
|
|
23
|
+
const [min, hour, dom, month, dow] = parts.map(part => this.convertIntervalParts(part));
|
|
24
|
+
let quartzDom = dom;
|
|
25
|
+
let quartzDow = dow;
|
|
26
|
+
|
|
27
|
+
if (dom !== '*' && dow === '*') quartzDow = '?';
|
|
28
|
+
else if (dom === '*') quartzDom = '?';
|
|
29
|
+
|
|
30
|
+
return `0 ${min} ${hour} ${quartzDom} ${month} ${quartzDow}`;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Converts a quartz cron expression to a unix cron expression
|
|
35
|
+
* @param quartzExpression - the quartz expression
|
|
36
|
+
* @returns the corresponding unix expression
|
|
37
|
+
*/
|
|
38
|
+
public static quartzToUnix(quartzExpression: string): string {
|
|
39
|
+
|
|
40
|
+
this.validateIfNullOrEmpty(quartzExpression);
|
|
41
|
+
const parts = quartzExpression.replace('?', '*').split(this.delimiter);
|
|
42
|
+
if (!this.quartzExpressionLengths.includes(parts.length)) throw new Error(`Invalid quartz cron format`);
|
|
43
|
+
|
|
44
|
+
const [_, min, hour, dom, month, dow] = parts.map(part => this.convertIntervalParts(part, true));
|
|
45
|
+
|
|
46
|
+
return `${min} ${hour} ${dom} ${month} ${dow}`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private static validateIfNullOrEmpty(cronExpression: string | undefined | null): void {
|
|
50
|
+
if (!cronExpression || cronExpression.trim() === '') throw new Error('Empty or null expression');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
private static convertIntervalParts(part: string, isQuartz = false): string {
|
|
54
|
+
part = part.trim();
|
|
55
|
+
|
|
56
|
+
const everyXUnitsPattern = isQuartz ? this.quartzEveryXUnitsRegex : this.unixEveryXUnitsRegex;
|
|
57
|
+
const matches = part.match(everyXUnitsPattern);
|
|
58
|
+
const everyXUnitsReplacePattern = isQuartz ? this.quartzEveryXUnitsReplacePattern : this.unixEveryXUnitsReplacePattern;
|
|
59
|
+
|
|
60
|
+
if (matches) return `${everyXUnitsReplacePattern.replace(this.everyXUnitsReplacePlaceholder, matches[1])}`;
|
|
61
|
+
|
|
62
|
+
return part;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './converter';
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export * from './converter';
|
|
2
|
+
|
|
3
|
+
|
package/tsconfig.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
/* Language and Environment */
|
|
4
|
-
"target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
|
|
5
|
-
"module": "commonjs" /* Specify what module code is generated. */,
|
|
6
|
-
"outDir": "./lib" /* Specify an output folder for all emitted files. */,
|
|
7
|
-
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
|
|
8
|
-
"declaration": true,
|
|
9
|
-
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
|
10
|
-
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
|
|
11
|
-
|
|
12
|
-
/* Type Checking */
|
|
13
|
-
"strict": true /* Enable all strict type-checking options. */,
|
|
14
|
-
/* Completeness */
|
|
15
|
-
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
|
16
|
-
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
|
17
|
-
},
|
|
18
|
-
"include": ["src/**/*.ts"],
|
|
19
|
-
"exclude": ["node_modules", "**/__tests__/**"]
|
|
20
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
/* Language and Environment */
|
|
4
|
+
"target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
|
|
5
|
+
"module": "commonjs" /* Specify what module code is generated. */,
|
|
6
|
+
"outDir": "./lib" /* Specify an output folder for all emitted files. */,
|
|
7
|
+
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
|
|
8
|
+
"declaration": true,
|
|
9
|
+
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
|
10
|
+
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
|
|
11
|
+
|
|
12
|
+
/* Type Checking */
|
|
13
|
+
"strict": true /* Enable all strict type-checking options. */,
|
|
14
|
+
/* Completeness */
|
|
15
|
+
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
|
16
|
+
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
|
17
|
+
},
|
|
18
|
+
"include": ["src/**/*.ts"],
|
|
19
|
+
"exclude": ["node_modules", "**/__tests__/**"]
|
|
20
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
declare module 'cron-converter-u2q' {
|
|
2
|
-
export const CronConverterU2QModule: {
|
|
3
|
-
unixToQuartz(unixExpression: string): string;
|
|
4
|
-
quartzToUnix(quartzExpression: string): string;
|
|
5
|
-
}
|
|
6
|
-
}
|
|
1
|
+
declare module 'cron-converter-u2q' {
|
|
2
|
+
export const CronConverterU2QModule: {
|
|
3
|
+
unixToQuartz(unixExpression: string): string;
|
|
4
|
+
quartzToUnix(quartzExpression: string): string;
|
|
5
|
+
}
|
|
6
|
+
}
|