steam-condenser
Version:
TypeScript port of steam-condenser.
52 lines • 2.34 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SteamID = void 0;
var bignum_1 = __importDefault(require("bignum"));
var SteamID = /** @class */ (function () {
function SteamID() {
}
SteamID.ConvertCommunityIDToSteamID = function (communityID) {
var comID = communityID;
if (typeof comID === 'string') {
comID = new bignum_1.default(comID);
}
var steamID1 = comID.mod(2);
var steamID2 = bignum_1.default.sub(communityID, new bignum_1.default('76561197960265728'));
if (steamID2.le(0)) {
throw new Error("SteamID " + communityID + " is too small.");
}
return "STEAM_0:" + steamID1 + ":" + steamID2.sub(steamID1).div(2);
};
SteamID.ConvertCommunityIdToSteamId3 = function (communityID) {
var comID = communityID;
if (typeof comID === 'string') {
comID = new bignum_1.default(comID);
}
var steamID1 = 1;
var steamID2 = bignum_1.default.sub(comID, new bignum_1.default('76561197960265728'));
if (steamID2.le(0)) {
throw new Error("SteamID " + comID + " is too small.");
}
return "[U:" + steamID1 + ":" + steamID2 + "]";
};
SteamID.ConvertSteamIdToCommunityId = function (steamID) {
if (steamID === 'STEAM_ID_LAN' || steamID === 'BOT') {
throw new Error("Cannot convert SteamID \"" + steamID + "\" to a community ID.");
}
if (steamID.match('^STEAM_[0-1]:[0-1]:[0-9]+$')) {
var tmpId = steamID.substring(8).split(':');
return new bignum_1.default(Number.parseInt(tmpId[0], 10) + Number.parseInt(tmpId[1], 10) * 2).add('76561197960265728');
}
if (steamID.match('^\\[U:[0-1]:[0-9]+\\]+$')) {
var tmpId = steamID.substring(3, steamID.length - 1).split(':');
return new bignum_1.default(Number.parseInt(tmpId[0], 10) + Number.parseInt(tmpId[1], 10)).add('76561197960265727');
}
throw new Error("SteamID \"" + steamID + "\" doesn't have the correct format.");
};
return SteamID;
}());
exports.SteamID = SteamID;
//# sourceMappingURL=SteamID.js.map