@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/README.md +0 -4
- package/dist/index.cjs +22 -9
- package/dist/index.cjs.map +3 -3
- package/dist/utils.esm.js +22 -9
- package/dist/utils.esm.js.map +3 -3
- package/dist/utils.umd.js +22 -9
- package/lib/asNumber.d.ts +6 -5
- package/lib/asNumber.js +14 -9
- package/lib/asNumber.js.map +1 -1
- package/lib/getDecimalSeparator.d.ts +8 -0
- package/lib/getDecimalSeparator.js +23 -0
- package/lib/getDecimalSeparator.js.map +1 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/schema/getDefaultFormState.js +4 -5
- package/lib/schema/getDefaultFormState.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/asNumber.ts +18 -9
- package/src/getDecimalSeparator.ts +20 -0
- package/src/index.ts +2 -0
- package/src/schema/getDefaultFormState.ts +4 -5
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
|
-
|
|
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(
|
|
50
|
+
if (/\.0$/.test(standardValue)) {
|
|
35
51
|
return value;
|
|
36
52
|
}
|
|
37
|
-
if (/\.\d*0$/.test(
|
|
53
|
+
if (/\.\d*0$/.test(standardValue)) {
|
|
38
54
|
return value;
|
|
39
55
|
}
|
|
40
|
-
const n = Number(
|
|
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,
|