@swan-io/shared-business 13.2.3 → 13.2.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swan-io/shared-business",
3
- "version": "13.2.3",
3
+ "version": "13.2.4",
4
4
  "engines": {
5
5
  "node": "^22.12.0"
6
6
  },
@@ -25,7 +25,7 @@
25
25
  ],
26
26
  "license": "MIT",
27
27
  "peerDependencies": {
28
- "@swan-io/lake": "13.2.3"
28
+ "@swan-io/lake": "13.2.4"
29
29
  },
30
30
  "dependencies": {
31
31
  "@formatjs/intl": "^3.1.6",
@@ -50,6 +50,6 @@
50
50
  "@types/react-dom": "^19.1.7",
51
51
  "@types/react-native": "^0.72.8",
52
52
  "type-fest": "^4.41.0",
53
- "@swan-io/lake": "13.2.3"
53
+ "@swan-io/lake": "13.2.4"
54
54
  }
55
55
  }
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, test } from "vitest";
2
- import { getCompanyTaxNumberHelp, getCompanyTaxNumberPlaceholder, getIndividualTaxNumberHelp, getIndividualTaxNumberPlaceholder, getTaxNumberTooltip, isValidEmail, validateBooleanRequired, validateCompanyTaxNumber, validateIndividualTaxNumber, validateNullableRequired, validateRequired, } from "../validation";
2
+ import { getCompanyTaxNumberHelp, getCompanyTaxNumberPlaceholder, getIndividualTaxNumberHelp, getIndividualTaxNumberPlaceholder, getTaxNumberTooltip, isValidEmail, sanitizeDecimal, validateBooleanRequired, validateCompanyTaxNumber, validateIndividualTaxNumber, validateNullableRequired, validateRequired, } from "../validation";
3
3
  describe("isValidEmail", () => {
4
4
  test("validates correct email addresses", () => {
5
5
  expect(isValidEmail("test@example.com")).toBe(true);
@@ -289,3 +289,20 @@ describe("Tax number helper functions", () => {
289
289
  });
290
290
  });
291
291
  });
292
+ describe("sanitizeDecimal", () => {
293
+ test("removes spaces from decimal input", () => {
294
+ expect(sanitizeDecimal("1 000")).toBe("1000");
295
+ });
296
+ test("handles multiple spaces", () => {
297
+ expect(sanitizeDecimal("1 000 000")).toBe("1000000");
298
+ });
299
+ test("replaces comma with dot for decimal separator", () => {
300
+ expect(sanitizeDecimal("10,5")).toBe("10.5");
301
+ });
302
+ test("removes spaces and replaces comma with dot", () => {
303
+ expect(sanitizeDecimal("1 234,56")).toBe("1234.56");
304
+ });
305
+ test("returns unchanged string when no spaces or commas", () => {
306
+ expect(sanitizeDecimal("1234.56")).toBe("1234.56");
307
+ });
308
+ });
@@ -3,6 +3,7 @@ import { CompanyCountryCCA3, IndividualCountryCCA3 } from "../constants/countrie
3
3
  import { ExtractedDate } from "./date";
4
4
  export declare const isValidVatNumber: (maybeVat: string) => boolean;
5
5
  export declare const isValidEmail: (maybeEmail: string) => boolean;
6
+ export declare const sanitizeDecimal: (value: string) => string;
6
7
  export declare const validateNullableRequired: Validator<string | undefined>;
7
8
  export declare const validateRequired: Validator<string>;
8
9
  export declare const validateBooleanRequired: Validator<boolean | undefined>;
@@ -109,6 +109,9 @@ export const isValidVatNumber = (maybeVat) => {
109
109
  export const isValidEmail = (maybeEmail) => {
110
110
  return EMAIL_REGEX.test(maybeEmail);
111
111
  };
112
+ export const sanitizeDecimal = (value) => {
113
+ return value.replace(/ /g, "").replace(/,/g, ".");
114
+ };
112
115
  export const validateNullableRequired = value => {
113
116
  if (value == null || !value) {
114
117
  return t("error.requiredField");