@sinclair/typebox 0.29.6 → 0.30.0-dev-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/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 +5 -4
- package/value/cast.js +255 -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 +5 -4
- package/value/convert.js +305 -318
- package/value/create.d.ts +6 -6
- package/value/create.js +388 -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 +15 -15
- package/value/value.js +27 -27
- package/value/is.d.ts +0 -11
- package/value/is.js +0 -53
package/value/value.js
CHANGED
|
@@ -28,72 +28,72 @@ THE SOFTWARE.
|
|
|
28
28
|
---------------------------------------------------------------------------*/
|
|
29
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
30
|
exports.Value = void 0;
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
/**
|
|
31
|
+
const ValueErrors = require("../errors/index");
|
|
32
|
+
const ValueMutate = require("./mutate");
|
|
33
|
+
const ValueHash = require("./hash");
|
|
34
|
+
const ValueEqual = require("./equal");
|
|
35
|
+
const ValueCast = require("./cast");
|
|
36
|
+
const ValueClone = require("./clone");
|
|
37
|
+
const ValueConvert = require("./convert");
|
|
38
|
+
const ValueCreate = require("./create");
|
|
39
|
+
const ValueCheck = require("./check");
|
|
40
|
+
const ValueDelta = require("./delta");
|
|
41
|
+
/** Functions to perform structural operations on JavaScript values */
|
|
42
42
|
var Value;
|
|
43
43
|
(function (Value) {
|
|
44
|
+
/** Casts a value into a given type. The return value will retain as much information of the original value as possible. */
|
|
44
45
|
function Cast(...args) {
|
|
45
|
-
|
|
46
|
-
return cast_1.ValueCast.Cast(schema, references, value);
|
|
46
|
+
return ValueCast.Cast.apply(ValueCast, args);
|
|
47
47
|
}
|
|
48
48
|
Value.Cast = Cast;
|
|
49
|
+
/** Creates a value from the given type */
|
|
49
50
|
function Create(...args) {
|
|
50
|
-
|
|
51
|
-
return create_1.ValueCreate.Create(schema, references);
|
|
51
|
+
return ValueCreate.Create.apply(ValueCreate, args);
|
|
52
52
|
}
|
|
53
53
|
Value.Create = Create;
|
|
54
|
+
/** Returns true if the value matches the given type. */
|
|
54
55
|
function Check(...args) {
|
|
55
|
-
|
|
56
|
-
return check_1.ValueCheck.Check(schema, references, value);
|
|
56
|
+
return ValueCheck.Check.apply(ValueCheck, args);
|
|
57
57
|
}
|
|
58
58
|
Value.Check = Check;
|
|
59
|
+
/** Converts any type mismatched values to their target type if a conversion is possible. */
|
|
59
60
|
function Convert(...args) {
|
|
60
|
-
|
|
61
|
-
return convert_1.ValueConvert.Convert(schema, references, value);
|
|
61
|
+
return ValueConvert.Convert.apply(ValueConvert, args);
|
|
62
62
|
}
|
|
63
63
|
Value.Convert = Convert;
|
|
64
64
|
/** Returns a structural clone of the given value */
|
|
65
65
|
function Clone(value) {
|
|
66
|
-
return
|
|
66
|
+
return ValueClone.Clone(value);
|
|
67
67
|
}
|
|
68
68
|
Value.Clone = Clone;
|
|
69
|
+
/** Returns an iterator for each error in this value. */
|
|
69
70
|
function Errors(...args) {
|
|
70
|
-
|
|
71
|
-
return index_1.ValueErrors.Errors(schema, references, value);
|
|
71
|
+
return ValueErrors.Errors.apply(ValueErrors, args);
|
|
72
72
|
}
|
|
73
73
|
Value.Errors = Errors;
|
|
74
74
|
/** Returns true if left and right values are structurally equal */
|
|
75
75
|
function Equal(left, right) {
|
|
76
|
-
return
|
|
76
|
+
return ValueEqual.Equal(left, right);
|
|
77
77
|
}
|
|
78
78
|
Value.Equal = Equal;
|
|
79
79
|
/** Returns edits to transform the current value into the next value */
|
|
80
80
|
function Diff(current, next) {
|
|
81
|
-
return
|
|
81
|
+
return ValueDelta.Diff(current, next);
|
|
82
82
|
}
|
|
83
83
|
Value.Diff = Diff;
|
|
84
84
|
/** Returns a FNV1A-64 non cryptographic hash of the given value */
|
|
85
85
|
function Hash(value) {
|
|
86
|
-
return
|
|
86
|
+
return ValueHash.Hash(value);
|
|
87
87
|
}
|
|
88
88
|
Value.Hash = Hash;
|
|
89
89
|
/** Returns a new value with edits applied to the given value */
|
|
90
90
|
function Patch(current, edits) {
|
|
91
|
-
return
|
|
91
|
+
return ValueDelta.Patch(current, edits);
|
|
92
92
|
}
|
|
93
93
|
Value.Patch = Patch;
|
|
94
94
|
/** Performs a deep mutable value assignment while retaining internal references. */
|
|
95
95
|
function Mutate(current, next) {
|
|
96
|
-
|
|
96
|
+
ValueMutate.Mutate(current, next);
|
|
97
97
|
}
|
|
98
98
|
Value.Mutate = Mutate;
|
|
99
99
|
})(Value || (exports.Value = Value = {}));
|
package/value/is.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export type ValueType = null | undefined | Function | symbol | bigint | number | boolean | string;
|
|
2
|
-
export type ObjectType = Record<string | number | symbol, unknown>;
|
|
3
|
-
export type TypedArrayType = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array;
|
|
4
|
-
export type ArrayType = unknown[];
|
|
5
|
-
export declare namespace Is {
|
|
6
|
-
function Object(value: unknown): value is ObjectType;
|
|
7
|
-
function Date(value: unknown): value is Date;
|
|
8
|
-
function Array(value: unknown): value is ArrayType;
|
|
9
|
-
function Value(value: unknown): value is ValueType;
|
|
10
|
-
function TypedArray(value: unknown): value is TypedArrayType;
|
|
11
|
-
}
|
package/value/is.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*--------------------------------------------------------------------------
|
|
3
|
-
|
|
4
|
-
@sinclair/typebox/value
|
|
5
|
-
|
|
6
|
-
The MIT License (MIT)
|
|
7
|
-
|
|
8
|
-
Copyright (c) 2017-2023 Haydn Paterson (sinclair) <haydn.developer@gmail.com>
|
|
9
|
-
|
|
10
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
-
in the Software without restriction, including without limitation the rights
|
|
13
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
-
furnished to do so, subject to the following conditions:
|
|
16
|
-
|
|
17
|
-
The above copyright notice and this permission notice shall be included in
|
|
18
|
-
all copies or substantial portions of the Software.
|
|
19
|
-
|
|
20
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
26
|
-
THE SOFTWARE.
|
|
27
|
-
|
|
28
|
-
---------------------------------------------------------------------------*/
|
|
29
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.Is = void 0;
|
|
31
|
-
var Is;
|
|
32
|
-
(function (Is) {
|
|
33
|
-
function Object(value) {
|
|
34
|
-
return value !== null && typeof value === 'object' && !globalThis.Array.isArray(value) && !ArrayBuffer.isView(value) && !(value instanceof globalThis.Date);
|
|
35
|
-
}
|
|
36
|
-
Is.Object = Object;
|
|
37
|
-
function Date(value) {
|
|
38
|
-
return value instanceof globalThis.Date;
|
|
39
|
-
}
|
|
40
|
-
Is.Date = Date;
|
|
41
|
-
function Array(value) {
|
|
42
|
-
return globalThis.Array.isArray(value) && !ArrayBuffer.isView(value);
|
|
43
|
-
}
|
|
44
|
-
Is.Array = Array;
|
|
45
|
-
function Value(value) {
|
|
46
|
-
return value === null || value === undefined || typeof value === 'function' || typeof value === 'symbol' || typeof value === 'bigint' || typeof value === 'number' || typeof value === 'boolean' || typeof value === 'string';
|
|
47
|
-
}
|
|
48
|
-
Is.Value = Value;
|
|
49
|
-
function TypedArray(value) {
|
|
50
|
-
return ArrayBuffer.isView(value);
|
|
51
|
-
}
|
|
52
|
-
Is.TypedArray = TypedArray;
|
|
53
|
-
})(Is || (exports.Is = Is = {}));
|