Port remaining lib/data modules to TypeScript

This commit is contained in:
Hornwitser committed 2023-08-11 01:13:38 +02:00
1 parent 2a52a82fb7
commit 679c00527f
6 files changed
+156 -227

No files matched your search

-46
View File
@@ -1,46 +0,0 @@
"use strict";
/**
* Export manifest for a mod pack
*
* Tracks files stored on disk for data that extracted from Factorio using a
* given mod pack.
* @alias module:lib.ExportManifest
*/
class ExportManifest {
/**
* Mapping between known assets and their file names.
*
* Currently exported assets are
* - settings: JSON of mod settings prototypes.
* - prototypes: JSON of all game prototypes except settings.
* - item-spritesheet: PNG containing icons from the game.
* - item-metadata: JSON of Map entries describing icons in item-spritesheet
* - locale: JSON of flattened Map entries of en locale strings from the game.
* @type {Object<string, string>}
*/
assets = {};
constructor(assets) {
if (assets) { this.assets = assets; }
}
static jsonSchema = {
type: "object",
additionalProperties: false,
required: ["assets"],
properties: {
"assets": {
type: "object",
additionalProperties: { type: "string" },
},
},
};
static fromJSON(json) {
return new this(json.assets);
}
}
module.exports = ExportManifest;
+33
View File
@@ -0,0 +1,33 @@
import { Type, Static } from "@sinclair/typebox";
/**
* Export manifest for a mod pack
*
* Tracks files stored on disk for data that extracted from Factorio using a
* given mod pack.
*/
export default class ExportManifest {
constructor(
/**
* Mapping between known assets and their file names.
*
* Currently exported assets are
* - settings: JSON of mod settings prototypes.
* - prototypes: JSON of all game prototypes except settings.
* - item-spritesheet: PNG containing icons from the game.
* - item-metadata: JSON of Map entries describing icons in item-spritesheet
* - locale: JSON of flattened Map entries of en locale strings from the game.
*/
public assets: Record<string, string>
) {
if (assets) { this.assets = assets; }
}
static jsonSchema = Type.Object({
"assets": Type.Record(Type.String(), Type.String()),
});
static fromJSON(json: Static<typeof ExportManifest.jsonSchema>) {
return new this(json.assets);
}
}
@@ -1,13 +1,12 @@
"use strict"; import fs from "fs-extra";
const fs = require("fs-extra"); import JSZip from "jszip";
const JSZip = require("jszip"); import { Type, Static } from "@sinclair/typebox";
const path = require("path");
const libHash = require("../hash"); import * as libHash from "../hash";
const libSchema = require("../schema"); import * as libSchema from "../schema";
const { findRoot } = require("../zip_ops"); import { findRoot } from "../zip_ops";
const { integerModVersion, integerFactorioVersion, modVersionRegExp } = require("./version"); import { integerModVersion, integerFactorioVersion, modVersionRegExp } from "./version";
/** /**
@@ -15,27 +14,23 @@ const { integerModVersion, integerFactorioVersion, modVersionRegExp } = require(
* *
* See https://wiki.factorio.com/Tutorial:Mod_structure#info.json for * See https://wiki.factorio.com/Tutorial:Mod_structure#info.json for
* details of the invidiual fields sourced from info.json. * details of the invidiual fields sourced from info.json.
* @alias module:lib.ModInfo
*/ */
class ModInfo { export default class ModInfo {
/** /**
* Internal name of this mod. * Internal name of this mod.
* This is the name of the zip file as well as the name that appears in * This is the name of the zip file as well as the name that appears in
* info.json. * info.json.
* @type {string}
*/ */
name = ""; name = "";
/** /**
* Version of the mod. * Version of the mod.
* Sourced from info.json. * Sourced from info.json.
* @type {string}
*/ */
version = ""; version = "";
/** /**
* Integer representation of the version * Integer representation of the version
* @type {number}
*/ */
get integerVersion() { get integerVersion() {
return integerModVersion(this.version); return integerModVersion(this.version);
@@ -44,42 +39,36 @@ class ModInfo {
/** /**
* Display name of the mod. * Display name of the mod.
* Sourced from info.json. * Sourced from info.json.
* @type {string}
*/ */
title = ""; title = "";
/** /**
* Author of the mod. * Author of the mod.
* Sourced from info.json. * Sourced from info.json.
* @type {string}
*/ */
author = ""; author = "";
/** /**
* Contact field for mod. * Contact field for mod.
* Sourced from info.json. * Sourced from info.json.
* @type {string}
*/ */
contact = ""; contact = "";
/** /**
* Homepage of the mod. * Homepage of the mod.
* Sourced from info.json. * Sourced from info.json.
* @type {string}
*/ */
homepage = ""; homepage = "";
/** /**
* Description of the mod. * Description of the mod.
* Sourced from info.json. * Sourced from info.json.
* @type {string}
*/ */
description = ""; description = "";
/** /**
* Major version of Factorio this mod supports. * Major version of Factorio this mod supports.
* Sourced from info.json. * Sourced from info.json.
* @type {string}
*/ */
factorioVersion = "0.12"; factorioVersion = "0.12";
@@ -94,13 +83,11 @@ class ModInfo {
/** /**
* Dependiences for this mod. * Dependiences for this mod.
* Sourced from info.json. * Sourced from info.json.
* @type {Array<string>}
*/ */
dependencies = ["base"]; dependencies = ["base"];
/** /**
* Expected name of zip file containing this mod. * Expected name of zip file containing this mod.
* @type {number}
*/ */
get filename() { get filename() {
return `${this.name}_${this.version}.zip`; return `${this.name}_${this.version}.zip`;
@@ -108,54 +95,44 @@ class ModInfo {
/** /**
* Size of the mod in bytes * Size of the mod in bytes
* @type {number}
*/ */
size = 0; size = 0;
/** /**
* SHA1 hash of this mod * SHA1 hash of this mod
* @type {string=}
*/ */
sha1; sha1: string;
/** /**
* True if this mod has been deleted * True if this mod has been deleted
* @type {boolean}
*/ */
isDeleted = false; isDeleted = false;
// Content of info.json found in mod files // Content of info.json found in mod files
static infoJsonSchema = { static infoJsonSchema = Type.Object({
type: "object", "name": Type.String(),
required: ["name", "version", "title", "author"], "version": Type.String(),
properties: { "title": Type.String(),
"name": { type: "string" }, "author": Type.String(),
"version": { type: "string" }, "contact": Type.Optional(Type.String()),
"title": { type: "string" }, "homepage": Type.Optional(Type.String()),
"author": { type: "string" }, "description": Type.Optional(Type.String()),
"contact": { type: "string" }, "factorio_version": Type.Optional(Type.String()),
"homepage": { type: "string" }, "dependencies": Type.Optional(Type.Array(Type.String())),
"description": { type: "string" }, });
"factorio_version": { type: "string" },
"dependencies": { type: "array", items: { type: "string" } },
},
};
static validateInfo = libSchema.compile(this.infoJsonSchema); static validateInfo = libSchema.compile<Static<typeof this.infoJsonSchema>>(this.infoJsonSchema as any);
static jsonSchema = { static jsonSchema = Type.Object({
type: "object", ...this.infoJsonSchema.properties,
properties: { "size": Type.Optional(Type.Integer()),
...this.infoJsonSchema.properties, "sha1": Type.Optional(Type.String()),
"size": { type: "integer" }, "is_deleted": Type.Optional(Type.Boolean()),
"sha1": { type: "string" }, });
"is_deleted": { type: "boolean" },
},
};
static validate = libSchema.compile(this.jsonSchema); static validate = libSchema.compile(this.jsonSchema as any);
static fromJSON(json) { static fromJSON(json: Static<typeof ModInfo.jsonSchema>) {
const modInfo = new this(); const modInfo = new this();
// info.json fields // info.json fields
@@ -178,7 +155,7 @@ class ModInfo {
} }
toJSON() { toJSON() {
let json = { let json: Static<typeof ModInfo.jsonSchema> = {
name: this.name, name: this.name,
version: this.version, version: this.version,
title: this.title, title: this.title,
@@ -187,7 +164,7 @@ class ModInfo {
if (this.contact) { json.contact = this.contact; } if (this.contact) { json.contact = this.contact; }
if (this.homepage) { json.homepage = this.homepage; } if (this.homepage) { json.homepage = this.homepage; }
if (this.description) { json.description = this.description; } if (this.description) { json.description = this.description; }
if (this.factorio_version !== "0.12") { json.factorio_version = this.factorioVersion; } if (this.factorioVersion !== "0.12") { json.factorio_version = this.factorioVersion; }
if (this.dependencies.length !== 1 || this.dependencies[0] !== "base") { if (this.dependencies.length !== 1 || this.dependencies[0] !== "base") {
json.dependencies = this.dependencies; json.dependencies = this.dependencies;
} }
@@ -198,7 +175,7 @@ class ModInfo {
} }
static async fromModFile(modPath) { static async fromModFile(modPath) {
let modInfo; let modInfo: Static<typeof ModInfo.jsonSchema>;
{ {
// XXX: JSZip needs the whole archive loaded in memory to work. // XXX: JSZip needs the whole archive loaded in memory to work.
// This is clearly untenable and will be replaced later. // This is clearly untenable and will be replaced later.
@@ -231,5 +208,3 @@ class ModInfo {
}); });
} }
} }
module.exports = ModInfo;
@@ -1,84 +1,81 @@
"use strict"; "use strict";
const zlib = require("zlib"); import zlib from "zlib";
import { Type, Static } from "@sinclair/typebox";
const libSchema = require("../schema"); import * as libSchema from "../schema";
const ExportManifest = require("./ExportManifest"); import ExportManifest from "./ExportManifest";
const { integerFactorioVersion } = require("./version"); import { integerFactorioVersion } from "./version";
import type { Logger } from "../logging";
/** /**
* A setting for a mod. * A setting for a mod.
* @typedef {object} module:lib.ModPack~ModSetting
* @property {boolean|number|string} value - Value of the given mod setting.
*/ */
const ModSettingJsonSchema = { interface ModSetting {
type: "object", /** Value of the given mod setting. */
additionalProperties: false, value: boolean | number | string;
required: ["value"], }
properties: {
"value": { type: ["boolean", "number", "string"] },
},
};
const ModSettingsJsonSchema = { const ModSettingJsonSchema = Type.Object({
type: "object", "value": Type.Union([Type.Boolean(), Type.Number(), Type.String()]),
additionalProperties: ModSettingJsonSchema, });
};
const ModSettingsJsonSchema = Type.Record(Type.String(), ModSettingJsonSchema);
/** /**
* A mod in a mod pack * A mod in a mod pack
* @typedef {object} module:lib.ModPack~ModRecord
* @property {string} name - name of the mod.
* @property {boolean} enabled - if mod is to be loaded.
* @property {string} version - version of the mod.
* @property {string=} sha1 - SHA1 hash of the zip file.
*/ */
const ModRecordJsonSchema = { interface ModRecord {
type: "object", /** name of the mod. */
required: ["name", "enabled", "version"], name: string,
properties: { /** if mod is to be loaded. */
"name": { type: "string" }, enabled: boolean,
"enabled": { type: "boolean" }, /** version of the mod. */
"version": { type: "string" }, version: string,
"sha1": { type: "string" }, /** SHA1 hash of the zip file. */
}, sha1?: string,
}; }
const ModRecordJsonSchema = Type.Object({
"name": Type.String(),
"enabled": Type.Boolean(),
"version": Type.String(),
"sha1": Type.Optional(Type.String()),
});
type PropertyType = null | boolean | number | string | PropertyType[] | { [key: string]: PropertyType };
/** /**
* Factorio Mod Pack * Factorio Mod Pack
* *
* Tracks mods and settings for a collection of Factorio mods. * Tracks mods and settings for a collection of Factorio mods.
* @alias module:lib.ModPack
*/ */
class ModPack { export default class ModPack {
declare ["constructor"]: typeof ModPack;
/** /**
* Id of this mod pack * Id of this mod pack
* @type {number}
*/ */
id; id: number;
/** /**
* Name of this mod pack. * Name of this mod pack.
* @type {string}
*/ */
name = ""; name = "";
/** /**
* Description for this modpcak. * Description for this modpcak.
* @type {string}
*/ */
description = ""; description = "";
/** /**
* Version of Factorio this mod pack is for * Version of Factorio this mod pack is for
* @type {string}
*/ */
factorioVersion = "1.1.0"; factorioVersion = "1.1.0";
/** /**
* Integer representation of the factorioVersion * Integer representation of the factorioVersion
* @type {number}
*/ */
get integerFactorioVersion() { get integerFactorioVersion() {
return integerFactorioVersion(this.factorioVersion); return integerFactorioVersion(this.factorioVersion);
@@ -86,29 +83,25 @@ class ModPack {
/** /**
* Mods included in this mod pack * Mods included in this mod pack
* @type {Map<string, module:lib.ModPack~ModRecord>}
*/ */
mods = new Map(); mods = new Map<string, ModRecord>();
/** /**
* Mod settings for this mod pack * Mod settings for this mod pack
* @type {Object<string, Map<string, module:lib.ModPack~ModSetting>>=}
*/ */
settings = { settings = {
"startup": new Map(), "startup": new Map<string, ModSetting>(),
"runtime-global": new Map(), "runtime-global": new Map<string, ModSetting>(),
"runtime-per-user": new Map(), "runtime-per-user": new Map<string, ModSetting>(),
}; };
/** /**
* Mapping to files containing exported data for this modpack * Mapping to files containing exported data for this modpack
* @type {module:lib.ExportManifest|undefined}
*/ */
exportManifest; exportManifest?: ExportManifest;
/** /**
* True if this mod pack has been deleted from the list of mod packs. * True if this mod pack has been deleted from the list of mod packs.
* @type {boolean}
*/ */
isDeleted = false; isDeleted = false;
@@ -125,37 +118,24 @@ class ModPack {
return clone; return clone;
} }
static jsonSchema = { static jsonSchema = Type.Object({
type: "object", "id": Type.Optional(Type.Integer()),
additionalProperties: false, "name": Type.String(),
required: ["name", "description", "factorio_version", "mods", "settings"], "description": Type.String(),
properties: { "factorio_version": Type.String(),
"id": { type: "integer" }, "mods": Type.Array(ModRecordJsonSchema),
"name": { type: "string" }, "settings": Type.Object({
"description": { type: "string" }, "startup": ModSettingsJsonSchema,
"factorio_version": { type: "string" }, "runtime-global": ModSettingsJsonSchema,
"mods": { "runtime-per-user": ModSettingsJsonSchema,
type: "array", }),
items: ModRecordJsonSchema, "export_manifest": Type.Optional(ExportManifest.jsonSchema),
}, "is_deleted": Type.Optional(Type.Boolean()),
"settings": { });
type: "object",
additionalProperties: false,
required: ["startup", "runtime-global", "runtime-per-user"],
properties: {
"startup": ModSettingsJsonSchema,
"runtime-global": ModSettingsJsonSchema,
"runtime-per-user": ModSettingsJsonSchema,
},
},
"export_manifest": ExportManifest.jsonSchema,
"is_deleted": { type: "boolean" },
},
};
static validate = libSchema.compile(this.jsonSchema); static validate = libSchema.compile<Static<typeof ModPack.jsonSchema>>(this.jsonSchema as any);
static fromJSON(json) { static fromJSON(json: Static<typeof ModPack.jsonSchema>) {
const modPack = new this(); const modPack = new this();
if (json.id) { if (json.id) {
@@ -185,7 +165,7 @@ class ModPack {
} }
toJSON() { toJSON() {
let json = { let json: Static<typeof ModPack.jsonSchema> = {
id: this.id, id: this.id,
name: this.name, name: this.name,
description: this.description, description: this.description,
@@ -212,7 +192,7 @@ class ModPack {
return buf.toString("base64"); return buf.toString("base64");
} }
static fromModPackString(modPackString) { static fromModPackString(modPackString: string) {
let buf = Buffer.from(modPackString, "base64"); let buf = Buffer.from(modPackString, "base64");
try { try {
// eslint-disable-next-line node/no-sync // eslint-disable-next-line node/no-sync
@@ -223,9 +203,9 @@ class ModPack {
} }
} }
let json; let json: unknown;
try { try {
json = JSON.parse(buf); json = JSON.parse(buf.toString());
} catch (err) { } catch (err) {
throw new Error(`Malformed mod pack string: ${err.message}`); throw new Error(`Malformed mod pack string: ${err.message}`);
} }
@@ -238,16 +218,16 @@ class ModPack {
} }
toModSettingsDat() { toModSettingsDat() {
function uint8Byte(int) { function uint8Byte(int: number) {
return Buffer.from(Uint8Array.from([int]).buffer); return Buffer.from(Uint8Array.from([int]).buffer);
} }
function int16Bytes(int) { function int16Bytes(int: number) {
return Buffer.from(Int16Array.from([int]).buffer); return Buffer.from(Int16Array.from([int]).buffer);
} }
function uint32Bytes(int) { function uint32Bytes(int: number) {
return Buffer.from(Uint32Array.from([int]).buffer); return Buffer.from(Uint32Array.from([int]).buffer);
} }
function uint32SpaceOptimizedBytes(int) { function uint32SpaceOptimizedBytes(int: number) {
if (0 <= int && int < 0xff) { if (0 <= int && int < 0xff) {
return uint8Byte(int); return uint8Byte(int);
} }
@@ -256,17 +236,17 @@ class ModPack {
uint32Bytes(int), uint32Bytes(int),
]); ]);
} }
function doubleBytes(double) { function doubleBytes(double: number) {
return Buffer.from(Float64Array.from([double]).buffer); return Buffer.from(Float64Array.from([double]).buffer);
} }
function stringBytes(str) { function stringBytes(str: string) {
const buf = Buffer.from(str, "utf8"); const buf = Buffer.from(str, "utf8");
return Buffer.concat([ return Buffer.concat([
uint32SpaceOptimizedBytes(buf.length), uint32SpaceOptimizedBytes(buf.length),
buf, buf,
]); ]);
} }
function immutableStringBytes(str) { function immutableStringBytes(str: string) {
if (str === undefined) { if (str === undefined) {
return uint8Byte(1); // empty return uint8Byte(1); // empty
} }
@@ -275,7 +255,7 @@ class ModPack {
stringBytes(str), stringBytes(str),
]); ]);
} }
function versionBytes(version) { function versionBytes(version: string) {
const [main, major, minor] = version.split(".").map(n => Number.parseInt(n, 10)); const [main, major, minor] = version.split(".").map(n => Number.parseInt(n, 10));
return Buffer.concat([ return Buffer.concat([
int16Bytes(main), int16Bytes(main),
@@ -285,7 +265,7 @@ class ModPack {
Buffer.alloc(1), // reserved byte Buffer.alloc(1), // reserved byte
]); ]);
} }
function propertyTreeListBytes(entries) { function propertyTreeListBytes(entries: [string, PropertyType][]) {
const sizeBytes = uint32Bytes(entries.length); const sizeBytes = uint32Bytes(entries.length);
const itemBytes = entries.flatMap(([key, item]) => [ const itemBytes = entries.flatMap(([key, item]) => [
immutableStringBytes(key), immutableStringBytes(key),
@@ -297,15 +277,15 @@ class ModPack {
...itemBytes, ...itemBytes,
]); ]);
} }
function propertyTreeBytes(element) { function propertyTreeBytes(element: PropertyType) {
let type; let type: number;
let dataBytes; let dataBytes: Buffer;
if (typeof element === null) { if (typeof element === null) {
type = 1; type = 1;
dataBytes = Buffer.alloc(0); dataBytes = Buffer.alloc(0);
} else if (typeof element === "boolean") { } else if (typeof element === "boolean") {
type = 1; type = 1;
dataBytes = uint8Byte(element); dataBytes = uint8Byte(Number(element));
} else if (typeof element === "number") { } else if (typeof element === "number") {
type = 2; type = 2;
dataBytes = doubleBytes(element); dataBytes = doubleBytes(element);
@@ -340,11 +320,11 @@ class ModPack {
* Uses the provided setting prototypes to add any missing mod settings * Uses the provided setting prototypes to add any missing mod settings
* in the mod pack with the default value from the prototype. * in the mod pack with the default value from the prototype.
* *
* @param {Object<string, object>} settingPrototypes - * @param settingPrototypes -
* Setting prototypes exported from the game. * Setting prototypes exported from the game.
* @param {Logger} logger - Logger used to report warnings on. * @param logger - Logger used to report warnings on.
*/ */
fillDefaultSettings(settingPrototypes, logger) { fillDefaultSettings(settingPrototypes: Record<string, object>, logger: Logger) {
const knownTypes = ["bool-setting", "int-setting", "double-setting", "string-setting"]; const knownTypes = ["bool-setting", "int-setting", "double-setting", "string-setting"];
let prototypes = Object.entries(settingPrototypes) let prototypes = Object.entries(settingPrototypes)
.filter(([type, _]) => knownTypes.includes(type)) .filter(([type, _]) => knownTypes.includes(type))
@@ -368,5 +348,3 @@ class ModPack {
} }
} }
} }
module.exports = ModPack;
+5 -5
View File
@@ -56,7 +56,7 @@ export class ModPackCreateRequest {
) { } ) { }
static jsonSchema = Type.Object({ static jsonSchema = Type.Object({
"modPack": Type.Unsafe<object>(ModPack.jsonSchema), "modPack": ModPack.jsonSchema,
}); });
static fromJSON(json: Static<typeof this.jsonSchema>) { static fromJSON(json: Static<typeof this.jsonSchema>) {
@@ -76,7 +76,7 @@ export class ModPackUpdateRequest {
) { } ) { }
static jsonSchema = Type.Object({ static jsonSchema = Type.Object({
"modPack": Type.Unsafe<object>(ModPack.jsonSchema), "modPack": ModPack.jsonSchema,
}); });
static fromJSON(json: Static<typeof this.jsonSchema>) { static fromJSON(json: Static<typeof this.jsonSchema>) {
@@ -203,7 +203,7 @@ export class ModSearchRequest {
"results": Type.Array( "results": Type.Array(
Type.Object({ Type.Object({
"name": Type.String(), "name": Type.String(),
"versions": Type.Array(Type.Unsafe<object>(ModInfo.jsonSchema)), "versions": Type.Array(ModInfo.jsonSchema),
}), }),
), ),
}); });
@@ -296,7 +296,7 @@ export class ModPackUpdateEvent {
) { } ) { }
static jsonSchema = Type.Object({ static jsonSchema = Type.Object({
"modPack": Type.Unsafe<object>(ModPack.jsonSchema), "modPack": ModPack.jsonSchema,
}); });
static fromJSON(json: Static<typeof this.jsonSchema>) { static fromJSON(json: Static<typeof this.jsonSchema>) {
@@ -315,7 +315,7 @@ export class ModUpdateEvent {
) { } ) { }
static jsonSchema = Type.Object({ static jsonSchema = Type.Object({
"mod": Type.Unsafe<object>(ModInfo.jsonSchema), "mod": ModInfo.jsonSchema,
}); });
static fromJSON(json: Static<typeof this.jsonSchema>) { static fromJSON(json: Static<typeof this.jsonSchema>) {
@@ -1,5 +1,4 @@
// Helper functions for dealing with factorio version numbers // Helper functions for dealing with factorio version numbers
"use strict";
/** /**
@@ -7,11 +6,10 @@
* *
* Suitable for sorting and comparing version numbers which may have different * Suitable for sorting and comparing version numbers which may have different
* number of leading zeros in them. * number of leading zeros in them.
* @param {string} version - string representation of version. * @param version - string representation of version.
* @returns {number} numeric representation. * @returns numeric representation.
* @alias module:lib.integerModVersion
*/ */
function integerModVersion(version) { export function integerModVersion(version: string) {
const [major, minor, sub] = version.split(".").map(n => Number.parseInt(n, 10)); 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. return major * 0x100000000 + minor * 0x10000 + sub; // Can't use bitwise here because this is 48-bits.
} }
@@ -21,24 +19,15 @@ function integerModVersion(version) {
* *
* Suitable for sorting and comparing version numbers which may have different * Suitable for sorting and comparing version numbers which may have different
* number of leading zeros in them. * number of leading zeros in them.
* @param {string} version - string representation of version. * @param version - string representation of version.
* @returns {number} numeric representation. * @returns numeric representation.
* @alias module:lib.integerFactorioVersion
*/ */
function integerFactorioVersion(version) { export function integerFactorioVersion(version: string) {
const [main, major, minor] = version.split(".").map(n => Number.parseInt(n, 10)); 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. return main * 0x100000000 + major * 0x10000 + (minor || 0); // Can't use bitwise here because this is 48-bits.
} }
/** /**
* Matches valid mod versions. * Matches valid mod versions.
* @type {RegExp}
* @alias module:lib.modVersionRegExp
*/ */
const modVersionRegExp = /^\d+\.\d+\.\d+$/; export const modVersionRegExp = /^\d+\.\d+\.\d+$/;
module.exports = {
integerModVersion,
integerFactorioVersion,
modVersionRegExp,
};