@sinclair/typebox 0.31.0 → 0.31.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.js +11 -1
- package/package.json +1 -1
- package/readme.md +6 -6
- package/value/transform.js +2 -2
package/compiler/compiler.js
CHANGED
|
@@ -145,6 +145,16 @@ var Identifier;
|
|
|
145
145
|
Identifier.Encode = Encode;
|
|
146
146
|
})(Identifier || (Identifier = {}));
|
|
147
147
|
// -------------------------------------------------------------------
|
|
148
|
+
// LiteralString
|
|
149
|
+
// -------------------------------------------------------------------
|
|
150
|
+
var LiteralString;
|
|
151
|
+
(function (LiteralString) {
|
|
152
|
+
function Escape(content) {
|
|
153
|
+
return content.replace(/'/g, "\\'");
|
|
154
|
+
}
|
|
155
|
+
LiteralString.Escape = Escape;
|
|
156
|
+
})(LiteralString || (LiteralString = {}));
|
|
157
|
+
// -------------------------------------------------------------------
|
|
148
158
|
// Errors
|
|
149
159
|
// -------------------------------------------------------------------
|
|
150
160
|
class TypeCompilerUnknownTypeError extends Types.TypeBoxError {
|
|
@@ -303,7 +313,7 @@ var TypeCompiler;
|
|
|
303
313
|
yield `(${value} === ${schema.const})`;
|
|
304
314
|
}
|
|
305
315
|
else {
|
|
306
|
-
yield `(${value} === '${schema.const}')`;
|
|
316
|
+
yield `(${value} === '${LiteralString.Escape(schema.const)}')`;
|
|
307
317
|
}
|
|
308
318
|
}
|
|
309
319
|
function* TNever(schema, references, value) {
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -58,9 +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 Json Schema objects that infer as TypeScript types. The schemas produced by this library are designed to match the static type checking rules of the TypeScript compiler. TypeBox offers a unified type that can be statically checked by TypeScript
|
|
61
|
+
TypeBox is a runtime type builder that creates Json Schema objects that infer as TypeScript types. The schemas produced by this library are designed to match the static type checking rules of the TypeScript compiler. TypeBox offers a unified type that can be statically checked by TypeScript or runtime checked using standard Json Schema validation.
|
|
62
62
|
|
|
63
|
-
TypeBox is
|
|
63
|
+
TypeBox is built upon industry standard specifications. It offers reflectable, serializable and publishable types as standard, a fully extensible type system capable of supporting multiple schema specifications, includes a high performance validation compiler, offers various tools for working with dynamic data and provides detailed structured error reporting.
|
|
64
64
|
|
|
65
65
|
TypeBox can be used as a simple tool to build up complex schemas or integrated into applications to enable high performance runtime validation for data received over the wire.
|
|
66
66
|
|
|
@@ -1169,9 +1169,9 @@ const Z = Value.Cast(T, { x: 1, y: 2, z: 3 }) // const Z = { x: 1, y: 2 }
|
|
|
1169
1169
|
Use the Decode function to decode a value from a type, or throw if the value is invalid. The return value will infer as the decoded type. This function will run Transform codecs if available.
|
|
1170
1170
|
|
|
1171
1171
|
```typescript
|
|
1172
|
-
const A =
|
|
1172
|
+
const A = Value.Decode(Type.String(), 'hello') // const A = 'hello'
|
|
1173
1173
|
|
|
1174
|
-
const B =
|
|
1174
|
+
const B = Value.Decode(Type.String(), 42) // throw
|
|
1175
1175
|
```
|
|
1176
1176
|
<a name='values-decode'></a>
|
|
1177
1177
|
|
|
@@ -1180,9 +1180,9 @@ const B = Type.Decode(Type.String(), 42) // throw
|
|
|
1180
1180
|
Use the Encode function to encode a value to a type, or throw if the value is invalid. The return value will infer as the encoded type. This function will run Transform codecs if available.
|
|
1181
1181
|
|
|
1182
1182
|
```typescript
|
|
1183
|
-
const A =
|
|
1183
|
+
const A = Value.Encode(Type.String(), 'hello') // const A = 'hello'
|
|
1184
1184
|
|
|
1185
|
-
const B =
|
|
1185
|
+
const B = Value.Encode(Type.String(), 42) // throw
|
|
1186
1186
|
```
|
|
1187
1187
|
|
|
1188
1188
|
<a name='values-equal'></a>
|
package/value/transform.js
CHANGED
|
@@ -88,10 +88,10 @@ var HasTransform;
|
|
|
88
88
|
return Types.TypeGuard.TTransform(schema) || Visit(schema.items, references);
|
|
89
89
|
}
|
|
90
90
|
function TConstructor(schema, references) {
|
|
91
|
-
return Types.TypeGuard.TTransform(schema) || Visit(schema.returns, references) || schema.parameters.some((schema) => Visit(schema
|
|
91
|
+
return Types.TypeGuard.TTransform(schema) || Visit(schema.returns, references) || schema.parameters.some((schema) => Visit(schema, references));
|
|
92
92
|
}
|
|
93
93
|
function TFunction(schema, references) {
|
|
94
|
-
return Types.TypeGuard.TTransform(schema) || Visit(schema.returns, references) || schema.parameters.some((schema) => Visit(schema
|
|
94
|
+
return Types.TypeGuard.TTransform(schema) || Visit(schema.returns, references) || schema.parameters.some((schema) => Visit(schema, references));
|
|
95
95
|
}
|
|
96
96
|
function TIntersect(schema, references) {
|
|
97
97
|
return Types.TypeGuard.TTransform(schema) || Types.TypeGuard.TTransform(schema.unevaluatedProperties) || schema.allOf.some((schema) => Visit(schema, references));
|