@rjsf/utils 6.7.0 → 6.7.1

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/utils.esm.js CHANGED
@@ -20,6 +20,20 @@ function allowAdditionalItems(schema) {
20
20
  return isObject(schema.additionalItems);
21
21
  }
22
22
 
23
+ // src/getDecimalSeparator.ts
24
+ function getDecimalSeparator(languages) {
25
+ const locales = languages || (typeof navigator !== "undefined" ? navigator.languages : void 0);
26
+ if (locales) {
27
+ try {
28
+ const formatter = new Intl.NumberFormat(locales);
29
+ const parts = formatter.formatToParts(1.1);
30
+ return parts.find((part) => part.type === "decimal")?.value || ".";
31
+ } catch (e) {
32
+ }
33
+ }
34
+ return ".";
35
+ }
36
+
23
37
  // src/asNumber.ts
24
38
  function asNumber(value) {
25
39
  if (value === "") {
@@ -28,16 +42,18 @@ function asNumber(value) {
28
42
  if (value === null) {
29
43
  return null;
30
44
  }
31
- if (/\.$/.test(value)) {
45
+ const separator = getDecimalSeparator();
46
+ const standardValue = typeof value === "string" && separator !== "." ? value.replace(separator, ".") : value;
47
+ if (/\.$/.test(standardValue)) {
32
48
  return value;
33
49
  }
34
- if (/\.0$/.test(value)) {
50
+ if (/\.0$/.test(standardValue)) {
35
51
  return value;
36
52
  }
37
- if (/\.\d*0$/.test(value)) {
53
+ if (/\.\d*0$/.test(standardValue)) {
38
54
  return value;
39
55
  }
40
- const n = Number(value);
56
+ const n = Number(standardValue);
41
57
  const valid = typeof n === "number" && !Number.isNaN(n);
42
58
  return valid ? n : value;
43
59
  }
@@ -1902,11 +1918,7 @@ function getArrayDefaults(validator, rawSchema, {
1902
1918
  }
1903
1919
  const defaultsLength = Array.isArray(defaults) ? defaults.length : 0;
1904
1920
  if (neverPopulate) {
1905
- if (shouldMergeDefaultsIntoFormData) {
1906
- if (schema.minItems && schema.minItems > defaultsLength) {
1907
- const fillerEntries = Array.from({ length: schema.minItems - defaultsLength }, () => null);
1908
- return (defaults ?? []).concat(fillerEntries);
1909
- }
1921
+ if (shouldMergeDefaultsIntoFormData && !required) {
1910
1922
  return defaults;
1911
1923
  }
1912
1924
  return defaults ?? emptyDefault;
@@ -4422,6 +4434,7 @@ export {
4422
4434
  getChangedFields,
4423
4435
  getClosestMatchingOption,
4424
4436
  getDateElementProps,
4437
+ getDecimalSeparator,
4425
4438
  getDefaultFormState,
4426
4439
  getDiscriminatorFieldFromSchema,
4427
4440
  getDisplayLabel,