@sinclair/typebox 0.31.14 → 0.31.15
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/package.json +1 -1
- package/readme.md +2 -4
- package/value/hash.js +12 -1
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -58,11 +58,9 @@ type T = Static<typeof T> // type T = {
|
|
|
58
58
|
|
|
59
59
|
## Overview
|
|
60
60
|
|
|
61
|
-
TypeBox is a runtime type builder that creates
|
|
61
|
+
TypeBox is a runtime type builder that creates in-memory JSON Schema objects that can be statically inferred as TypeScript types. The schemas produced by this library are designed to match the static type assertion rules of the TypeScript compiler. TypeBox enables one to create a unified type that can be statically checked by TypeScript and runtime asserted using standard JSON Schema validation.
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
TypeBox can be used as a simple tool to build up complex schemas or integrated into applications and frameworks to enable high performance runtime type checking for data received over the wire.
|
|
63
|
+
This library is designed to enable JSON schema to compose with the same flexibility as TypeScript's type system. It can be used as a simple tool to build up complex schemas or integrated into REST or RPC services to help validate data received over the wire.
|
|
66
64
|
|
|
67
65
|
License MIT
|
|
68
66
|
|
package/value/hash.js
CHANGED
|
@@ -66,6 +66,15 @@ const F64 = new Float64Array(1);
|
|
|
66
66
|
const F64In = new DataView(F64.buffer);
|
|
67
67
|
const F64Out = new Uint8Array(F64.buffer);
|
|
68
68
|
// --------------------------------------------------------------------------
|
|
69
|
+
// NumberToBytes
|
|
70
|
+
// --------------------------------------------------------------------------
|
|
71
|
+
function* NumberToBytes(value) {
|
|
72
|
+
const byteCount = value === 0 ? 1 : Math.ceil(Math.floor(Math.log2(value) + 1) / 8);
|
|
73
|
+
for (let i = 0; i < byteCount; i++) {
|
|
74
|
+
yield (value >> (8 * (byteCount - 1 - i))) & 0xff;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// --------------------------------------------------------------------------
|
|
69
78
|
// Hashing Functions
|
|
70
79
|
// --------------------------------------------------------------------------
|
|
71
80
|
function ArrayType(value) {
|
|
@@ -109,7 +118,9 @@ function ObjectType(value) {
|
|
|
109
118
|
function StringType(value) {
|
|
110
119
|
FNV1A64(ByteMarker.String);
|
|
111
120
|
for (let i = 0; i < value.length; i++) {
|
|
112
|
-
|
|
121
|
+
for (const byte of NumberToBytes(value.charCodeAt(i))) {
|
|
122
|
+
FNV1A64(byte);
|
|
123
|
+
}
|
|
113
124
|
}
|
|
114
125
|
}
|
|
115
126
|
function SymbolType(value) {
|