@royalinvest/dto 0.69.13 → 0.69.15

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/profile.d.ts CHANGED
@@ -1,6 +1,7 @@
1
+ import { LocaleType } from "./types";
1
2
  export interface IProfile {
2
3
  id?: string;
3
4
  photo?: string;
4
5
  notification_seen_at?: Date;
5
- language?: "en" | "fr";
6
+ language?: LocaleType;
6
7
  }
package/dist/utils.d.ts CHANGED
@@ -1,6 +1,4 @@
1
- import { CountryEnum, CurrencyEnum } from "./enum";
2
- import { LocaleType } from "./types";
1
+ import { CurrencyEnum } from "./enum";
3
2
  export declare function fromMinorUnits(amountMinor: string, currency: CurrencyEnum): number;
4
3
  export declare function fromMinorUnitsExact(amountMinor: string, currency: CurrencyEnum): string;
5
4
  export declare function parseMajorToMinor(value: string, currency: CurrencyEnum): string;
6
- export declare function resolveLocale(uiLanguage: LocaleType, country?: CountryEnum | null): string;
package/dist/utils.js CHANGED
@@ -3,34 +3,40 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fromMinorUnits = fromMinorUnits;
4
4
  exports.fromMinorUnitsExact = fromMinorUnitsExact;
5
5
  exports.parseMajorToMinor = parseMajorToMinor;
6
- exports.resolveLocale = resolveLocale;
7
6
  const config_1 = require("./config");
8
7
  // This is going to be used for web app to show amount in minor taking into account units configured for the currency
9
8
  function fromMinorUnits(amountMinor, currency) {
10
- const decimals = config_1.CurrencyMinorUnits[currency];
11
- return Number(amountMinor) / 10 ** decimals;
9
+ const decimals = config_1.CurrencyMinorUnits[currency] ?? 2;
10
+ const n = Number(amountMinor);
11
+ if (!Number.isFinite(n))
12
+ return 0;
13
+ return n / 10 ** decimals;
12
14
  }
13
15
  // This is going to be used in emails, pdf where we need to show exact amount without rounding them and showing units per currency
14
16
  function fromMinorUnitsExact(amountMinor, currency) {
15
- const decimals = config_1.CurrencyMinorUnits[currency];
16
- const value = amountMinor.padStart(decimals + 1, "0");
17
+ const decimals = config_1.CurrencyMinorUnits[currency] ?? 2;
18
+ const neg = amountMinor.startsWith("-");
19
+ const raw = neg ? amountMinor.slice(1) : amountMinor;
20
+ if (decimals === 0)
21
+ return (neg ? "-" : "") + raw;
22
+ const value = raw.padStart(decimals + 1, "0");
17
23
  const index = value.length - decimals;
18
- return `${value.slice(0, index)}.${value.slice(index)}`;
24
+ return (neg ? "-" : "") + `${value.slice(0, index)}.${value.slice(index)}`;
19
25
  }
20
26
  // Safe way to parse Major amount to minor using units configured for the currency
21
27
  function parseMajorToMinor(value, currency) {
22
- const decimals = config_1.CurrencyMinorUnits[currency];
23
- const [i, d = ""] = value.split(".");
24
- const padded = (d + "0".repeat(decimals)).slice(0, decimals);
25
- return `${i}${padded}`;
26
- }
27
- function resolveLocale(uiLanguage, country) {
28
- if (country) {
29
- const byCountry = config_1.DEFAULT_LOCALE_BY_COUNTRY_AND_LANGUAGE[country];
30
- if (byCountry) {
31
- return byCountry[uiLanguage] ?? Object.values(byCountry)[0];
32
- }
28
+ const decimals = config_1.CurrencyMinorUnits[currency] ?? 2;
29
+ const trimmed = value.trim().replace(",", ".");
30
+ const neg = trimmed.startsWith("-");
31
+ const v = neg ? trimmed.slice(1) : trimmed;
32
+ const [iRaw, dRaw = ""] = v.split(".");
33
+ const i = (iRaw || "0").replace(/^0+(?=\d)/, "");
34
+ const d = dRaw.replace(/\D/g, "");
35
+ if (!/^\d+$/.test(i) || (dRaw && !/^\d*$/.test(d))) {
36
+ throw new Error("Invalid amount format");
33
37
  }
34
- // Fallback: language-only default
35
- return config_1.DEFAULT_LOCALE_BY_LANGUAGE[uiLanguage] ?? "en-US";
38
+ if (decimals === 0)
39
+ return (neg ? "-" : "") + i;
40
+ const padded = (d + "0".repeat(decimals)).slice(0, decimals);
41
+ return (neg ? "-" : "") + `${i}${padded}`;
36
42
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@royalinvest/dto",
3
- "version": "0.69.13",
3
+ "version": "0.69.15",
4
4
  "description": "Data Transfer Objects (DTOs) to carry data between frontend and backend processes.",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",