cron-time-generator
Advanced tools
Comparing version 2.0.2 to 2.0.3
@@ -81,12 +81,3 @@ "use strict"; | ||
days = [days]; | ||
const newDays = []; | ||
for (const day of days) { | ||
if (typeof day === "string") { | ||
newDays.push(this.dayToInt(day)); | ||
} | ||
else { | ||
newDays.push(day); | ||
} | ||
} | ||
return newDays; | ||
return days.map((day) => this.dayToInt(day)); | ||
}, | ||
@@ -93,0 +84,0 @@ /** |
@@ -37,6 +37,2 @@ import EveryTime from "./EveryTime"; | ||
/** | ||
* Every Sunday | ||
*/ | ||
static everySunday(): string; | ||
/** | ||
* Every Sunday At | ||
@@ -48,5 +44,5 @@ * @param {number|number[]} hoursOfTheDay - Hours Of the Day | ||
/** | ||
* Every Monday | ||
* Every Sunday | ||
*/ | ||
static everyMonday(): string; | ||
static everySunday(): string; | ||
/** | ||
@@ -59,5 +55,5 @@ * Every Monday At | ||
/** | ||
* Every Tuesday | ||
* Every Monday | ||
*/ | ||
static everyTuesday(): string; | ||
static everyMonday(): string; | ||
/** | ||
@@ -70,5 +66,5 @@ * Every Tuesday At | ||
/** | ||
* Every Wednesday | ||
* Every Tuesday | ||
*/ | ||
static everyWednesday(): string; | ||
static everyTuesday(): string; | ||
/** | ||
@@ -81,5 +77,5 @@ * Every Wednesday At | ||
/** | ||
* Every Thursday | ||
* Every Wednesday | ||
*/ | ||
static everyThursday(): string; | ||
static everyWednesday(): string; | ||
/** | ||
@@ -92,5 +88,5 @@ * Every Thursday At | ||
/** | ||
* Every Friday | ||
* Every Thursday | ||
*/ | ||
static everyFriday(): string; | ||
static everyThursday(): string; | ||
/** | ||
@@ -103,5 +99,5 @@ * Every Friday At | ||
/** | ||
* Every Saturday | ||
* Every Friday | ||
*/ | ||
static everySaturday(): string; | ||
static everyFriday(): string; | ||
/** | ||
@@ -114,2 +110,6 @@ * Every Saturday At | ||
/** | ||
* Every Saturday | ||
*/ | ||
static everySaturday(): string; | ||
/** | ||
* On Specific Days | ||
@@ -116,0 +116,0 @@ * @param {(string|number)[]} days |
@@ -76,11 +76,5 @@ "use strict"; | ||
static everyDayAt(hoursOfTheDay, minutesOfTheHour = 0) { | ||
return `${minutesOfTheHour} ${hoursOfTheDay} * * *`; | ||
return helpers_1.default.day(hoursOfTheDay, minutesOfTheHour); | ||
} | ||
/** | ||
* Every Sunday | ||
*/ | ||
static everySunday() { | ||
return CronTime.everySundayAt(0); | ||
} | ||
/** | ||
* Every Sunday At | ||
@@ -94,6 +88,6 @@ * @param {number|number[]} hoursOfTheDay - Hours Of the Day | ||
/** | ||
* Every Monday | ||
* Every Sunday | ||
*/ | ||
static everyMonday() { | ||
return CronTime.everyMondayAt(0); | ||
static everySunday() { | ||
return CronTime.everySundayAt(0); | ||
} | ||
@@ -109,6 +103,6 @@ /** | ||
/** | ||
* Every Tuesday | ||
* Every Monday | ||
*/ | ||
static everyTuesday() { | ||
return CronTime.everyTuesdayAt(0); | ||
static everyMonday() { | ||
return CronTime.everyMondayAt(0); | ||
} | ||
@@ -124,6 +118,6 @@ /** | ||
/** | ||
* Every Wednesday | ||
* Every Tuesday | ||
*/ | ||
static everyWednesday() { | ||
return CronTime.everyWednesdayAt(0); | ||
static everyTuesday() { | ||
return CronTime.everyTuesdayAt(0); | ||
} | ||
@@ -139,6 +133,6 @@ /** | ||
/** | ||
* Every Thursday | ||
* Every Wednesday | ||
*/ | ||
static everyThursday() { | ||
return CronTime.everyThursdayAt(0); | ||
static everyWednesday() { | ||
return CronTime.everyWednesdayAt(0); | ||
} | ||
@@ -154,6 +148,6 @@ /** | ||
/** | ||
* Every Friday | ||
* Every Thursday | ||
*/ | ||
static everyFriday() { | ||
return CronTime.everyFridayAt(0); | ||
static everyThursday() { | ||
return CronTime.everyThursdayAt(0); | ||
} | ||
@@ -169,6 +163,6 @@ /** | ||
/** | ||
* Every Saturday | ||
* Every Friday | ||
*/ | ||
static everySaturday() { | ||
return CronTime.everySaturdayAt(0); | ||
static everyFriday() { | ||
return CronTime.everyFridayAt(0); | ||
} | ||
@@ -184,2 +178,8 @@ /** | ||
/** | ||
* Every Saturday | ||
*/ | ||
static everySaturday() { | ||
return CronTime.everySaturdayAt(0); | ||
} | ||
/** | ||
* On Specific Days | ||
@@ -186,0 +186,0 @@ * @param {(string|number)[]} days |
126
dist/test.js
@@ -8,6 +8,58 @@ "use strict"; | ||
const index_1 = __importDefault(require("./index")); | ||
const tests = [ | ||
const cron_validator_1 = require("cron-validator"); | ||
const helpers_1 = __importDefault(require("./helpers")); | ||
const HelpersTests = [ | ||
{ | ||
title: "everyMinute", | ||
title: `spliceIntoPosition(0, "2")`, | ||
expects: "2 * * * *", | ||
test: () => helpers_1.default.spliceIntoPosition(0, "2") | ||
}, | ||
{ | ||
title: `spliceIntoPosition(4, "5")`, | ||
expects: "* * * * 5", | ||
test: () => helpers_1.default.spliceIntoPosition(4, "5") | ||
}, | ||
{ | ||
title: "minute()", | ||
expects: "* * * * *", | ||
test: () => helpers_1.default.minute() | ||
}, | ||
{ | ||
title: "hour()", | ||
expects: "0 * * * *", | ||
test: () => helpers_1.default.hour() | ||
}, | ||
{ | ||
title: "day(10, 30)", | ||
expects: "30 10 * * *", | ||
test: () => helpers_1.default.day(10, 30) | ||
}, | ||
{ | ||
title: `dayToInt(0) === dayToInt("sunday")`, | ||
expects: true, | ||
test: () => helpers_1.default.dayToInt(0) === helpers_1.default.dayToInt("sunday") | ||
}, | ||
{ | ||
title: `dayToInt(...) using all days`, | ||
expects: [0, 1, 2, 3, 4, 5, 6], | ||
test: () => ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"].map(helpers_1.default.dayToInt) | ||
}, | ||
{ | ||
title: `daysToIntegers(["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"])`, | ||
expects: [0, 1, 2, 3, 4, 5, 6], | ||
test: () => helpers_1.default.daysToIntegers([ | ||
"sunday", | ||
"monday", | ||
"tuesday", | ||
"wednesday", | ||
"thursday", | ||
"friday", | ||
"saturday" | ||
]) | ||
} | ||
]; | ||
const MethodsTests = [ | ||
{ | ||
title: "everyMinute()", | ||
expects: "* * * * *", | ||
test: () => index_1.default.everyMinute() | ||
@@ -26,2 +78,7 @@ }, | ||
{ | ||
title: "everyHourAt(10, 20, 30) - Multiple minutes of an hour", | ||
expects: "10,20,30 * * * *", | ||
test: () => index_1.default.everyHourAt([10, 20, 30]) | ||
}, | ||
{ | ||
title: "everyDay()", | ||
@@ -37,2 +94,7 @@ expects: "0 0 * * *", | ||
{ | ||
title: "everyDayAt([6, 9, 12], [10, 30]) - Multiple hours and minutes of a day", | ||
expects: "10,30 6,9,12 * * *", | ||
test: () => index_1.default.everyDayAt([6, 9, 12], [10, 30]) | ||
}, | ||
{ | ||
title: "everySunday()", | ||
@@ -48,2 +110,7 @@ expects: "0 0 * * 0", | ||
{ | ||
title: "everySundayAt([9, 10, 11], [30, 45]) - Multiple hours and minutes of a day", | ||
expects: "30,45 9,10,11 * * 0", | ||
test: () => index_1.default.everySundayAt([9, 10, 11], [30, 45]) | ||
}, | ||
{ | ||
title: "everyMonday()", | ||
@@ -59,2 +126,7 @@ expects: "0 0 * * 1", | ||
{ | ||
title: "everyMondayAt([9, 10, 11], [30, 45]) - Multiple hours and minutes of a day", | ||
expects: "30,45 9,10,11 * * 1", | ||
test: () => index_1.default.everyMondayAt([9, 10, 11], [30, 45]) | ||
}, | ||
{ | ||
title: "everyTuesday", | ||
@@ -70,2 +142,7 @@ expects: "0 0 * * 2", | ||
{ | ||
title: "everyTuesdayAt([9, 10, 11], [30, 45]) - Multiple hours and minutes of a day", | ||
expects: "30,45 9,10,11 * * 2", | ||
test: () => index_1.default.everyTuesdayAt([9, 10, 11], [30, 45]) | ||
}, | ||
{ | ||
title: "everyWednesday", | ||
@@ -81,2 +158,7 @@ expects: "0 0 * * 3", | ||
{ | ||
title: "everyWednesdayAt([9, 10, 11], [30, 45]) - Multiple hours and minutes of a day", | ||
expects: "30,45 9,10,11 * * 3", | ||
test: () => index_1.default.everyWednesdayAt([9, 10, 11], [30, 45]) | ||
}, | ||
{ | ||
title: "everyThursday", | ||
@@ -92,2 +174,7 @@ expects: "0 0 * * 4", | ||
{ | ||
title: "everyThursdayAt([9, 10, 11], [30, 45]) - Multiple hours and minutes of a day", | ||
expects: "30,45 9,10,11 * * 4", | ||
test: () => index_1.default.everyThursdayAt([9, 10, 11], [30, 45]) | ||
}, | ||
{ | ||
title: "everyFriday", | ||
@@ -103,2 +190,7 @@ expects: "0 0 * * 5", | ||
{ | ||
title: "everyFridayAt([9, 10, 11], [30, 45]) - Multiple hours and minutes of a day", | ||
expects: "30,45 9,10,11 * * 5", | ||
test: () => index_1.default.everyFridayAt([9, 10, 11], [30, 45]) | ||
}, | ||
{ | ||
title: "everySaturday", | ||
@@ -114,2 +206,7 @@ expects: "0 0 * * 6", | ||
{ | ||
title: "everySaturdayAt([9, 10, 11], [30, 45]) - Multiple hours and minutes of a day", | ||
expects: "30,45 9,10,11 * * 6", | ||
test: () => index_1.default.everySaturdayAt([9, 10, 11], [30, 45]) | ||
}, | ||
{ | ||
title: "onSpecificDays(['monday', 'wednesday', 'friday'])", | ||
@@ -175,9 +272,28 @@ expects: "0 0 * * 1,3,5", | ||
]; | ||
// add expectsType to MethodsTests | ||
for (const test of MethodsTests) | ||
test.expectsType = "cron"; | ||
/** | ||
* Test Runner | ||
* @param tests | ||
*/ | ||
function runTests(tests) { | ||
for (const cron of tests) { | ||
test(`${cron.title} => [${cron.expects}]`, (assert) => { | ||
assert.equal(cron.test(), cron.expects); | ||
const title = `${cron.title} => [${cron.expects}]`; | ||
const expectsCron = cron.expectsType === "cron"; | ||
test(title, (assert) => { | ||
// check if expects is a valid cron | ||
if (expectsCron && !(0, cron_validator_1.isValidCron)(cron.expects)) | ||
throw new Error(`Invalid expects cron: ${cron.expects}`); | ||
const value = cron.test(); | ||
// if string, check if valid cron | ||
if (expectsCron) | ||
assert.isTrue((0, cron_validator_1.isValidCron)(value)); | ||
assert.deepEqual(value, cron.expects); | ||
}); | ||
} | ||
} | ||
runTests(tests); | ||
/** | ||
* Run Tests | ||
*/ | ||
runTests([].concat(HelpersTests, MethodsTests)); |
{ | ||
"name": "cron-time-generator", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"description": "Cron Time Expression Generator", | ||
@@ -26,2 +26,3 @@ "main": "./dist/index.js", | ||
"@types/node": "^20.4.2", | ||
"cron-validator": "^1.3.1", | ||
"japa": "^4.0.0", | ||
@@ -28,0 +29,0 @@ "prettier": "^3.0.0", |
46966
1161
5