import CronParser from 'cron-parser';

"use strict";
const cronRule = {
  // eslint-disable-next-line no-empty-pattern
  validator({}, value) {
    if (!value) {
      return Promise.resolve();
    }
    const values = value.split(" ").filter((item) => !!item);
    if (values.length > 7) {
      return Promise.reject("Cron\u8868\u8FBE\u5F0F\u6700\u591A7\u9879\uFF01");
    }
    let val = value;
    if (values.length === 7) {
      const year = values[6];
      if (year !== "*" && year !== "?") {
        let yearValues = [];
        if (year.indexOf("-") >= 0) {
          yearValues = year.split("-");
        } else if (year.indexOf("/")) {
          yearValues = year.split("/");
        } else {
          yearValues = [year];
        }
        const checkYear = yearValues.some((item) => isNaN(Number(item)));
        if (checkYear) {
          return Promise.reject("Cron\u8868\u8FBE\u5F0F\u53C2\u6570[\u5E74]\u9519\u8BEF\uFF1A" + year);
        }
      }
      val = values.slice(0, 6).join(" ");
    }
    try {
      const iter = CronParser.parseExpression(val);
      iter.next();
      return Promise.resolve();
    } catch (e) {
      return Promise.reject("Cron\u8868\u8FBE\u5F0F\u9519\u8BEF\uFF1A" + e);
    }
  }
};
var validator = cronRule.validator;

export { validator as default };
//# sourceMappingURL=validator.mjs.map
