@sinclair/typebox 0.31.1 → 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.
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sinclair/typebox",
3
- "version": "0.31.1",
3
+ "version": "0.31.2",
4
4
  "description": "JSONSchema Type Builder with Static Type Resolution for TypeScript",
5
5
  "keywords": [
6
6
  "typescript",
package/readme.md CHANGED
@@ -60,7 +60,9 @@ type T = Static<typeof T> // type T = {
60
60
 
61
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 designed to be a runtime type system based on industry standard specifications. It offers serializable and publishable types as standard, a fully extensible type system capable of supporting multiple schema specifications, a high performance runtime validation compiler, various tools for working with dynamic data and offers detailed structured error reporting. It can either 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.
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
+
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.
64
66
 
65
67
  License MIT
66
68
 
@@ -1167,9 +1169,9 @@ const Z = Value.Cast(T, { x: 1, y: 2, z: 3 }) // const Z = { x: 1, y: 2 }
1167
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.
1168
1170
 
1169
1171
  ```typescript
1170
- const A = Type.Decode(Type.String(), 'hello') // const A = 'hello'
1172
+ const A = Value.Decode(Type.String(), 'hello') // const A = 'hello'
1171
1173
 
1172
- const B = Type.Decode(Type.String(), 42) // throw
1174
+ const B = Value.Decode(Type.String(), 42) // throw
1173
1175
  ```
1174
1176
  <a name='values-decode'></a>
1175
1177
 
@@ -1178,9 +1180,9 @@ const B = Type.Decode(Type.String(), 42) // throw
1178
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.
1179
1181
 
1180
1182
  ```typescript
1181
- const A = Type.Encode(Type.String(), 'hello') // const A = 'hello'
1183
+ const A = Value.Encode(Type.String(), 'hello') // const A = 'hello'
1182
1184
 
1183
- const B = Type.Encode(Type.String(), 42) // throw
1185
+ const B = Value.Encode(Type.String(), 42) // throw
1184
1186
  ```
1185
1187
 
1186
1188
  <a name='values-equal'></a>