cron-converter-u2q 0.1.3 → 0.1.4
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/lib/converter.d.ts +18 -0
- package/lib/converter.js +53 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +15 -55
- package/package.json +1 -1
- package/src/converter.ts +57 -0
- package/src/index.ts +1 -62
- package/tsconfig.json +1 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare class CronConverterU2Q {
|
|
2
|
+
static readonly delimiter = " ";
|
|
3
|
+
static readonly unixExpressionLength = 5;
|
|
4
|
+
static readonly quartzExpressionLengths: number[];
|
|
5
|
+
/**
|
|
6
|
+
* Converts a unix cron expression to a quartz cron expression by adding '0' seconds
|
|
7
|
+
* @param unixExpression - the unix expression
|
|
8
|
+
* @returns the corresponding quartz expression
|
|
9
|
+
*/
|
|
10
|
+
static unixToQuartz(unixExpression: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Converts a quartz cron expression to a unix cron expression
|
|
13
|
+
* @param quartzExpression - the quartz expression
|
|
14
|
+
* @returns the corresponding unix expression
|
|
15
|
+
*/
|
|
16
|
+
static quartzToUnix(quartzExpression: string): string;
|
|
17
|
+
private static validateIfNullOrEmpty;
|
|
18
|
+
}
|
package/lib/converter.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CronConverterU2Q = void 0;
|
|
4
|
+
class CronConverterU2Q {
|
|
5
|
+
/**
|
|
6
|
+
* Converts a unix cron expression to a quartz cron expression by adding '0' seconds
|
|
7
|
+
* @param unixExpression - the unix expression
|
|
8
|
+
* @returns the corresponding quartz expression
|
|
9
|
+
*/
|
|
10
|
+
static unixToQuartz(unixExpression) {
|
|
11
|
+
this.validateIfNullOrEmpty(unixExpression);
|
|
12
|
+
const parts = unixExpression.split(this.delimiter);
|
|
13
|
+
if (parts.length !== this.unixExpressionLength)
|
|
14
|
+
throw new Error(`Invalid unix cron format`);
|
|
15
|
+
const [min, hour, dom, month, dow] = parts;
|
|
16
|
+
let quartzDom = dom;
|
|
17
|
+
let quartzDow = dow;
|
|
18
|
+
if (dom === '*' && (dow === '*' || dow !== '*'))
|
|
19
|
+
quartzDom = '?';
|
|
20
|
+
else if (dom !== '*' && dow === '*')
|
|
21
|
+
quartzDow = '?';
|
|
22
|
+
return `0 ${min} ${hour} ${quartzDom} ${month} ${quartzDow}`;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Converts a quartz cron expression to a unix cron expression
|
|
26
|
+
* @param quartzExpression - the quartz expression
|
|
27
|
+
* @returns the corresponding unix expression
|
|
28
|
+
*/
|
|
29
|
+
static quartzToUnix(quartzExpression) {
|
|
30
|
+
this.validateIfNullOrEmpty(quartzExpression);
|
|
31
|
+
const parts = quartzExpression.split(this.delimiter);
|
|
32
|
+
if (!this.quartzExpressionLengths.includes(parts.length))
|
|
33
|
+
throw new Error(`Invalid quartz cron format`);
|
|
34
|
+
const [_, min, hour, dom, month, dow] = parts;
|
|
35
|
+
let unixDom = dom;
|
|
36
|
+
let unixDow = dow;
|
|
37
|
+
if (dom === '?' && dow === '*')
|
|
38
|
+
unixDom = '*';
|
|
39
|
+
else if (dow === '?' && dom === '*')
|
|
40
|
+
unixDow = '*';
|
|
41
|
+
else if (dom !== '?' && dom === '?')
|
|
42
|
+
unixDom = '*';
|
|
43
|
+
return `${min} ${hour} ${unixDom} ${month} ${unixDow}`;
|
|
44
|
+
}
|
|
45
|
+
static validateIfNullOrEmpty(cronExpression) {
|
|
46
|
+
if (!cronExpression || cronExpression.trim() === '')
|
|
47
|
+
throw new Error('Empty or null expression');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.CronConverterU2Q = CronConverterU2Q;
|
|
51
|
+
CronConverterU2Q.delimiter = ' ';
|
|
52
|
+
CronConverterU2Q.unixExpressionLength = 5;
|
|
53
|
+
CronConverterU2Q.quartzExpressionLengths = [6, 7];
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './converter';
|
package/lib/index.js
CHANGED
|
@@ -1,57 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
this.unixExpressionLength = 5;
|
|
8
|
-
this.quartzExpressionLengths = [6, 7];
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Converts a unix cron expression to a quartz cron expression by adding '0' seconds
|
|
12
|
-
* @param unixExpression - the unix expression
|
|
13
|
-
* @returns the corresponding quartz expression
|
|
14
|
-
*/
|
|
15
|
-
unixToQuartz(unixExpression) {
|
|
16
|
-
this.validateIfNullOrEmpty(unixExpression);
|
|
17
|
-
const parts = unixExpression.split(this.delimiter);
|
|
18
|
-
if (parts.length !== this.unixExpressionLength)
|
|
19
|
-
throw new Error(`Invalid unix cron format`);
|
|
20
|
-
const [min, hour, dom, month, dow] = parts;
|
|
21
|
-
let quartzDom = dom;
|
|
22
|
-
let quartzDow = dow;
|
|
23
|
-
if (dom === '*' && (dow === '*' || dow !== '*'))
|
|
24
|
-
quartzDom = '?';
|
|
25
|
-
else if (dom !== '*' && dow === '*')
|
|
26
|
-
quartzDow = '?';
|
|
27
|
-
return `0 ${min} ${hour} ${quartzDom} ${month} ${quartzDow}`;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Converts a quartz cron expression to a unix cron expression
|
|
31
|
-
* @param quartzExpression - the quartz expression
|
|
32
|
-
* @returns the corresponding unix expression
|
|
33
|
-
*/
|
|
34
|
-
quartzToUnix(quartzExpression) {
|
|
35
|
-
this.validateIfNullOrEmpty(quartzExpression);
|
|
36
|
-
const parts = quartzExpression.split(this.delimiter);
|
|
37
|
-
if (!this.quartzExpressionLengths.includes(parts.length))
|
|
38
|
-
throw new Error(`Invalid quartz cron format`);
|
|
39
|
-
const [_, min, hour, dom, month, dow] = parts;
|
|
40
|
-
let unixDom = dom;
|
|
41
|
-
let unixDow = dow;
|
|
42
|
-
if (dom === '?' && dow === '*')
|
|
43
|
-
unixDom = '*';
|
|
44
|
-
else if (dow === '?' && dom === '*')
|
|
45
|
-
unixDow = '*';
|
|
46
|
-
else if (dom !== '?' && dom === '?')
|
|
47
|
-
unixDom = '*';
|
|
48
|
-
return `${min} ${hour} ${unixDom} ${month} ${unixDow}`;
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
49
7
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./converter"), exports);
|
package/package.json
CHANGED
package/src/converter.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export class CronConverterU2Q {
|
|
2
|
+
|
|
3
|
+
static readonly delimiter = ' ';
|
|
4
|
+
static readonly unixExpressionLength = 5;
|
|
5
|
+
static readonly quartzExpressionLengths = [6, 7];
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Converts a unix cron expression to a quartz cron expression by adding '0' seconds
|
|
9
|
+
* @param unixExpression - the unix expression
|
|
10
|
+
* @returns the corresponding quartz expression
|
|
11
|
+
*/
|
|
12
|
+
public static unixToQuartz(unixExpression: string): string {
|
|
13
|
+
|
|
14
|
+
this.validateIfNullOrEmpty(unixExpression);
|
|
15
|
+
|
|
16
|
+
const parts = unixExpression.split(this.delimiter);
|
|
17
|
+
if (parts.length !== this.unixExpressionLength) throw new Error(`Invalid unix cron format`);
|
|
18
|
+
|
|
19
|
+
const [min, hour, dom, month, dow] = parts;
|
|
20
|
+
let quartzDom = dom;
|
|
21
|
+
let quartzDow = dow;
|
|
22
|
+
|
|
23
|
+
if (dom === '*' && (dow === '*' || dow !== '*')) quartzDom = '?';
|
|
24
|
+
else if (dom !== '*' && dow === '*') quartzDow = '?';
|
|
25
|
+
|
|
26
|
+
return `0 ${min} ${hour} ${quartzDom} ${month} ${quartzDow}`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Converts a quartz cron expression to a unix cron expression
|
|
31
|
+
* @param quartzExpression - the quartz expression
|
|
32
|
+
* @returns the corresponding unix expression
|
|
33
|
+
*/
|
|
34
|
+
public static quartzToUnix(quartzExpression: string): string {
|
|
35
|
+
|
|
36
|
+
this.validateIfNullOrEmpty(quartzExpression);
|
|
37
|
+
|
|
38
|
+
const parts = quartzExpression.split(this.delimiter);
|
|
39
|
+
|
|
40
|
+
if (!this.quartzExpressionLengths.includes(parts.length)) throw new Error(`Invalid quartz cron format`);
|
|
41
|
+
|
|
42
|
+
const [_, min, hour, dom, month, dow] = parts;
|
|
43
|
+
let unixDom = dom;
|
|
44
|
+
let unixDow = dow;
|
|
45
|
+
|
|
46
|
+
if (dom === '?' && dow === '*') unixDom = '*';
|
|
47
|
+
else if (dow === '?' && dom === '*') unixDow = '*';
|
|
48
|
+
else if (dom !== '?' && dom === '?') unixDom = '*';
|
|
49
|
+
|
|
50
|
+
return `${min} ${hour} ${unixDom} ${month} ${unixDow}`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
private static validateIfNullOrEmpty(cronExpression: string | undefined | null): void {
|
|
54
|
+
if (!cronExpression || cronExpression.trim() === '') throw new Error('Empty or null expression');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,64 +1,3 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './converter';
|
|
2
2
|
|
|
3
|
-
static readonly delimiter = ' ';
|
|
4
|
-
static readonly unixExpressionLength = 5;
|
|
5
|
-
static readonly quartzExpressionLengths = [6, 7];
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Converts a unix cron expression to a quartz cron expression by adding '0' seconds
|
|
9
|
-
* @param unixExpression - the unix expression
|
|
10
|
-
* @returns the corresponding quartz expression
|
|
11
|
-
*/
|
|
12
|
-
public static unixToQuartz(unixExpression: string): string {
|
|
13
|
-
|
|
14
|
-
this.validateIfNullOrEmpty(unixExpression);
|
|
15
|
-
|
|
16
|
-
const parts = unixExpression.split(this.delimiter);
|
|
17
|
-
if (parts.length !== this.unixExpressionLength) throw new Error(`Invalid unix cron format`);
|
|
18
|
-
|
|
19
|
-
const [min, hour, dom, month, dow] = parts;
|
|
20
|
-
let quartzDom = dom;
|
|
21
|
-
let quartzDow = dow;
|
|
22
|
-
|
|
23
|
-
if (dom === '*' && (dow === '*' || dow !== '*')) quartzDom = '?';
|
|
24
|
-
else if (dom !== '*' && dow === '*') quartzDow = '?';
|
|
25
|
-
|
|
26
|
-
return `0 ${min} ${hour} ${quartzDom} ${month} ${quartzDow}`;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Converts a quartz cron expression to a unix cron expression
|
|
31
|
-
* @param quartzExpression - the quartz expression
|
|
32
|
-
* @returns the corresponding unix expression
|
|
33
|
-
*/
|
|
34
|
-
public static quartzToUnix(quartzExpression: string): string {
|
|
35
|
-
|
|
36
|
-
this.validateIfNullOrEmpty(quartzExpression);
|
|
37
|
-
|
|
38
|
-
const parts = quartzExpression.split(this.delimiter);
|
|
39
|
-
|
|
40
|
-
if (!this.quartzExpressionLengths.includes(parts.length)) throw new Error(`Invalid quartz cron format`);
|
|
41
|
-
|
|
42
|
-
const [_, min, hour, dom, month, dow] = parts;
|
|
43
|
-
let unixDom = dom;
|
|
44
|
-
let unixDow = dow;
|
|
45
|
-
|
|
46
|
-
if (dom === '?' && dow === '*') unixDom = '*';
|
|
47
|
-
else if (dow === '?' && dom === '*') unixDow = '*';
|
|
48
|
-
else if (dom !== '?' && dom === '?') unixDom = '*';
|
|
49
|
-
|
|
50
|
-
return `${min} ${hour} ${unixDom} ${month} ${unixDow}`;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
private static validateIfNullOrEmpty(cronExpression: string | undefined | null): void {
|
|
54
|
-
if (!cronExpression || cronExpression.trim() === '') throw new Error('Empty or null expression');
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export const CronConverterU2QModule = CronConverterU2Q;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
// if (process.env.NODE_ENV === 'development') {
|
|
63
|
-
// }
|
|
64
3
|
|
package/tsconfig.json
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
"module": "commonjs" /* Specify what module code is generated. */,
|
|
6
6
|
"outDir": "./lib" /* Specify an output folder for all emitted files. */,
|
|
7
7
|
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
|
|
8
|
+
"declaration": true,
|
|
8
9
|
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
|
9
10
|
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
|
|
10
11
|
|