@sinclair/typebox 0.29.6 → 0.30.0-dev-2
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/compiler/compiler.d.ts +7 -4
- package/compiler/compiler.js +208 -194
- package/errors/errors.d.ts +65 -60
- package/errors/errors.js +515 -492
- package/package.json +14 -2
- package/readme.md +161 -169
- package/system/system.js +0 -6
- package/typebox.d.ts +99 -52
- package/typebox.js +496 -573
- package/value/cast.d.ts +4 -4
- package/value/cast.js +254 -260
- package/value/check.d.ts +4 -3
- package/value/check.js +412 -397
- package/value/clone.d.ts +2 -3
- package/value/clone.js +62 -42
- package/value/convert.d.ts +4 -4
- package/value/convert.js +304 -318
- package/value/create.d.ts +4 -6
- package/value/create.js +386 -376
- package/value/delta.d.ts +2 -4
- package/value/delta.js +121 -130
- package/value/equal.d.ts +2 -3
- package/value/equal.js +48 -51
- package/value/guard.d.ts +44 -0
- package/value/guard.js +146 -0
- package/value/hash.d.ts +14 -3
- package/value/hash.js +124 -166
- package/value/index.d.ts +3 -4
- package/value/index.js +6 -20
- package/value/mutate.d.ts +2 -4
- package/value/mutate.js +75 -67
- package/value/pointer.js +8 -2
- package/value/value.d.ts +20 -20
- package/value/value.js +27 -27
- package/value/is.d.ts +0 -11
- package/value/is.js +0 -53
package/value/clone.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
}
|
|
1
|
+
/** Returns a clone of the given value */
|
|
2
|
+
export declare function Clone<T extends unknown>(value: T): T;
|
package/value/clone.js
CHANGED
|
@@ -27,45 +27,65 @@ THE SOFTWARE.
|
|
|
27
27
|
|
|
28
28
|
---------------------------------------------------------------------------*/
|
|
29
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
30
|
+
exports.Clone = void 0;
|
|
31
|
+
const ValueGuard = require("./guard");
|
|
32
|
+
// --------------------------------------------------------------------------
|
|
33
|
+
// Clonable
|
|
34
|
+
// --------------------------------------------------------------------------
|
|
35
|
+
function ObjectType(value) {
|
|
36
|
+
const keys = [...Object.getOwnPropertyNames(value), ...Object.getOwnPropertySymbols(value)];
|
|
37
|
+
return keys.reduce((acc, key) => ({ ...acc, [key]: Clone(value[key]) }), {});
|
|
38
|
+
}
|
|
39
|
+
function ArrayType(value) {
|
|
40
|
+
return value.map((element) => Clone(element));
|
|
41
|
+
}
|
|
42
|
+
function TypedArrayType(value) {
|
|
43
|
+
return value.slice();
|
|
44
|
+
}
|
|
45
|
+
function DateType(value) {
|
|
46
|
+
return new Date(value.toISOString());
|
|
47
|
+
}
|
|
48
|
+
function ValueType(value) {
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
// --------------------------------------------------------------------------
|
|
52
|
+
// Non-Clonable
|
|
53
|
+
// --------------------------------------------------------------------------
|
|
54
|
+
function AsyncIteratorType(value) {
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
function IteratorType(value) {
|
|
58
|
+
return value;
|
|
59
|
+
}
|
|
60
|
+
function FunctionType(value) {
|
|
61
|
+
return value;
|
|
62
|
+
}
|
|
63
|
+
function PromiseType(value) {
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
// --------------------------------------------------------------------------
|
|
67
|
+
// Clone
|
|
68
|
+
// --------------------------------------------------------------------------
|
|
69
|
+
/** Returns a clone of the given value */
|
|
70
|
+
function Clone(value) {
|
|
71
|
+
if (ValueGuard.IsArray(value))
|
|
72
|
+
return ArrayType(value);
|
|
73
|
+
if (ValueGuard.IsAsyncIterator(value))
|
|
74
|
+
return AsyncIteratorType(value);
|
|
75
|
+
if (ValueGuard.IsFunction(value))
|
|
76
|
+
return FunctionType(value);
|
|
77
|
+
if (ValueGuard.IsIterator(value))
|
|
78
|
+
return IteratorType(value);
|
|
79
|
+
if (ValueGuard.IsPromise(value))
|
|
80
|
+
return PromiseType(value);
|
|
81
|
+
if (ValueGuard.IsDate(value))
|
|
82
|
+
return DateType(value);
|
|
83
|
+
if (ValueGuard.IsPlainObject(value))
|
|
84
|
+
return ObjectType(value);
|
|
85
|
+
if (ValueGuard.IsTypedArray(value))
|
|
86
|
+
return TypedArrayType(value);
|
|
87
|
+
if (ValueGuard.IsValueType(value))
|
|
88
|
+
return ValueType(value);
|
|
89
|
+
throw new Error('ValueClone: Unable to clone value');
|
|
90
|
+
}
|
|
91
|
+
exports.Clone = Clone;
|
package/value/convert.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export declare class ValueConvertDereferenceError extends Error {
|
|
|
7
7
|
readonly schema: Types.TRef | Types.TThis;
|
|
8
8
|
constructor(schema: Types.TRef | Types.TThis);
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
/** Converts any type mismatched values to their target type if a reasonable conversion is possible. */
|
|
11
|
+
export declare function Convert<T extends Types.TSchema>(schema: T, references: Types.TSchema[], value: unknown): unknown;
|
|
12
|
+
/** Converts any type mismatched values to their target type if a reasonable conversion is possible. */
|
|
13
|
+
export declare function Convert<T extends Types.TSchema>(schema: T, value: unknown): unknown;
|