mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-12 15:04:52 +09:00
Move all functions and classes currently available through lib/name and libName to be under a single flat namespace in lib. This make reorganising the lib namespace much simpler as the location of symbols can move without breaking the consumers of lib. The multi-entrypoint design was already problematic for the web plugin system which couldn't effectively use it due to how webpack's shared module system is awkward to set up with multiple entrypoints per package.
45 lines
1.4 KiB
JavaScript
45 lines
1.4 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.
|
|
* @alias module:lib.integerModVersion
|
|
*/
|
|
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.
|
|
* @alias module:lib.integerFactorioVersion
|
|
*/
|
|
function integerFactorioVersion(version) {
|
|
const [main, major, minor] = version.split(".").map(n => Number.parseInt(n, 10));
|
|
return main * 0x100000000 + major * 0x10000 + (minor || 0); // Can't use bitwise here because this is 48-bits.
|
|
}
|
|
|
|
/**
|
|
* Matches valid mod versions.
|
|
* @type {RegExp}
|
|
* @alias module:lib.modVersionRegExp
|
|
*/
|
|
const modVersionRegExp = /^\d+\.\d+\.\d+$/;
|
|
|
|
module.exports = {
|
|
integerModVersion,
|
|
integerFactorioVersion,
|
|
modVersionRegExp,
|
|
};
|