@sinclair/typebox 0.26.0-dev.2 → 0.26.0-dev.4

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/value/equal.js CHANGED
@@ -1,80 +1,80 @@
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.ValueEqual = void 0;
31
- const is_1 = require("./is");
32
- var ValueEqual;
33
- (function (ValueEqual) {
34
- function Object(left, right) {
35
- if (!is_1.Is.Object(right))
36
- return false;
37
- const leftKeys = [...globalThis.Object.keys(left), ...globalThis.Object.getOwnPropertySymbols(left)];
38
- const rightKeys = [...globalThis.Object.keys(right), ...globalThis.Object.getOwnPropertySymbols(right)];
39
- if (leftKeys.length !== rightKeys.length)
40
- return false;
41
- return leftKeys.every((key) => Equal(left[key], right[key]));
42
- }
43
- function Date(left, right) {
44
- return is_1.Is.Date(right) && left.getTime() === right.getTime();
45
- }
46
- function Array(left, right) {
47
- if (!is_1.Is.Array(right) || left.length !== right.length)
48
- return false;
49
- return left.every((value, index) => Equal(value, right[index]));
50
- }
51
- function TypedArray(left, right) {
52
- if (!is_1.Is.TypedArray(right) || left.length !== right.length || globalThis.Object.getPrototypeOf(left).constructor.name !== globalThis.Object.getPrototypeOf(right).constructor.name)
53
- return false;
54
- return left.every((value, index) => Equal(value, right[index]));
55
- }
56
- function Value(left, right) {
57
- return left === right;
58
- }
59
- function Equal(left, right) {
60
- if (is_1.Is.Object(left)) {
61
- return Object(left, right);
62
- }
63
- else if (is_1.Is.Date(left)) {
64
- return Date(left, right);
65
- }
66
- else if (is_1.Is.TypedArray(left)) {
67
- return TypedArray(left, right);
68
- }
69
- else if (is_1.Is.Array(left)) {
70
- return Array(left, right);
71
- }
72
- else if (is_1.Is.Value(left)) {
73
- return Value(left, right);
74
- }
75
- else {
76
- throw new Error('ValueEquals: Unable to compare value');
77
- }
78
- }
79
- ValueEqual.Equal = Equal;
80
- })(ValueEqual = exports.ValueEqual || (exports.ValueEqual = {}));
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.ValueEqual = void 0;
31
+ const is_1 = require("./is");
32
+ var ValueEqual;
33
+ (function (ValueEqual) {
34
+ function Object(left, right) {
35
+ if (!is_1.Is.Object(right))
36
+ return false;
37
+ const leftKeys = [...globalThis.Object.keys(left), ...globalThis.Object.getOwnPropertySymbols(left)];
38
+ const rightKeys = [...globalThis.Object.keys(right), ...globalThis.Object.getOwnPropertySymbols(right)];
39
+ if (leftKeys.length !== rightKeys.length)
40
+ return false;
41
+ return leftKeys.every((key) => Equal(left[key], right[key]));
42
+ }
43
+ function Date(left, right) {
44
+ return is_1.Is.Date(right) && left.getTime() === right.getTime();
45
+ }
46
+ function Array(left, right) {
47
+ if (!is_1.Is.Array(right) || left.length !== right.length)
48
+ return false;
49
+ return left.every((value, index) => Equal(value, right[index]));
50
+ }
51
+ function TypedArray(left, right) {
52
+ if (!is_1.Is.TypedArray(right) || left.length !== right.length || globalThis.Object.getPrototypeOf(left).constructor.name !== globalThis.Object.getPrototypeOf(right).constructor.name)
53
+ return false;
54
+ return left.every((value, index) => Equal(value, right[index]));
55
+ }
56
+ function Value(left, right) {
57
+ return left === right;
58
+ }
59
+ function Equal(left, right) {
60
+ if (is_1.Is.Object(left)) {
61
+ return Object(left, right);
62
+ }
63
+ else if (is_1.Is.Date(left)) {
64
+ return Date(left, right);
65
+ }
66
+ else if (is_1.Is.TypedArray(left)) {
67
+ return TypedArray(left, right);
68
+ }
69
+ else if (is_1.Is.Array(left)) {
70
+ return Array(left, right);
71
+ }
72
+ else if (is_1.Is.Value(left)) {
73
+ return Value(left, right);
74
+ }
75
+ else {
76
+ throw new Error('ValueEquals: Unable to compare value');
77
+ }
78
+ }
79
+ ValueEqual.Equal = Equal;
80
+ })(ValueEqual = exports.ValueEqual || (exports.ValueEqual = {}));
package/value/hash.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- export declare class ValueHashError extends Error {
2
- readonly value: unknown;
3
- constructor(value: unknown);
4
- }
5
- export declare namespace ValueHash {
6
- /** Creates a FNV1A-64 non cryptographic hash of the given value */
7
- function Create(value: unknown): bigint;
8
- }
1
+ export declare class ValueHashError extends Error {
2
+ readonly value: unknown;
3
+ constructor(value: unknown);
4
+ }
5
+ export declare namespace ValueHash {
6
+ /** Creates a FNV1A-64 non cryptographic hash of the given value */
7
+ function Create(value: unknown): bigint;
8
+ }
package/value/hash.js CHANGED
@@ -1,208 +1,208 @@
1
- "use strict";
2
- /*--------------------------------------------------------------------------
3
-
4
- @sinclair/typebox/hash
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.ValueHash = exports.ValueHashError = void 0;
31
- class ValueHashError extends Error {
32
- constructor(value) {
33
- super(`Hash: Unable to hash value`);
34
- this.value = value;
35
- }
36
- }
37
- exports.ValueHashError = ValueHashError;
38
- var ValueHash;
39
- (function (ValueHash) {
40
- let ByteMarker;
41
- (function (ByteMarker) {
42
- ByteMarker[ByteMarker["Undefined"] = 0] = "Undefined";
43
- ByteMarker[ByteMarker["Null"] = 1] = "Null";
44
- ByteMarker[ByteMarker["Boolean"] = 2] = "Boolean";
45
- ByteMarker[ByteMarker["Number"] = 3] = "Number";
46
- ByteMarker[ByteMarker["String"] = 4] = "String";
47
- ByteMarker[ByteMarker["Object"] = 5] = "Object";
48
- ByteMarker[ByteMarker["Array"] = 6] = "Array";
49
- ByteMarker[ByteMarker["Date"] = 7] = "Date";
50
- ByteMarker[ByteMarker["Uint8Array"] = 8] = "Uint8Array";
51
- ByteMarker[ByteMarker["Symbol"] = 9] = "Symbol";
52
- ByteMarker[ByteMarker["BigInt"] = 10] = "BigInt";
53
- })(ByteMarker || (ByteMarker = {}));
54
- // ----------------------------------------------------
55
- // State
56
- // ----------------------------------------------------
57
- let Hash = globalThis.BigInt('14695981039346656037');
58
- const [Prime, Size] = [globalThis.BigInt('1099511628211'), globalThis.BigInt('2') ** globalThis.BigInt('64')];
59
- const Bytes = globalThis.Array.from({ length: 256 }).map((_, i) => globalThis.BigInt(i));
60
- const F64 = new globalThis.Float64Array(1);
61
- const F64In = new globalThis.DataView(F64.buffer);
62
- const F64Out = new globalThis.Uint8Array(F64.buffer);
63
- // ----------------------------------------------------
64
- // Guards
65
- // ----------------------------------------------------
66
- function IsDate(value) {
67
- return value instanceof globalThis.Date;
68
- }
69
- function IsUint8Array(value) {
70
- return value instanceof globalThis.Uint8Array;
71
- }
72
- function IsArray(value) {
73
- return globalThis.Array.isArray(value);
74
- }
75
- function IsBoolean(value) {
76
- return typeof value === 'boolean';
77
- }
78
- function IsNull(value) {
79
- return value === null;
80
- }
81
- function IsNumber(value) {
82
- return typeof value === 'number';
83
- }
84
- function IsSymbol(value) {
85
- return typeof value === 'symbol';
86
- }
87
- function IsBigInt(value) {
88
- return typeof value === 'bigint';
89
- }
90
- function IsObject(value) {
91
- return typeof value === 'object' && value !== null && !IsArray(value) && !IsDate(value) && !IsUint8Array(value);
92
- }
93
- function IsString(value) {
94
- return typeof value === 'string';
95
- }
96
- function IsUndefined(value) {
97
- return value === undefined;
98
- }
99
- // ----------------------------------------------------
100
- // Encoding
101
- // ----------------------------------------------------
102
- function Array(value) {
103
- FNV1A64(ByteMarker.Array);
104
- for (const item of value) {
105
- Visit(item);
106
- }
107
- }
108
- function Boolean(value) {
109
- FNV1A64(ByteMarker.Boolean);
110
- FNV1A64(value ? 1 : 0);
111
- }
112
- function BigInt(value) {
113
- FNV1A64(ByteMarker.BigInt);
114
- F64In.setBigInt64(0, value);
115
- for (const byte of F64Out) {
116
- FNV1A64(byte);
117
- }
118
- }
119
- function Date(value) {
120
- FNV1A64(ByteMarker.Date);
121
- Visit(value.getTime());
122
- }
123
- function Null(value) {
124
- FNV1A64(ByteMarker.Null);
125
- }
126
- function Number(value) {
127
- FNV1A64(ByteMarker.Number);
128
- F64In.setFloat64(0, value);
129
- for (const byte of F64Out) {
130
- FNV1A64(byte);
131
- }
132
- }
133
- function Object(value) {
134
- FNV1A64(ByteMarker.Object);
135
- for (const key of globalThis.Object.keys(value).sort()) {
136
- Visit(key);
137
- Visit(value[key]);
138
- }
139
- }
140
- function String(value) {
141
- FNV1A64(ByteMarker.String);
142
- for (let i = 0; i < value.length; i++) {
143
- FNV1A64(value.charCodeAt(i));
144
- }
145
- }
146
- function Symbol(value) {
147
- FNV1A64(ByteMarker.Symbol);
148
- Visit(value.description);
149
- }
150
- function Uint8Array(value) {
151
- FNV1A64(ByteMarker.Uint8Array);
152
- for (let i = 0; i < value.length; i++) {
153
- FNV1A64(value[i]);
154
- }
155
- }
156
- function Undefined(value) {
157
- return FNV1A64(ByteMarker.Undefined);
158
- }
159
- function Visit(value) {
160
- if (IsArray(value)) {
161
- Array(value);
162
- }
163
- else if (IsBoolean(value)) {
164
- Boolean(value);
165
- }
166
- else if (IsBigInt(value)) {
167
- BigInt(value);
168
- }
169
- else if (IsDate(value)) {
170
- Date(value);
171
- }
172
- else if (IsNull(value)) {
173
- Null(value);
174
- }
175
- else if (IsNumber(value)) {
176
- Number(value);
177
- }
178
- else if (IsObject(value)) {
179
- Object(value);
180
- }
181
- else if (IsString(value)) {
182
- String(value);
183
- }
184
- else if (IsSymbol(value)) {
185
- Symbol(value);
186
- }
187
- else if (IsUint8Array(value)) {
188
- Uint8Array(value);
189
- }
190
- else if (IsUndefined(value)) {
191
- Undefined(value);
192
- }
193
- else {
194
- throw new ValueHashError(value);
195
- }
196
- }
197
- function FNV1A64(byte) {
198
- Hash = Hash ^ Bytes[byte];
199
- Hash = (Hash * Prime) % Size;
200
- }
201
- /** Creates a FNV1A-64 non cryptographic hash of the given value */
202
- function Create(value) {
203
- Hash = globalThis.BigInt('14695981039346656037');
204
- Visit(value);
205
- return Hash;
206
- }
207
- ValueHash.Create = Create;
208
- })(ValueHash = exports.ValueHash || (exports.ValueHash = {}));
1
+ "use strict";
2
+ /*--------------------------------------------------------------------------
3
+
4
+ @sinclair/typebox/hash
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.ValueHash = exports.ValueHashError = void 0;
31
+ class ValueHashError extends Error {
32
+ constructor(value) {
33
+ super(`Hash: Unable to hash value`);
34
+ this.value = value;
35
+ }
36
+ }
37
+ exports.ValueHashError = ValueHashError;
38
+ var ValueHash;
39
+ (function (ValueHash) {
40
+ let ByteMarker;
41
+ (function (ByteMarker) {
42
+ ByteMarker[ByteMarker["Undefined"] = 0] = "Undefined";
43
+ ByteMarker[ByteMarker["Null"] = 1] = "Null";
44
+ ByteMarker[ByteMarker["Boolean"] = 2] = "Boolean";
45
+ ByteMarker[ByteMarker["Number"] = 3] = "Number";
46
+ ByteMarker[ByteMarker["String"] = 4] = "String";
47
+ ByteMarker[ByteMarker["Object"] = 5] = "Object";
48
+ ByteMarker[ByteMarker["Array"] = 6] = "Array";
49
+ ByteMarker[ByteMarker["Date"] = 7] = "Date";
50
+ ByteMarker[ByteMarker["Uint8Array"] = 8] = "Uint8Array";
51
+ ByteMarker[ByteMarker["Symbol"] = 9] = "Symbol";
52
+ ByteMarker[ByteMarker["BigInt"] = 10] = "BigInt";
53
+ })(ByteMarker || (ByteMarker = {}));
54
+ // ----------------------------------------------------
55
+ // State
56
+ // ----------------------------------------------------
57
+ let Hash = globalThis.BigInt('14695981039346656037');
58
+ const [Prime, Size] = [globalThis.BigInt('1099511628211'), globalThis.BigInt('2') ** globalThis.BigInt('64')];
59
+ const Bytes = globalThis.Array.from({ length: 256 }).map((_, i) => globalThis.BigInt(i));
60
+ const F64 = new globalThis.Float64Array(1);
61
+ const F64In = new globalThis.DataView(F64.buffer);
62
+ const F64Out = new globalThis.Uint8Array(F64.buffer);
63
+ // ----------------------------------------------------
64
+ // Guards
65
+ // ----------------------------------------------------
66
+ function IsDate(value) {
67
+ return value instanceof globalThis.Date;
68
+ }
69
+ function IsUint8Array(value) {
70
+ return value instanceof globalThis.Uint8Array;
71
+ }
72
+ function IsArray(value) {
73
+ return globalThis.Array.isArray(value);
74
+ }
75
+ function IsBoolean(value) {
76
+ return typeof value === 'boolean';
77
+ }
78
+ function IsNull(value) {
79
+ return value === null;
80
+ }
81
+ function IsNumber(value) {
82
+ return typeof value === 'number';
83
+ }
84
+ function IsSymbol(value) {
85
+ return typeof value === 'symbol';
86
+ }
87
+ function IsBigInt(value) {
88
+ return typeof value === 'bigint';
89
+ }
90
+ function IsObject(value) {
91
+ return typeof value === 'object' && value !== null && !IsArray(value) && !IsDate(value) && !IsUint8Array(value);
92
+ }
93
+ function IsString(value) {
94
+ return typeof value === 'string';
95
+ }
96
+ function IsUndefined(value) {
97
+ return value === undefined;
98
+ }
99
+ // ----------------------------------------------------
100
+ // Encoding
101
+ // ----------------------------------------------------
102
+ function Array(value) {
103
+ FNV1A64(ByteMarker.Array);
104
+ for (const item of value) {
105
+ Visit(item);
106
+ }
107
+ }
108
+ function Boolean(value) {
109
+ FNV1A64(ByteMarker.Boolean);
110
+ FNV1A64(value ? 1 : 0);
111
+ }
112
+ function BigInt(value) {
113
+ FNV1A64(ByteMarker.BigInt);
114
+ F64In.setBigInt64(0, value);
115
+ for (const byte of F64Out) {
116
+ FNV1A64(byte);
117
+ }
118
+ }
119
+ function Date(value) {
120
+ FNV1A64(ByteMarker.Date);
121
+ Visit(value.getTime());
122
+ }
123
+ function Null(value) {
124
+ FNV1A64(ByteMarker.Null);
125
+ }
126
+ function Number(value) {
127
+ FNV1A64(ByteMarker.Number);
128
+ F64In.setFloat64(0, value);
129
+ for (const byte of F64Out) {
130
+ FNV1A64(byte);
131
+ }
132
+ }
133
+ function Object(value) {
134
+ FNV1A64(ByteMarker.Object);
135
+ for (const key of globalThis.Object.keys(value).sort()) {
136
+ Visit(key);
137
+ Visit(value[key]);
138
+ }
139
+ }
140
+ function String(value) {
141
+ FNV1A64(ByteMarker.String);
142
+ for (let i = 0; i < value.length; i++) {
143
+ FNV1A64(value.charCodeAt(i));
144
+ }
145
+ }
146
+ function Symbol(value) {
147
+ FNV1A64(ByteMarker.Symbol);
148
+ Visit(value.description);
149
+ }
150
+ function Uint8Array(value) {
151
+ FNV1A64(ByteMarker.Uint8Array);
152
+ for (let i = 0; i < value.length; i++) {
153
+ FNV1A64(value[i]);
154
+ }
155
+ }
156
+ function Undefined(value) {
157
+ return FNV1A64(ByteMarker.Undefined);
158
+ }
159
+ function Visit(value) {
160
+ if (IsArray(value)) {
161
+ Array(value);
162
+ }
163
+ else if (IsBoolean(value)) {
164
+ Boolean(value);
165
+ }
166
+ else if (IsBigInt(value)) {
167
+ BigInt(value);
168
+ }
169
+ else if (IsDate(value)) {
170
+ Date(value);
171
+ }
172
+ else if (IsNull(value)) {
173
+ Null(value);
174
+ }
175
+ else if (IsNumber(value)) {
176
+ Number(value);
177
+ }
178
+ else if (IsObject(value)) {
179
+ Object(value);
180
+ }
181
+ else if (IsString(value)) {
182
+ String(value);
183
+ }
184
+ else if (IsSymbol(value)) {
185
+ Symbol(value);
186
+ }
187
+ else if (IsUint8Array(value)) {
188
+ Uint8Array(value);
189
+ }
190
+ else if (IsUndefined(value)) {
191
+ Undefined(value);
192
+ }
193
+ else {
194
+ throw new ValueHashError(value);
195
+ }
196
+ }
197
+ function FNV1A64(byte) {
198
+ Hash = Hash ^ Bytes[byte];
199
+ Hash = (Hash * Prime) % Size;
200
+ }
201
+ /** Creates a FNV1A-64 non cryptographic hash of the given value */
202
+ function Create(value) {
203
+ Hash = globalThis.BigInt('14695981039346656037');
204
+ Visit(value);
205
+ return Hash;
206
+ }
207
+ ValueHash.Create = Create;
208
+ })(ValueHash = exports.ValueHash || (exports.ValueHash = {}));
package/value/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export { ValueError, ValueErrorIterator, ValueErrorType } from '../errors/index';
2
- export { ValueHash } from './hash';
3
- export { Edit, Insert, Update, Delete } from './delta';
4
- export * from './pointer';
5
- export * from './value';
1
+ export { ValueError, ValueErrorIterator, ValueErrorType } from '../errors/index';
2
+ export { ValueHash } from './hash';
3
+ export { Edit, Insert, Update, Delete } from './delta';
4
+ export * from './pointer';
5
+ export * from './value';