From cf4b474c700918932b3a306bdc4eda6f6e685474 Mon Sep 17 00:00:00 2001 From: Alex Corn Date: Sun, 1 Oct 2023 21:30:12 -0400 Subject: [PATCH] Added steamID coalescing helper, although currently unused --- components/helpers.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/components/helpers.js b/components/helpers.js index e887fff..d56b4f3 100644 --- a/components/helpers.js +++ b/components/helpers.js @@ -1,7 +1,9 @@ -const EResult = require('../resources/EResult.js'); const request = require('request'); +const SteamID = require('steamid'); const xml2js = require('xml2js'); +const EResult = require('../resources/EResult.js'); + exports.isSteamID = function(input) { var keys = Object.keys(input); if (keys.length != 4) { @@ -105,4 +107,22 @@ exports.resolveVanityURL = function(url, callback) { callback(null, {"vanityURL": vanityURL, "steamID": steamID64}); }); }); -}; \ No newline at end of file +}; + +/** + * Converts `input` into a SteamID object, if it's a parseable string. + * @param {SteamID|string} input + * @return {SteamID} + */ +exports.steamID = function(input) { + if (exports.isSteamID(input)) { + return input; + } + + if (typeof input != 'string') { + throw new Error(`Input SteamID value "${input}" is not a string`); + } + + // This will throw if the input is not a well-formed SteamID + return new SteamID(input); +};