@sinclair/typebox 0.32.23 → 0.32.24
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/build/import/value/convert/convert.mjs +8 -6
- package/build/import/value/value/value.d.mts +2 -2
- package/build/import/value/value/value.mjs +1 -1
- package/build/require/value/convert/convert.js +7 -5
- package/build/require/value/value/value.d.ts +2 -2
- package/build/require/value/value/value.js +1 -1
- package/package.json +1 -1
|
@@ -5,7 +5,7 @@ import { Kind } from '../../type/symbols/index.mjs';
|
|
|
5
5
|
// ------------------------------------------------------------------
|
|
6
6
|
// ValueGuard
|
|
7
7
|
// ------------------------------------------------------------------
|
|
8
|
-
import { IsArray, IsObject, IsDate, IsUndefined, IsString, IsNumber, IsBoolean, IsBigInt, IsSymbol } from '../guard/index.mjs';
|
|
8
|
+
import { IsArray, IsObject, IsDate, IsUndefined, IsString, IsNumber, IsBoolean, IsBigInt, IsSymbol, HasPropertyKey } from '../guard/index.mjs';
|
|
9
9
|
// ------------------------------------------------------------------
|
|
10
10
|
// Conversions
|
|
11
11
|
// ------------------------------------------------------------------
|
|
@@ -142,11 +142,13 @@ function FromObject(schema, references, value) {
|
|
|
142
142
|
const isConvertable = IsObject(value);
|
|
143
143
|
if (!isConvertable)
|
|
144
144
|
return value;
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
145
|
+
const result = {};
|
|
146
|
+
for (const key of Object.keys(value)) {
|
|
147
|
+
result[key] = HasPropertyKey(schema.properties, key)
|
|
148
|
+
? Visit(schema.properties[key], references, value[key])
|
|
149
|
+
: value[key];
|
|
150
|
+
}
|
|
151
|
+
return result;
|
|
150
152
|
}
|
|
151
153
|
function FromRecord(schema, references, value) {
|
|
152
154
|
const propertyKey = Object.getOwnPropertyNames(schema.patternProperties)[0];
|
|
@@ -19,9 +19,9 @@ export declare function Check<T extends TSchema>(schema: T, value: unknown): val
|
|
|
19
19
|
export declare function Clean(schema: TSchema, references: TSchema[], value: unknown): unknown;
|
|
20
20
|
/** `[Mutable]` Removes excess properties from a value and returns the result. This function does not check the value and returns an unknown type. You should Check the result before use. Clean is a mutable operation. To avoid mutation, Clone the value first. */
|
|
21
21
|
export declare function Clean(schema: TSchema, value: unknown): unknown;
|
|
22
|
-
/** Converts any type mismatched values to their target type if a reasonable conversion is possible */
|
|
22
|
+
/** Converts any type mismatched values to their target type if a reasonable conversion is possible. */
|
|
23
23
|
export declare function Convert(schema: TSchema, references: TSchema[], value: unknown): unknown;
|
|
24
|
-
/** Converts any type mismatched values to their target type if a reasonable conversion is
|
|
24
|
+
/** Converts any type mismatched values to their target type if a reasonable conversion is possible. */
|
|
25
25
|
export declare function Convert(schema: TSchema, value: unknown): unknown;
|
|
26
26
|
/** Returns a structural clone of the given value */
|
|
27
27
|
export declare function Clone<T>(value: T): T;
|
|
@@ -27,7 +27,7 @@ export function Check(...args) {
|
|
|
27
27
|
export function Clean(...args) {
|
|
28
28
|
return CleanValue.apply(CleanValue, args);
|
|
29
29
|
}
|
|
30
|
-
/** Converts any type mismatched values to their target type if a reasonable conversion is possible */
|
|
30
|
+
/** Converts any type mismatched values to their target type if a reasonable conversion is possible. */
|
|
31
31
|
export function Convert(...args) {
|
|
32
32
|
return ConvertValue.apply(ConvertValue, args);
|
|
33
33
|
}
|
|
@@ -146,11 +146,13 @@ function FromObject(schema, references, value) {
|
|
|
146
146
|
const isConvertable = (0, index_5.IsObject)(value);
|
|
147
147
|
if (!isConvertable)
|
|
148
148
|
return value;
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
149
|
+
const result = {};
|
|
150
|
+
for (const key of Object.keys(value)) {
|
|
151
|
+
result[key] = (0, index_5.HasPropertyKey)(schema.properties, key)
|
|
152
|
+
? Visit(schema.properties[key], references, value[key])
|
|
153
|
+
: value[key];
|
|
154
|
+
}
|
|
155
|
+
return result;
|
|
154
156
|
}
|
|
155
157
|
function FromRecord(schema, references, value) {
|
|
156
158
|
const propertyKey = Object.getOwnPropertyNames(schema.patternProperties)[0];
|
|
@@ -19,9 +19,9 @@ export declare function Check<T extends TSchema>(schema: T, value: unknown): val
|
|
|
19
19
|
export declare function Clean(schema: TSchema, references: TSchema[], value: unknown): unknown;
|
|
20
20
|
/** `[Mutable]` Removes excess properties from a value and returns the result. This function does not check the value and returns an unknown type. You should Check the result before use. Clean is a mutable operation. To avoid mutation, Clone the value first. */
|
|
21
21
|
export declare function Clean(schema: TSchema, value: unknown): unknown;
|
|
22
|
-
/** Converts any type mismatched values to their target type if a reasonable conversion is possible */
|
|
22
|
+
/** Converts any type mismatched values to their target type if a reasonable conversion is possible. */
|
|
23
23
|
export declare function Convert(schema: TSchema, references: TSchema[], value: unknown): unknown;
|
|
24
|
-
/** Converts any type mismatched values to their target type if a reasonable conversion is
|
|
24
|
+
/** Converts any type mismatched values to their target type if a reasonable conversion is possible. */
|
|
25
25
|
export declare function Convert(schema: TSchema, value: unknown): unknown;
|
|
26
26
|
/** Returns a structural clone of the given value */
|
|
27
27
|
export declare function Clone<T>(value: T): T;
|
|
@@ -35,7 +35,7 @@ function Clean(...args) {
|
|
|
35
35
|
return index_9.Clean.apply(index_9.Clean, args);
|
|
36
36
|
}
|
|
37
37
|
exports.Clean = Clean;
|
|
38
|
-
/** Converts any type mismatched values to their target type if a reasonable conversion is possible */
|
|
38
|
+
/** Converts any type mismatched values to their target type if a reasonable conversion is possible. */
|
|
39
39
|
function Convert(...args) {
|
|
40
40
|
return index_7.Convert.apply(index_7.Convert, args);
|
|
41
41
|
}
|