Files
factorio-clusterio/packages/lib/data/version.js
T
Hornwitser 7d34c60dd1 Break out version to integer functions
Move the multiple implementation of version to integers calculation to
dedicated functions in one place.
2022-09-25 23:33:22 +02:00

35 lines
1.1 KiB
JavaScript

// Helper functions for dealing with factorio version numbers
"use strict";
/**
* Integer representation of a mod version
*
* Suitable for sorting and comparing version numbers which may have different
* number of leading zeros in them.
* @param {string} version - string representation of version.
* @returns {number} numeric representation.
*/
function integerModVersion(version) {
const [major, minor, sub] = version.split(".").map(n => Number.parseInt(n, 10));
return major * 0x100000000 + minor * 0x10000 + sub; // Can't use bitwise here because this is 48-bits.
}
/**
* Integer representation of a factorio version
*
* Suitable for sorting and comparing version numbers which may have different
* number of leading zeros in them.
* @param {string} version - string representation of version.
* @returns {number} numeric representation.
*/
function integerFactorioVersion(version) {
const [major, minor, sub] = version.split(".").map(n => Number.parseInt(n, 10));
return major * 0x100000000 + minor * 0x10000 + (sub || 0); // Can't use bitwise here because this is 48-bits.
}
module.exports = {
integerModVersion,
integerFactorioVersion,
};