@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/README.md
CHANGED
|
@@ -7,10 +7,6 @@
|
|
|
7
7
|
<!-- PROJECT LOGO -->
|
|
8
8
|
<br />
|
|
9
9
|
<p align="center">
|
|
10
|
-
<a href="https://github.com/rjsf-team/react-jsonschema-form">
|
|
11
|
-
<img src="https://raw.githubusercontent.com/rjsf-team/react-jsonschema-form/7ebc86621d8df8c21f0c39bcca6d476f6f7a2051/packages/utils/logo.png" alt="Logo" width="120" height="120">
|
|
12
|
-
</a>
|
|
13
|
-
|
|
14
10
|
<h3 align="center">@rjsf/utils</h3>
|
|
15
11
|
|
|
16
12
|
<p align="center">
|
package/dist/index.cjs
CHANGED
|
@@ -104,6 +104,7 @@ __export(index_exports, {
|
|
|
104
104
|
getChangedFields: () => getChangedFields,
|
|
105
105
|
getClosestMatchingOption: () => getClosestMatchingOption,
|
|
106
106
|
getDateElementProps: () => getDateElementProps,
|
|
107
|
+
getDecimalSeparator: () => getDecimalSeparator,
|
|
107
108
|
getDefaultFormState: () => getDefaultFormState,
|
|
108
109
|
getDiscriminatorFieldFromSchema: () => getDiscriminatorFieldFromSchema,
|
|
109
110
|
getDisplayLabel: () => getDisplayLabel,
|
|
@@ -202,6 +203,20 @@ function allowAdditionalItems(schema) {
|
|
|
202
203
|
return isObject(schema.additionalItems);
|
|
203
204
|
}
|
|
204
205
|
|
|
206
|
+
// src/getDecimalSeparator.ts
|
|
207
|
+
function getDecimalSeparator(languages) {
|
|
208
|
+
const locales = languages || (typeof navigator !== "undefined" ? navigator.languages : void 0);
|
|
209
|
+
if (locales) {
|
|
210
|
+
try {
|
|
211
|
+
const formatter = new Intl.NumberFormat(locales);
|
|
212
|
+
const parts = formatter.formatToParts(1.1);
|
|
213
|
+
return parts.find((part) => part.type === "decimal")?.value || ".";
|
|
214
|
+
} catch (e) {
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return ".";
|
|
218
|
+
}
|
|
219
|
+
|
|
205
220
|
// src/asNumber.ts
|
|
206
221
|
function asNumber(value) {
|
|
207
222
|
if (value === "") {
|
|
@@ -210,16 +225,18 @@ function asNumber(value) {
|
|
|
210
225
|
if (value === null) {
|
|
211
226
|
return null;
|
|
212
227
|
}
|
|
213
|
-
|
|
228
|
+
const separator = getDecimalSeparator();
|
|
229
|
+
const standardValue = typeof value === "string" && separator !== "." ? value.replace(separator, ".") : value;
|
|
230
|
+
if (/\.$/.test(standardValue)) {
|
|
214
231
|
return value;
|
|
215
232
|
}
|
|
216
|
-
if (/\.0$/.test(
|
|
233
|
+
if (/\.0$/.test(standardValue)) {
|
|
217
234
|
return value;
|
|
218
235
|
}
|
|
219
|
-
if (/\.\d*0$/.test(
|
|
236
|
+
if (/\.\d*0$/.test(standardValue)) {
|
|
220
237
|
return value;
|
|
221
238
|
}
|
|
222
|
-
const n = Number(
|
|
239
|
+
const n = Number(standardValue);
|
|
223
240
|
const valid = typeof n === "number" && !Number.isNaN(n);
|
|
224
241
|
return valid ? n : value;
|
|
225
242
|
}
|
|
@@ -2084,11 +2101,7 @@ function getArrayDefaults(validator, rawSchema, {
|
|
|
2084
2101
|
}
|
|
2085
2102
|
const defaultsLength = Array.isArray(defaults) ? defaults.length : 0;
|
|
2086
2103
|
if (neverPopulate) {
|
|
2087
|
-
if (shouldMergeDefaultsIntoFormData) {
|
|
2088
|
-
if (schema.minItems && schema.minItems > defaultsLength) {
|
|
2089
|
-
const fillerEntries = Array.from({ length: schema.minItems - defaultsLength }, () => null);
|
|
2090
|
-
return (defaults ?? []).concat(fillerEntries);
|
|
2091
|
-
}
|
|
2104
|
+
if (shouldMergeDefaultsIntoFormData && !required) {
|
|
2092
2105
|
return defaults;
|
|
2093
2106
|
}
|
|
2094
2107
|
return defaults ?? emptyDefault;
|