steamutils 1.5.50 → 1.5.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +48 -6
- package/package.json +1 -1
package/index.js
CHANGED
@@ -5,7 +5,7 @@ import moment from "moment";
|
|
5
5
|
import { hex2b64, Key as RSA } from "node-bignumber";
|
6
6
|
import SteamID from "steamid";
|
7
7
|
import qs from "qs";
|
8
|
-
import { console_log, convertLongsToNumbers, downloadImage, formatMarketHistoryDate, getCleanObject, getImageSize, isJWT, JSON_parse, JSON_stringify, removeSpaceKeys, secretAsBuffer, sleep } from "./utils.js";
|
8
|
+
import { console_log, convertLongsToNumbers, downloadImage, formatMarketCurrency, formatMarketHistoryDate, getCleanObject, getImageSize, getMarketPriceValueAsInt, isJWT, JSON_parse, JSON_stringify, removeSpaceKeys, secretAsBuffer, sleep } from "./utils.js";
|
9
9
|
import { Header, request } from "./axios.js";
|
10
10
|
import { getTableHasHeaders, querySelectorAll, table2json } from "./cheerio.js";
|
11
11
|
import { getJSObjectFronXML } from "./xml2json.js";
|
@@ -6779,20 +6779,62 @@ export default class SteamUser {
|
|
6779
6779
|
return friendSince;
|
6780
6780
|
}
|
6781
6781
|
|
6782
|
+
/**
|
6783
|
+
* Retrieves the Steam Wallet balances (main and pending) and the account currency
|
6784
|
+
* for the currently authenticated user by parsing the wallet info from the profile HTML.
|
6785
|
+
*
|
6786
|
+
* @async
|
6787
|
+
* @returns {Promise<{mainBalance: string|null, pending: string|null, currency: string|null}|undefined>}
|
6788
|
+
* A Promise that resolves to an object containing:
|
6789
|
+
* - mainBalance: The main wallet balance as a string (e.g., "276.400,82₫"), or null if not found.
|
6790
|
+
* - pending: The pending wallet balance as a string (e.g., "90.176,70₫"), or null if not found.
|
6791
|
+
* - currency: The detected currency symbol or code (e.g., "₫", "€", "$", "TL"), or null if not found.
|
6792
|
+
* The function returns undefined if an error occurs or valid HTML is not available.
|
6793
|
+
*
|
6794
|
+
* @example
|
6795
|
+
* const { mainBalance, pending, currency } = await getWalletBalance();
|
6796
|
+
* console.log(mainBalance); // e.g., "276.400,82₫"
|
6797
|
+
* console.log(pending); // e.g., "90.176,70₫"
|
6798
|
+
* console.log(currency); // e.g., "₫"
|
6799
|
+
*/
|
6782
6800
|
async getWalletBalance() {
|
6783
6801
|
const result = await this._httpRequest(`my?l=english`);
|
6784
6802
|
if (result instanceof ResponseError) {
|
6785
|
-
return
|
6803
|
+
return;
|
6786
6804
|
}
|
6787
6805
|
const html = result?.data;
|
6788
6806
|
if (!html || typeof html !== "string") {
|
6789
6807
|
return;
|
6790
6808
|
}
|
6791
6809
|
const $ = cheerio.load(html);
|
6792
|
-
|
6793
|
-
|
6794
|
-
|
6795
|
-
|
6810
|
+
|
6811
|
+
const mainBalance = $("#header_wallet_balance").clone().children().remove().end().text().trim() || null;
|
6812
|
+
|
6813
|
+
let currency = null;
|
6814
|
+
if (mainBalance) {
|
6815
|
+
// This regex matches all non-digit, non-comma, non-dot characters at the end (currency symbol/code)
|
6816
|
+
// Handles "12,34€", "$12.34", "12,34 TL", etc.
|
6817
|
+
const m = mainBalance.match(/([^\d.,\s].*)$/);
|
6818
|
+
if (m) currency = m[1].trim();
|
6819
|
+
else {
|
6820
|
+
// fallback for prefix (e.g. "$12.34")
|
6821
|
+
const m2 = mainBalance.match(/^([^\d.,\s]+)/);
|
6822
|
+
if (m2) currency = m2[1].trim();
|
6823
|
+
}
|
6824
|
+
}
|
6825
|
+
|
6826
|
+
let pendingStr = $("#header_wallet_balance span.tooltip").text();
|
6827
|
+
let pending = null;
|
6828
|
+
if (pendingStr) {
|
6829
|
+
const match = pendingStr.match(/Pending:\s*([\d.,]+[^\s]*)/);
|
6830
|
+
if (match) pending = match[1];
|
6831
|
+
}
|
6832
|
+
|
6833
|
+
return {
|
6834
|
+
mainBalance,
|
6835
|
+
pending,
|
6836
|
+
currency,
|
6837
|
+
};
|
6796
6838
|
}
|
6797
6839
|
|
6798
6840
|
async acceptConfirmationForObject(accessToken, identitySecret, objectID) {
|