@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 +0 -4
- package/dist/index.cjs +34 -15
- package/dist/index.cjs.map +3 -3
- package/dist/utils.esm.js +34 -15
- package/dist/utils.esm.js.map +3 -3
- package/dist/utils.umd.js +34 -15
- 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/hashForSchema.d.ts +2 -1
- package/lib/hashForSchema.js +17 -8
- package/lib/hashForSchema.js.map +1 -1
- 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/hashForSchema.ts +19 -8
- 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;
|
|
@@ -3421,12 +3433,18 @@ function hashString(string) {
|
|
|
3421
3433
|
return hash.toString(16);
|
|
3422
3434
|
}
|
|
3423
3435
|
function sortedJSONStringify(object) {
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3436
|
+
function shouldIncludeValue(value) {
|
|
3437
|
+
return value !== void 0 && typeof value !== "function" && typeof value !== "symbol";
|
|
3438
|
+
}
|
|
3439
|
+
if (Array.isArray(object)) {
|
|
3440
|
+
return `[${object.map((x) => x === void 0 ? "undefined" : sortedJSONStringify(x)).join(",")}]`;
|
|
3441
|
+
}
|
|
3442
|
+
if (object === null || typeof object !== "object") {
|
|
3443
|
+
return JSON.stringify(typeof object === "function" ? null : object);
|
|
3444
|
+
}
|
|
3445
|
+
const record = object;
|
|
3446
|
+
const sortedValues = Object.keys(record).sort().filter((key) => shouldIncludeValue(record[key])).map((key) => `${JSON.stringify(key)}:${sortedJSONStringify(record[key])}`);
|
|
3447
|
+
return `{${sortedValues.join(",")}}`;
|
|
3430
3448
|
}
|
|
3431
3449
|
function hashObject(object) {
|
|
3432
3450
|
return hashString(sortedJSONStringify(object));
|
|
@@ -4422,6 +4440,7 @@ export {
|
|
|
4422
4440
|
getChangedFields,
|
|
4423
4441
|
getClosestMatchingOption,
|
|
4424
4442
|
getDateElementProps,
|
|
4443
|
+
getDecimalSeparator,
|
|
4425
4444
|
getDefaultFormState,
|
|
4426
4445
|
getDiscriminatorFieldFromSchema,
|
|
4427
4446
|
getDisplayLabel,
|