gambling-bot-shared 0.1.48 → 0.1.50
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/dist/constants/defaultGlobalSettings.d.ts +1 -2
- package/dist/constants/defaultGlobalSettings.js +0 -1
- package/dist/mongoose/guildConfiguration.schema.js +0 -1
- package/dist/schemas/forms.d.ts +0 -1
- package/dist/schemas/forms.js +5 -5
- package/dist/utils/formatters.d.ts +2 -2
- package/dist/utils/formatters.js +5 -4
- package/dist/utils/globalSettings.d.ts +0 -1
- package/dist/utils/globalSettings.js +8 -9
- package/dist/utils/normalizeGlobalSettings.js +6 -10
- package/package.json +1 -1
|
@@ -13,9 +13,8 @@ export type GlobalSettings = {
|
|
|
13
13
|
disableVip: boolean;
|
|
14
14
|
maintenanceMode: boolean;
|
|
15
15
|
timezone: string;
|
|
16
|
-
currencyCode: string;
|
|
17
16
|
currencySymbol: string;
|
|
18
|
-
/** prefix: symbol before amount ($
|
|
17
|
+
/** prefix: symbol before amount ($1.5k). suffix: symbol after amount (1.5kCZK). Spacing is part of currencySymbol. */
|
|
19
18
|
currencyPlacement: CurrencyPlacement;
|
|
20
19
|
};
|
|
21
20
|
export declare const defaultGlobalSettings: GlobalSettings;
|
|
@@ -112,7 +112,6 @@ exports.GuildConfigurationSchema = new mongoose_1.Schema({
|
|
|
112
112
|
disableVip: { type: Boolean, default: false },
|
|
113
113
|
maintenanceMode: { type: Boolean, default: false },
|
|
114
114
|
timezone: { type: String, default: constants_1.defaultGlobalSettings.timezone },
|
|
115
|
-
currencyCode: { type: String, default: constants_1.defaultGlobalSettings.currencyCode },
|
|
116
115
|
currencySymbol: {
|
|
117
116
|
type: String,
|
|
118
117
|
default: constants_1.defaultGlobalSettings.currencySymbol
|
package/dist/schemas/forms.d.ts
CHANGED
|
@@ -148,7 +148,6 @@ export declare const globalSettingsFormSchema: z.ZodObject<{
|
|
|
148
148
|
"Australia/Melbourne": "Australia/Melbourne";
|
|
149
149
|
"Pacific/Auckland": "Pacific/Auckland";
|
|
150
150
|
}>;
|
|
151
|
-
currencyCode: z.ZodString;
|
|
152
151
|
currencySymbol: z.ZodString;
|
|
153
152
|
currencyPlacement: z.ZodEnum<{
|
|
154
153
|
prefix: "prefix";
|
package/dist/schemas/forms.js
CHANGED
|
@@ -143,12 +143,12 @@ exports.globalSettingsFormSchema = zod_1.default.object({
|
|
|
143
143
|
disableVip: zod_1.default.boolean(),
|
|
144
144
|
maintenanceMode: zod_1.default.boolean(),
|
|
145
145
|
timezone: zod_1.default.enum(commonTimezones_1.COMMON_TIMEZONES),
|
|
146
|
-
|
|
146
|
+
currencySymbol: zod_1.default
|
|
147
147
|
.string()
|
|
148
|
-
.
|
|
149
|
-
.
|
|
150
|
-
|
|
151
|
-
|
|
148
|
+
.max(8)
|
|
149
|
+
.refine((value) => value.trim().length > 0, {
|
|
150
|
+
message: 'Currency symbol is required'
|
|
151
|
+
}),
|
|
152
152
|
currencyPlacement: zod_1.default.enum(['prefix', 'suffix'])
|
|
153
153
|
});
|
|
154
154
|
exports.bonusFormSchema = zod_1.default.object({
|
|
@@ -2,9 +2,9 @@ import type { GlobalSettings } from '../constants/defaultGlobalSettings';
|
|
|
2
2
|
export declare const formatNumberToReadableString: (number: number) => string;
|
|
3
3
|
export declare const parseReadableStringToNumber: (readableString: string) => number;
|
|
4
4
|
export declare const formatNumberWithSpaces: (num: number) => string;
|
|
5
|
-
/** Compact amount with guild currency (prefix
|
|
5
|
+
/** Compact amount with guild currency (prefix or suffix symbol). */
|
|
6
6
|
export declare const formatMoney: (amount: number, globalSettings?: Partial<GlobalSettings> | null) => string;
|
|
7
|
-
/** Full-precision amount with guild currency (prefix
|
|
7
|
+
/** Full-precision amount with guild currency (prefix or suffix symbol). */
|
|
8
8
|
export declare const formatMoneyExact: (amount: number, globalSettings?: Partial<GlobalSettings> | null) => string;
|
|
9
9
|
export declare const formatNumberToPercentage: (num: number) => string;
|
|
10
10
|
export declare const getReadableName: (key: string, map: {
|
package/dist/utils/formatters.js
CHANGED
|
@@ -5,10 +5,11 @@ const globalSettings_1 = require("./globalSettings");
|
|
|
5
5
|
const formatAmountWithCurrency = (amount, formattedAbsAmount, globalSettings) => {
|
|
6
6
|
const negative = amount < 0;
|
|
7
7
|
const sign = negative ? '-' : '';
|
|
8
|
+
const symbol = (0, globalSettings_1.getCurrencySymbol)(globalSettings);
|
|
8
9
|
if ((0, globalSettings_1.getCurrencyPlacement)(globalSettings) === 'suffix') {
|
|
9
|
-
return `${sign}${formattedAbsAmount}
|
|
10
|
+
return `${sign}${formattedAbsAmount}${symbol}`;
|
|
10
11
|
}
|
|
11
|
-
return `${sign}${
|
|
12
|
+
return `${sign}${symbol}${formattedAbsAmount}`;
|
|
12
13
|
};
|
|
13
14
|
const formatNumberToReadableString = (number) => {
|
|
14
15
|
const absNumber = Math.abs(number);
|
|
@@ -52,10 +53,10 @@ const formatNumberWithSpaces = (num) => {
|
|
|
52
53
|
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ' ');
|
|
53
54
|
};
|
|
54
55
|
exports.formatNumberWithSpaces = formatNumberWithSpaces;
|
|
55
|
-
/** Compact amount with guild currency (prefix
|
|
56
|
+
/** Compact amount with guild currency (prefix or suffix symbol). */
|
|
56
57
|
const formatMoney = (amount, globalSettings) => formatAmountWithCurrency(amount, (0, exports.formatNumberToReadableString)(Math.abs(amount)), globalSettings);
|
|
57
58
|
exports.formatMoney = formatMoney;
|
|
58
|
-
/** Full-precision amount with guild currency (prefix
|
|
59
|
+
/** Full-precision amount with guild currency (prefix or suffix symbol). */
|
|
59
60
|
const formatMoneyExact = (amount, globalSettings) => formatAmountWithCurrency(amount, (0, exports.formatNumberWithSpaces)(Math.abs(amount)), globalSettings);
|
|
60
61
|
exports.formatMoneyExact = formatMoneyExact;
|
|
61
62
|
const formatNumberToPercentage = (num) => {
|
|
@@ -4,4 +4,3 @@ export type GlobalFeature = 'registration' | 'deposit' | 'withdraw' | 'casinoGam
|
|
|
4
4
|
export declare function isGlobalFeatureDisabled(config: TGuildConfiguration | null | undefined, feature: GlobalFeature): boolean;
|
|
5
5
|
export declare const getCurrencyPlacement: (globalSettings?: Partial<GlobalSettings> | null) => CurrencyPlacement;
|
|
6
6
|
export declare const getCurrencySymbol: (globalSettings?: Partial<GlobalSettings> | null) => string;
|
|
7
|
-
export declare const getCurrencyCode: (globalSettings?: Partial<GlobalSettings> | null) => string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getCurrencySymbol = exports.getCurrencyPlacement = void 0;
|
|
4
4
|
exports.isGlobalFeatureDisabled = isGlobalFeatureDisabled;
|
|
5
5
|
const defaultGlobalSettings_1 = require("../constants/defaultGlobalSettings");
|
|
6
6
|
function isGlobalFeatureDisabled(config, feature) {
|
|
@@ -40,12 +40,11 @@ function isGlobalFeatureDisabled(config, feature) {
|
|
|
40
40
|
}
|
|
41
41
|
const getCurrencyPlacement = (globalSettings) => globalSettings?.currencyPlacement === 'suffix' ? 'suffix' : 'prefix';
|
|
42
42
|
exports.getCurrencyPlacement = getCurrencyPlacement;
|
|
43
|
-
const getCurrencySymbol = (globalSettings) =>
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return /^[A-Z]{3}$/.test(raw) ? raw : defaultGlobalSettings_1.defaultGlobalSettings.currencyCode;
|
|
43
|
+
const getCurrencySymbol = (globalSettings) => {
|
|
44
|
+
const symbol = globalSettings?.currencySymbol;
|
|
45
|
+
if (symbol == null || symbol.trim().length === 0) {
|
|
46
|
+
return defaultGlobalSettings_1.defaultGlobalSettings.currencySymbol;
|
|
47
|
+
}
|
|
48
|
+
return symbol;
|
|
50
49
|
};
|
|
51
|
-
exports.
|
|
50
|
+
exports.getCurrencySymbol = getCurrencySymbol;
|
|
@@ -11,14 +11,11 @@ const coerceBool = (value, fallback) => {
|
|
|
11
11
|
return false;
|
|
12
12
|
return fallback;
|
|
13
13
|
};
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const trimCurrencySymbol = (value) => {
|
|
20
|
-
const raw = typeof value === 'string' ? value.trim() : '';
|
|
21
|
-
return raw.length > 0 ? raw.slice(0, 8) : constants_1.defaultGlobalSettings.currencySymbol;
|
|
14
|
+
const normalizeCurrencySymbol = (value) => {
|
|
15
|
+
if (typeof value !== 'string' || value.trim().length === 0) {
|
|
16
|
+
return constants_1.defaultGlobalSettings.currencySymbol;
|
|
17
|
+
}
|
|
18
|
+
return value.slice(0, 8);
|
|
22
19
|
};
|
|
23
20
|
const normalizeCurrencyPlacement = (value) => value === 'suffix' ? 'suffix' : 'prefix';
|
|
24
21
|
const normalizeTimezone = (value) => {
|
|
@@ -43,8 +40,7 @@ const normalizeGlobalSettings = (settings) => ({
|
|
|
43
40
|
disableVip: coerceBool(settings?.disableVip, constants_1.defaultGlobalSettings.disableVip),
|
|
44
41
|
maintenanceMode: coerceBool(settings?.maintenanceMode, constants_1.defaultGlobalSettings.maintenanceMode),
|
|
45
42
|
timezone: normalizeTimezone(settings?.timezone),
|
|
46
|
-
|
|
47
|
-
currencySymbol: trimCurrencySymbol(settings?.currencySymbol),
|
|
43
|
+
currencySymbol: normalizeCurrencySymbol(settings?.currencySymbol),
|
|
48
44
|
currencyPlacement: normalizeCurrencyPlacement(settings?.currencyPlacement)
|
|
49
45
|
});
|
|
50
46
|
exports.normalizeGlobalSettings = normalizeGlobalSettings;
|