@sinclair/typebox 0.25.24 → 0.25.25
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 +25 -28
- package/compiler/compiler.js +495 -498
- package/compiler/index.d.ts +2 -2
- package/compiler/index.js +47 -47
- package/conditional/conditional.d.ts +17 -17
- package/conditional/conditional.js +91 -91
- package/conditional/index.d.ts +2 -2
- package/conditional/index.js +45 -45
- package/conditional/structural.d.ts +11 -11
- package/conditional/structural.js +685 -685
- package/custom/custom.d.ts +12 -12
- package/custom/custom.js +55 -55
- package/custom/index.d.ts +1 -1
- package/custom/index.js +44 -44
- package/errors/errors.d.ts +67 -67
- package/errors/errors.js +472 -472
- package/errors/index.d.ts +1 -1
- package/errors/index.js +44 -44
- package/format/format.d.ts +12 -12
- package/format/format.js +55 -55
- package/format/index.d.ts +1 -1
- package/format/index.js +44 -44
- package/guard/extends.d.ts +10 -10
- package/guard/extends.js +50 -50
- package/guard/guard.d.ts +60 -60
- package/guard/guard.js +440 -440
- package/guard/index.d.ts +2 -2
- package/guard/index.js +45 -45
- package/hash/hash.d.ts +8 -8
- package/hash/hash.js +183 -183
- package/hash/index.d.ts +1 -1
- package/hash/index.js +44 -44
- package/license +22 -22
- package/package.json +55 -52
- package/readme.md +1237 -1237
- package/system/index.d.ts +1 -1
- package/system/index.js +44 -44
- package/system/system.d.ts +17 -17
- package/system/system.js +69 -69
- package/typebox.d.ts +422 -422
- package/typebox.js +388 -388
- package/value/cast.d.ts +26 -26
- package/value/cast.js +415 -415
- package/value/check.d.ts +8 -8
- package/value/check.js +405 -405
- package/value/clone.d.ts +3 -3
- package/value/clone.js +71 -71
- package/value/create.d.ts +14 -14
- package/value/create.js +378 -378
- package/value/delta.d.ts +43 -43
- package/value/delta.js +204 -204
- package/value/equal.d.ts +3 -3
- package/value/equal.js +80 -80
- package/value/index.d.ts +4 -4
- package/value/index.js +53 -53
- package/value/is.d.ts +11 -11
- package/value/is.js +53 -53
- package/value/pointer.d.ts +24 -24
- package/value/pointer.js +142 -142
- package/value/value.d.ts +32 -32
- package/value/value.js +87 -87
package/value/pointer.js
CHANGED
|
@@ -1,142 +1,142 @@
|
|
|
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.ValuePointer = exports.ValuePointerRootDeleteError = exports.ValuePointerRootSetError = void 0;
|
|
31
|
-
class ValuePointerRootSetError extends Error {
|
|
32
|
-
constructor(value, path, update) {
|
|
33
|
-
super('ValuePointer: Cannot set root value');
|
|
34
|
-
this.value = value;
|
|
35
|
-
this.path = path;
|
|
36
|
-
this.update = update;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
exports.ValuePointerRootSetError = ValuePointerRootSetError;
|
|
40
|
-
class ValuePointerRootDeleteError extends Error {
|
|
41
|
-
constructor(value, path) {
|
|
42
|
-
super('ValuePointer: Cannot delete root value');
|
|
43
|
-
this.value = value;
|
|
44
|
-
this.path = path;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
exports.ValuePointerRootDeleteError = ValuePointerRootDeleteError;
|
|
48
|
-
/** Provides functionality to update values through RFC6901 string pointers */
|
|
49
|
-
var ValuePointer;
|
|
50
|
-
(function (ValuePointer) {
|
|
51
|
-
function Escape(component) {
|
|
52
|
-
return component.indexOf('~') === -1 ? component : component.replace(/~1/g, '/').replace(/~0/g, '~');
|
|
53
|
-
}
|
|
54
|
-
/** Formats the given pointer into navigable key components */
|
|
55
|
-
function* Format(pointer) {
|
|
56
|
-
if (pointer === '')
|
|
57
|
-
return;
|
|
58
|
-
let [start, end] = [0, 0];
|
|
59
|
-
for (let i = 0; i < pointer.length; i++) {
|
|
60
|
-
const char = pointer.charAt(i);
|
|
61
|
-
if (char === '/') {
|
|
62
|
-
if (i === 0) {
|
|
63
|
-
start = i + 1;
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
end = i;
|
|
67
|
-
yield Escape(pointer.slice(start, end));
|
|
68
|
-
start = i + 1;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
end = i;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
yield Escape(pointer.slice(start));
|
|
76
|
-
}
|
|
77
|
-
ValuePointer.Format = Format;
|
|
78
|
-
/** Sets the value at the given pointer. If the value at the pointer does not exist it is created */
|
|
79
|
-
function Set(value, pointer, update) {
|
|
80
|
-
if (pointer === '')
|
|
81
|
-
throw new ValuePointerRootSetError(value, pointer, update);
|
|
82
|
-
let [owner, next, key] = [null, value, ''];
|
|
83
|
-
for (const component of Format(pointer)) {
|
|
84
|
-
if (next[component] === undefined)
|
|
85
|
-
next[component] = {};
|
|
86
|
-
owner = next;
|
|
87
|
-
next = next[component];
|
|
88
|
-
key = component;
|
|
89
|
-
}
|
|
90
|
-
owner[key] = update;
|
|
91
|
-
}
|
|
92
|
-
ValuePointer.Set = Set;
|
|
93
|
-
/** Deletes a value at the given pointer */
|
|
94
|
-
function Delete(value, pointer) {
|
|
95
|
-
if (pointer === '')
|
|
96
|
-
throw new ValuePointerRootDeleteError(value, pointer);
|
|
97
|
-
let [owner, next, key] = [null, value, ''];
|
|
98
|
-
for (const component of Format(pointer)) {
|
|
99
|
-
if (next[component] === undefined || next[component] === null)
|
|
100
|
-
return;
|
|
101
|
-
owner = next;
|
|
102
|
-
next = next[component];
|
|
103
|
-
key = component;
|
|
104
|
-
}
|
|
105
|
-
if (globalThis.Array.isArray(owner)) {
|
|
106
|
-
const index = parseInt(key);
|
|
107
|
-
owner.splice(index, 1);
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
delete owner[key];
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
ValuePointer.Delete = Delete;
|
|
114
|
-
/** Returns true if a value exists at the given pointer */
|
|
115
|
-
function Has(value, pointer) {
|
|
116
|
-
if (pointer === '')
|
|
117
|
-
return true;
|
|
118
|
-
let [owner, next, key] = [null, value, ''];
|
|
119
|
-
for (const component of Format(pointer)) {
|
|
120
|
-
if (next[component] === undefined)
|
|
121
|
-
return false;
|
|
122
|
-
owner = next;
|
|
123
|
-
next = next[component];
|
|
124
|
-
key = component;
|
|
125
|
-
}
|
|
126
|
-
return globalThis.Object.getOwnPropertyNames(owner).includes(key);
|
|
127
|
-
}
|
|
128
|
-
ValuePointer.Has = Has;
|
|
129
|
-
/** Gets the value at the given pointer */
|
|
130
|
-
function Get(value, pointer) {
|
|
131
|
-
if (pointer === '')
|
|
132
|
-
return value;
|
|
133
|
-
let current = value;
|
|
134
|
-
for (const component of Format(pointer)) {
|
|
135
|
-
if (current[component] === undefined)
|
|
136
|
-
return undefined;
|
|
137
|
-
current = current[component];
|
|
138
|
-
}
|
|
139
|
-
return current;
|
|
140
|
-
}
|
|
141
|
-
ValuePointer.Get = Get;
|
|
142
|
-
})(ValuePointer = exports.ValuePointer || (exports.ValuePointer = {}));
|
|
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.ValuePointer = exports.ValuePointerRootDeleteError = exports.ValuePointerRootSetError = void 0;
|
|
31
|
+
class ValuePointerRootSetError extends Error {
|
|
32
|
+
constructor(value, path, update) {
|
|
33
|
+
super('ValuePointer: Cannot set root value');
|
|
34
|
+
this.value = value;
|
|
35
|
+
this.path = path;
|
|
36
|
+
this.update = update;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.ValuePointerRootSetError = ValuePointerRootSetError;
|
|
40
|
+
class ValuePointerRootDeleteError extends Error {
|
|
41
|
+
constructor(value, path) {
|
|
42
|
+
super('ValuePointer: Cannot delete root value');
|
|
43
|
+
this.value = value;
|
|
44
|
+
this.path = path;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.ValuePointerRootDeleteError = ValuePointerRootDeleteError;
|
|
48
|
+
/** Provides functionality to update values through RFC6901 string pointers */
|
|
49
|
+
var ValuePointer;
|
|
50
|
+
(function (ValuePointer) {
|
|
51
|
+
function Escape(component) {
|
|
52
|
+
return component.indexOf('~') === -1 ? component : component.replace(/~1/g, '/').replace(/~0/g, '~');
|
|
53
|
+
}
|
|
54
|
+
/** Formats the given pointer into navigable key components */
|
|
55
|
+
function* Format(pointer) {
|
|
56
|
+
if (pointer === '')
|
|
57
|
+
return;
|
|
58
|
+
let [start, end] = [0, 0];
|
|
59
|
+
for (let i = 0; i < pointer.length; i++) {
|
|
60
|
+
const char = pointer.charAt(i);
|
|
61
|
+
if (char === '/') {
|
|
62
|
+
if (i === 0) {
|
|
63
|
+
start = i + 1;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
end = i;
|
|
67
|
+
yield Escape(pointer.slice(start, end));
|
|
68
|
+
start = i + 1;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
end = i;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
yield Escape(pointer.slice(start));
|
|
76
|
+
}
|
|
77
|
+
ValuePointer.Format = Format;
|
|
78
|
+
/** Sets the value at the given pointer. If the value at the pointer does not exist it is created */
|
|
79
|
+
function Set(value, pointer, update) {
|
|
80
|
+
if (pointer === '')
|
|
81
|
+
throw new ValuePointerRootSetError(value, pointer, update);
|
|
82
|
+
let [owner, next, key] = [null, value, ''];
|
|
83
|
+
for (const component of Format(pointer)) {
|
|
84
|
+
if (next[component] === undefined)
|
|
85
|
+
next[component] = {};
|
|
86
|
+
owner = next;
|
|
87
|
+
next = next[component];
|
|
88
|
+
key = component;
|
|
89
|
+
}
|
|
90
|
+
owner[key] = update;
|
|
91
|
+
}
|
|
92
|
+
ValuePointer.Set = Set;
|
|
93
|
+
/** Deletes a value at the given pointer */
|
|
94
|
+
function Delete(value, pointer) {
|
|
95
|
+
if (pointer === '')
|
|
96
|
+
throw new ValuePointerRootDeleteError(value, pointer);
|
|
97
|
+
let [owner, next, key] = [null, value, ''];
|
|
98
|
+
for (const component of Format(pointer)) {
|
|
99
|
+
if (next[component] === undefined || next[component] === null)
|
|
100
|
+
return;
|
|
101
|
+
owner = next;
|
|
102
|
+
next = next[component];
|
|
103
|
+
key = component;
|
|
104
|
+
}
|
|
105
|
+
if (globalThis.Array.isArray(owner)) {
|
|
106
|
+
const index = parseInt(key);
|
|
107
|
+
owner.splice(index, 1);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
delete owner[key];
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
ValuePointer.Delete = Delete;
|
|
114
|
+
/** Returns true if a value exists at the given pointer */
|
|
115
|
+
function Has(value, pointer) {
|
|
116
|
+
if (pointer === '')
|
|
117
|
+
return true;
|
|
118
|
+
let [owner, next, key] = [null, value, ''];
|
|
119
|
+
for (const component of Format(pointer)) {
|
|
120
|
+
if (next[component] === undefined)
|
|
121
|
+
return false;
|
|
122
|
+
owner = next;
|
|
123
|
+
next = next[component];
|
|
124
|
+
key = component;
|
|
125
|
+
}
|
|
126
|
+
return globalThis.Object.getOwnPropertyNames(owner).includes(key);
|
|
127
|
+
}
|
|
128
|
+
ValuePointer.Has = Has;
|
|
129
|
+
/** Gets the value at the given pointer */
|
|
130
|
+
function Get(value, pointer) {
|
|
131
|
+
if (pointer === '')
|
|
132
|
+
return value;
|
|
133
|
+
let current = value;
|
|
134
|
+
for (const component of Format(pointer)) {
|
|
135
|
+
if (current[component] === undefined)
|
|
136
|
+
return undefined;
|
|
137
|
+
current = current[component];
|
|
138
|
+
}
|
|
139
|
+
return current;
|
|
140
|
+
}
|
|
141
|
+
ValuePointer.Get = Get;
|
|
142
|
+
})(ValuePointer = exports.ValuePointer || (exports.ValuePointer = {}));
|
package/value/value.d.ts
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import * as Types from '../typebox';
|
|
2
|
-
import { ValueError } from '../errors/index';
|
|
3
|
-
import { Edit } from './delta';
|
|
4
|
-
/** Provides functions to perform structural updates to JavaScript values */
|
|
5
|
-
export declare namespace Value {
|
|
6
|
-
/** Casts a value into a given type. The return value will retain as much information of the original value as possible. Cast will convert string, number, boolean and date values if a reasonable conversion is possible. */
|
|
7
|
-
function Cast<T extends Types.TSchema, R extends Types.TSchema[]>(schema: T, references: [...R], value: unknown): Types.Static<T>;
|
|
8
|
-
/** Casts a value into a given type. The return value will retain as much information of the original value as possible. Cast will convert string, number, boolean and date values if a reasonable conversion is possible. */
|
|
9
|
-
function Cast<T extends Types.TSchema>(schema: T, value: unknown): Types.Static<T>;
|
|
10
|
-
/** Creates a value from the given type */
|
|
11
|
-
function Create<T extends Types.TSchema, R extends Types.TSchema[]>(schema: T, references: [...R]): Types.Static<T>;
|
|
12
|
-
/** Creates a value from the given type */
|
|
13
|
-
function Create<T extends Types.TSchema>(schema: T): Types.Static<T>;
|
|
14
|
-
/** Returns true if the value matches the given type. */
|
|
15
|
-
function Check<T extends Types.TSchema, R extends Types.TSchema[]>(schema: T, references: [...R], value: unknown): value is Types.Static<T>;
|
|
16
|
-
/** Returns true if the value matches the given type. */
|
|
17
|
-
function Check<T extends Types.TSchema>(schema: T, value: unknown): value is Types.Static<T>;
|
|
18
|
-
/** Returns a structural clone of the given value */
|
|
19
|
-
function Clone<T>(value: T): T;
|
|
20
|
-
/** Returns an iterator for each error in this value. */
|
|
21
|
-
function Errors<T extends Types.TSchema, R extends Types.TSchema[]>(schema: T, references: [...R], value: unknown): IterableIterator<ValueError>;
|
|
22
|
-
/** Returns an iterator for each error in this value. */
|
|
23
|
-
function Errors<T extends Types.TSchema>(schema: T, value: unknown): IterableIterator<ValueError>;
|
|
24
|
-
/** Returns true if left and right values are structurally equal */
|
|
25
|
-
function Equal<T>(left: T, right: unknown): right is T;
|
|
26
|
-
/** Returns edits to transform the current value into the next value */
|
|
27
|
-
function Diff(current: unknown, next: unknown): Edit[];
|
|
28
|
-
/** Returns a FNV1A-64 non cryptographic hash of the given value */
|
|
29
|
-
function Hash(value: unknown): bigint;
|
|
30
|
-
/** Returns a new value with edits applied to the given value */
|
|
31
|
-
function Patch<T = any>(current: unknown, edits: Edit[]): T;
|
|
32
|
-
}
|
|
1
|
+
import * as Types from '../typebox';
|
|
2
|
+
import { ValueError } from '../errors/index';
|
|
3
|
+
import { Edit } from './delta';
|
|
4
|
+
/** Provides functions to perform structural updates to JavaScript values */
|
|
5
|
+
export declare namespace Value {
|
|
6
|
+
/** Casts a value into a given type. The return value will retain as much information of the original value as possible. Cast will convert string, number, boolean and date values if a reasonable conversion is possible. */
|
|
7
|
+
function Cast<T extends Types.TSchema, R extends Types.TSchema[]>(schema: T, references: [...R], value: unknown): Types.Static<T>;
|
|
8
|
+
/** Casts a value into a given type. The return value will retain as much information of the original value as possible. Cast will convert string, number, boolean and date values if a reasonable conversion is possible. */
|
|
9
|
+
function Cast<T extends Types.TSchema>(schema: T, value: unknown): Types.Static<T>;
|
|
10
|
+
/** Creates a value from the given type */
|
|
11
|
+
function Create<T extends Types.TSchema, R extends Types.TSchema[]>(schema: T, references: [...R]): Types.Static<T>;
|
|
12
|
+
/** Creates a value from the given type */
|
|
13
|
+
function Create<T extends Types.TSchema>(schema: T): Types.Static<T>;
|
|
14
|
+
/** Returns true if the value matches the given type. */
|
|
15
|
+
function Check<T extends Types.TSchema, R extends Types.TSchema[]>(schema: T, references: [...R], value: unknown): value is Types.Static<T>;
|
|
16
|
+
/** Returns true if the value matches the given type. */
|
|
17
|
+
function Check<T extends Types.TSchema>(schema: T, value: unknown): value is Types.Static<T>;
|
|
18
|
+
/** Returns a structural clone of the given value */
|
|
19
|
+
function Clone<T>(value: T): T;
|
|
20
|
+
/** Returns an iterator for each error in this value. */
|
|
21
|
+
function Errors<T extends Types.TSchema, R extends Types.TSchema[]>(schema: T, references: [...R], value: unknown): IterableIterator<ValueError>;
|
|
22
|
+
/** Returns an iterator for each error in this value. */
|
|
23
|
+
function Errors<T extends Types.TSchema>(schema: T, value: unknown): IterableIterator<ValueError>;
|
|
24
|
+
/** Returns true if left and right values are structurally equal */
|
|
25
|
+
function Equal<T>(left: T, right: unknown): right is T;
|
|
26
|
+
/** Returns edits to transform the current value into the next value */
|
|
27
|
+
function Diff(current: unknown, next: unknown): Edit[];
|
|
28
|
+
/** Returns a FNV1A-64 non cryptographic hash of the given value */
|
|
29
|
+
function Hash(value: unknown): bigint;
|
|
30
|
+
/** Returns a new value with edits applied to the given value */
|
|
31
|
+
function Patch<T = any>(current: unknown, edits: Edit[]): T;
|
|
32
|
+
}
|
package/value/value.js
CHANGED
|
@@ -1,87 +1,87 @@
|
|
|
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.Value = void 0;
|
|
31
|
-
const index_1 = require("../errors/index");
|
|
32
|
-
const index_2 = require("../hash/index");
|
|
33
|
-
const equal_1 = require("./equal");
|
|
34
|
-
const cast_1 = require("./cast");
|
|
35
|
-
const clone_1 = require("./clone");
|
|
36
|
-
const create_1 = require("./create");
|
|
37
|
-
const check_1 = require("./check");
|
|
38
|
-
const delta_1 = require("./delta");
|
|
39
|
-
/** Provides functions to perform structural updates to JavaScript values */
|
|
40
|
-
var Value;
|
|
41
|
-
(function (Value) {
|
|
42
|
-
function Cast(...args) {
|
|
43
|
-
const [schema, references, value] = args.length === 3 ? [args[0], args[1], args[2]] : [args[0], [], args[1]];
|
|
44
|
-
return cast_1.ValueCast.Cast(schema, references, value);
|
|
45
|
-
}
|
|
46
|
-
Value.Cast = Cast;
|
|
47
|
-
function Create(...args) {
|
|
48
|
-
const [schema, references] = args.length === 2 ? [args[0], args[1]] : [args[0], []];
|
|
49
|
-
return create_1.ValueCreate.Create(schema, references);
|
|
50
|
-
}
|
|
51
|
-
Value.Create = Create;
|
|
52
|
-
function Check(...args) {
|
|
53
|
-
const [schema, references, value] = args.length === 3 ? [args[0], args[1], args[2]] : [args[0], [], args[1]];
|
|
54
|
-
return check_1.ValueCheck.Check(schema, references, value);
|
|
55
|
-
}
|
|
56
|
-
Value.Check = Check;
|
|
57
|
-
/** Returns a structural clone of the given value */
|
|
58
|
-
function Clone(value) {
|
|
59
|
-
return clone_1.ValueClone.Clone(value);
|
|
60
|
-
}
|
|
61
|
-
Value.Clone = Clone;
|
|
62
|
-
function* Errors(...args) {
|
|
63
|
-
const [schema, references, value] = args.length === 3 ? [args[0], args[1], args[2]] : [args[0], [], args[1]];
|
|
64
|
-
yield* index_1.ValueErrors.Errors(schema, references, value);
|
|
65
|
-
}
|
|
66
|
-
Value.Errors = Errors;
|
|
67
|
-
/** Returns true if left and right values are structurally equal */
|
|
68
|
-
function Equal(left, right) {
|
|
69
|
-
return equal_1.ValueEqual.Equal(left, right);
|
|
70
|
-
}
|
|
71
|
-
Value.Equal = Equal;
|
|
72
|
-
/** Returns edits to transform the current value into the next value */
|
|
73
|
-
function Diff(current, next) {
|
|
74
|
-
return delta_1.ValueDelta.Diff(current, next);
|
|
75
|
-
}
|
|
76
|
-
Value.Diff = Diff;
|
|
77
|
-
/** Returns a FNV1A-64 non cryptographic hash of the given value */
|
|
78
|
-
function Hash(value) {
|
|
79
|
-
return index_2.ValueHash.Create(value);
|
|
80
|
-
}
|
|
81
|
-
Value.Hash = Hash;
|
|
82
|
-
/** Returns a new value with edits applied to the given value */
|
|
83
|
-
function Patch(current, edits) {
|
|
84
|
-
return delta_1.ValueDelta.Patch(current, edits);
|
|
85
|
-
}
|
|
86
|
-
Value.Patch = Patch;
|
|
87
|
-
})(Value = exports.Value || (exports.Value = {}));
|
|
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.Value = void 0;
|
|
31
|
+
const index_1 = require("../errors/index");
|
|
32
|
+
const index_2 = require("../hash/index");
|
|
33
|
+
const equal_1 = require("./equal");
|
|
34
|
+
const cast_1 = require("./cast");
|
|
35
|
+
const clone_1 = require("./clone");
|
|
36
|
+
const create_1 = require("./create");
|
|
37
|
+
const check_1 = require("./check");
|
|
38
|
+
const delta_1 = require("./delta");
|
|
39
|
+
/** Provides functions to perform structural updates to JavaScript values */
|
|
40
|
+
var Value;
|
|
41
|
+
(function (Value) {
|
|
42
|
+
function Cast(...args) {
|
|
43
|
+
const [schema, references, value] = args.length === 3 ? [args[0], args[1], args[2]] : [args[0], [], args[1]];
|
|
44
|
+
return cast_1.ValueCast.Cast(schema, references, value);
|
|
45
|
+
}
|
|
46
|
+
Value.Cast = Cast;
|
|
47
|
+
function Create(...args) {
|
|
48
|
+
const [schema, references] = args.length === 2 ? [args[0], args[1]] : [args[0], []];
|
|
49
|
+
return create_1.ValueCreate.Create(schema, references);
|
|
50
|
+
}
|
|
51
|
+
Value.Create = Create;
|
|
52
|
+
function Check(...args) {
|
|
53
|
+
const [schema, references, value] = args.length === 3 ? [args[0], args[1], args[2]] : [args[0], [], args[1]];
|
|
54
|
+
return check_1.ValueCheck.Check(schema, references, value);
|
|
55
|
+
}
|
|
56
|
+
Value.Check = Check;
|
|
57
|
+
/** Returns a structural clone of the given value */
|
|
58
|
+
function Clone(value) {
|
|
59
|
+
return clone_1.ValueClone.Clone(value);
|
|
60
|
+
}
|
|
61
|
+
Value.Clone = Clone;
|
|
62
|
+
function* Errors(...args) {
|
|
63
|
+
const [schema, references, value] = args.length === 3 ? [args[0], args[1], args[2]] : [args[0], [], args[1]];
|
|
64
|
+
yield* index_1.ValueErrors.Errors(schema, references, value);
|
|
65
|
+
}
|
|
66
|
+
Value.Errors = Errors;
|
|
67
|
+
/** Returns true if left and right values are structurally equal */
|
|
68
|
+
function Equal(left, right) {
|
|
69
|
+
return equal_1.ValueEqual.Equal(left, right);
|
|
70
|
+
}
|
|
71
|
+
Value.Equal = Equal;
|
|
72
|
+
/** Returns edits to transform the current value into the next value */
|
|
73
|
+
function Diff(current, next) {
|
|
74
|
+
return delta_1.ValueDelta.Diff(current, next);
|
|
75
|
+
}
|
|
76
|
+
Value.Diff = Diff;
|
|
77
|
+
/** Returns a FNV1A-64 non cryptographic hash of the given value */
|
|
78
|
+
function Hash(value) {
|
|
79
|
+
return index_2.ValueHash.Create(value);
|
|
80
|
+
}
|
|
81
|
+
Value.Hash = Hash;
|
|
82
|
+
/** Returns a new value with edits applied to the given value */
|
|
83
|
+
function Patch(current, edits) {
|
|
84
|
+
return delta_1.ValueDelta.Patch(current, edits);
|
|
85
|
+
}
|
|
86
|
+
Value.Patch = Patch;
|
|
87
|
+
})(Value = exports.Value || (exports.Value = {}));
|