@rjsf/utils 6.7.0 → 6.8.0

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 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
- if (/\.$/.test(value)) {
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(value)) {
233
+ if (/\.0$/.test(standardValue)) {
217
234
  return value;
218
235
  }
219
- if (/\.\d*0$/.test(value)) {
236
+ if (/\.\d*0$/.test(standardValue)) {
220
237
  return value;
221
238
  }
222
- const n = Number(value);
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;
@@ -3603,12 +3616,18 @@ function hashString(string) {
3603
3616
  return hash.toString(16);
3604
3617
  }
3605
3618
  function sortedJSONStringify(object) {
3606
- const allKeys = /* @__PURE__ */ new Set();
3607
- JSON.stringify(object, (key, value) => {
3608
- allKeys.add(key);
3609
- return value;
3610
- });
3611
- return JSON.stringify(object, Array.from(allKeys).sort());
3619
+ function shouldIncludeValue(value) {
3620
+ return value !== void 0 && typeof value !== "function" && typeof value !== "symbol";
3621
+ }
3622
+ if (Array.isArray(object)) {
3623
+ return `[${object.map((x) => x === void 0 ? "undefined" : sortedJSONStringify(x)).join(",")}]`;
3624
+ }
3625
+ if (object === null || typeof object !== "object") {
3626
+ return JSON.stringify(typeof object === "function" ? null : object);
3627
+ }
3628
+ const record = object;
3629
+ const sortedValues = Object.keys(record).sort().filter((key) => shouldIncludeValue(record[key])).map((key) => `${JSON.stringify(key)}:${sortedJSONStringify(record[key])}`);
3630
+ return `{${sortedValues.join(",")}}`;
3612
3631
  }
3613
3632
  function hashObject(object) {
3614
3633
  return hashString(sortedJSONStringify(object));