UNPKG

cron-time-generator2

Version:
85 lines (84 loc) 2.92 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); // @ts-check const helpers_1 = __importDefault(require("./helpers")); /** * Every Time Class */ class EveryTime { /** * * @param {number[]|string|number} every * @param {{}} config */ constructor(every, config = {}) { this.interval = 1; this.config = {}; if (every === "even") every = 2; this.interval = every; this.config = Object.assign(this.config, config); return this; } /** * Every nth Minute */ minutes() { if (this.config["between"] && Array.isArray(this.interval)) { this.config["between"] = false; return helpers_1.default.spliceIntoPosition(0, this.interval.join("-"), helpers_1.default.minute()); } if (typeof this.interval === "number" && this.interval > 1) { return helpers_1.default.spliceIntoPosition(0, "*/" + this.interval); } else if (this.interval === "uneven") { return helpers_1.default.spliceIntoPosition(0, "1-59/2"); } return helpers_1.default.minute(); } /** * Every nth Hour */ hours() { const hour = helpers_1.default.hour(); if (this.config["between"] && Array.isArray(this.interval)) { this.config["between"] = false; return helpers_1.default.spliceIntoPosition(1, this.interval.join("-"), hour); } if (typeof this.interval === "number" && this.interval > 1) { return helpers_1.default.spliceIntoPosition(1, "*/" + this.interval, hour); } else if (this.interval === "uneven") { return helpers_1.default.spliceIntoPosition(1, "1-23/2", hour); } return hour; } /** * Every nth Days after * @param hoursOfDay * @param $minutesOfDay */ days(hoursOfDay = 0, $minutesOfDay = 0) { const day = helpers_1.default.day(hoursOfDay, $minutesOfDay); // if (this.config["at"]) { // this.config["at"] = false; // // return Helpers.spliceIntoPosition(2, this.config.at, day); // } if (this.config["between"] && Array.isArray(this.interval)) { this.config["between"] = false; return helpers_1.default.spliceIntoPosition(2, this.interval.join("-"), day); } if (typeof this.interval === "number" && this.interval > 1) { return helpers_1.default.spliceIntoPosition(2, "*/" + this.interval, day); } else if (this.interval === "uneven") { return helpers_1.default.spliceIntoPosition(2, "1-31/2", day); } return day; } } exports.default = EveryTime;