import lodash from "lodash";
import { RICOS_VERSION as currentVersion } from "./../../ricos-schema/next-schema/index.js";
const toVersion = (versionString) => {
  return versionString.split(".").map((literal) => {
    const numeric = parseInt(literal, 10);
    return lodash.isNaN(numeric) ? 0 : numeric;
  }).slice(0, 3);
};
const compareVersions = (left, right) => {
  const leftVersion = toVersion(left);
  const rightVersion = toVersion(right);
  const diff = leftVersion.map((left2, idx) => Math.sign(left2 - rightVersion[idx]));
  return diff.find((num) => num !== 0) || 0;
};
const evaluations = {
  "<": (left, right) => compareVersions(left, right) < 0,
  ">": (left, right) => compareVersions(left, right) > 0,
  "=": (left, right) => compareVersions(left, right) === 0,
  "<=": (left, right) => compareVersions(left, right) <= 0,
  ">=": (left, right) => compareVersions(left, right) >= 0
};
const evaluateVersion = (tested, semver) => {
  const [, operator, version] = /([<>=]{0,2})(.*)/gm.exec(semver);
  return evaluations[operator || "="](tested, version);
};
const versioningUtils = {
  lessThan: (left, right) => compareVersions(left, right) < 0,
  greaterThan: (left, right) => compareVersions(left, right) > 0,
  equal: (left, right) => compareVersions(left, right) === 0,
  compare: compareVersions,
  currentVersion,
  evaluate: evaluateVersion
};
export {
  versioningUtils
};
//# sourceMappingURL=versioning-utils.js.map
