UNPKG

schoolx-ota-manager

Version:

React Native library for managing OTA updates with GitLab integration

38 lines 1.43 kB
export class VersionChecker { static compareVersions(version1, version2) { const v1 = version1.split('.').map(Number); const v2 = version2.split('.').map(Number); for (let i = 0; i < Math.max(v1.length, v2.length); i++) { const num1 = v1[i] || 0; const num2 = v2[i] || 0; if (num1 > num2) return 1; if (num1 < num2) return -1; } return 0; } static satisfiesRange(appVersion, targetVersion) { if (!targetVersion.match(/^[<>=]/)) { return this.compareVersions(appVersion, targetVersion) === 0; } const match = targetVersion.match(/^([<>=]+)(.+)$/); if (!match) return false; const [_, operator, version] = match; const comparison = this.compareVersions(appVersion, version); switch (operator) { case '>': return comparison > 0; case '>=': return comparison >= 0; case '<': return comparison < 0; case '<=': return comparison <= 0; default: return false; } } static isCompatible(appVersion, targetVersion, buildNumber, installedBuildNumber, enabled) { return (this.satisfiesRange(appVersion, targetVersion) && buildNumber > installedBuildNumber && enabled); } } //# sourceMappingURL=VersionChecker.js.map