@sinclair/typebox 0.25.24 → 0.26.0-dev

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.
Files changed (46) hide show
  1. package/compiler/compiler.d.ts +9 -4
  2. package/compiler/compiler.js +160 -122
  3. package/errors/errors.d.ts +56 -46
  4. package/errors/errors.js +234 -153
  5. package/package.json +1 -6
  6. package/readme.md +294 -207
  7. package/system/system.d.ts +9 -6
  8. package/system/system.js +17 -17
  9. package/typebox.d.ts +386 -162
  10. package/typebox.js +1710 -229
  11. package/value/cast.d.ts +2 -2
  12. package/value/cast.js +121 -188
  13. package/value/check.d.ts +1 -1
  14. package/value/check.js +156 -111
  15. package/value/convert.d.ts +13 -0
  16. package/value/convert.js +345 -0
  17. package/value/create.d.ts +6 -2
  18. package/value/create.js +149 -97
  19. package/{hash → value}/hash.js +39 -14
  20. package/value/index.d.ts +1 -0
  21. package/value/index.js +3 -1
  22. package/value/value.d.ts +2 -8
  23. package/value/value.js +20 -14
  24. package/conditional/conditional.d.ts +0 -17
  25. package/conditional/conditional.js +0 -91
  26. package/conditional/index.d.ts +0 -2
  27. package/conditional/index.js +0 -45
  28. package/conditional/structural.d.ts +0 -11
  29. package/conditional/structural.js +0 -685
  30. package/custom/custom.d.ts +0 -12
  31. package/custom/custom.js +0 -55
  32. package/custom/index.d.ts +0 -1
  33. package/custom/index.js +0 -44
  34. package/format/format.d.ts +0 -12
  35. package/format/format.js +0 -55
  36. package/format/index.d.ts +0 -1
  37. package/format/index.js +0 -44
  38. package/guard/extends.d.ts +0 -10
  39. package/guard/extends.js +0 -50
  40. package/guard/guard.d.ts +0 -60
  41. package/guard/guard.js +0 -440
  42. package/guard/index.d.ts +0 -2
  43. package/guard/index.js +0 -45
  44. package/hash/index.d.ts +0 -1
  45. package/hash/index.js +0 -44
  46. /package/{hash → value}/hash.d.ts +0 -0
@@ -1,3 +1,4 @@
1
+ import * as Types from '../typebox';
1
2
  export declare class TypeSystemDuplicateTypeKind extends Error {
2
3
  constructor(kind: string);
3
4
  }
@@ -6,12 +7,14 @@ export declare class TypeSystemDuplicateFormat extends Error {
6
7
  }
7
8
  /** Creates user defined types and formats and provides overrides for value checking behaviours */
8
9
  export declare namespace TypeSystem {
9
- /** Sets whether arrays should be treated as kinds of objects. The default is `false` */
10
+ /** Sets whether arrays should be treated as a kind of objects. The default is `false` */
10
11
  let AllowArrayObjects: boolean;
11
- /** Sets whether numeric checks should consider NaN a valid number type. The default is `false` */
12
+ /** Sets whether `NaN` or `Infinity` should be treated as valid numeric values. The default is `false` */
12
13
  let AllowNaN: boolean;
13
- /** Creates a custom type */
14
- function CreateType<Type, Options = object>(kind: string, callback: (options: Options, value: unknown) => boolean): (options?: Partial<Options>) => import("../typebox").TUnsafe<Type>;
15
- /** Creates a custom string format */
16
- function CreateFormat(format: string, callback: (value: string) => boolean): (value: string) => boolean;
14
+ /** Sets whether `null` should validate for void types. The default is `false` */
15
+ let AllowVoidNull: boolean;
16
+ /** Creates a new type */
17
+ function Type<Type, Options = object>(kind: string, check: (options: Options, value: unknown) => boolean): (options?: Partial<Options>) => Types.TUnsafe<Type>;
18
+ /** Creates a new string format */
19
+ function Format<F extends string>(format: F, check: (value: string) => boolean): F;
17
20
  }
package/system/system.js CHANGED
@@ -28,9 +28,7 @@ THE SOFTWARE.
28
28
  ---------------------------------------------------------------------------*/
29
29
  Object.defineProperty(exports, "__esModule", { value: true });
30
30
  exports.TypeSystem = exports.TypeSystemDuplicateFormat = exports.TypeSystemDuplicateTypeKind = void 0;
31
- const typebox_1 = require("../typebox");
32
- const index_1 = require("../custom/index");
33
- const index_2 = require("../format/index");
31
+ const Types = require("../typebox");
34
32
  class TypeSystemDuplicateTypeKind extends Error {
35
33
  constructor(kind) {
36
34
  super(`Duplicate kind '${kind}' detected`);
@@ -46,24 +44,26 @@ exports.TypeSystemDuplicateFormat = TypeSystemDuplicateFormat;
46
44
  /** Creates user defined types and formats and provides overrides for value checking behaviours */
47
45
  var TypeSystem;
48
46
  (function (TypeSystem) {
49
- /** Sets whether arrays should be treated as kinds of objects. The default is `false` */
47
+ /** Sets whether arrays should be treated as a kind of objects. The default is `false` */
50
48
  TypeSystem.AllowArrayObjects = false;
51
- /** Sets whether numeric checks should consider NaN a valid number type. The default is `false` */
49
+ /** Sets whether `NaN` or `Infinity` should be treated as valid numeric values. The default is `false` */
52
50
  TypeSystem.AllowNaN = false;
53
- /** Creates a custom type */
54
- function CreateType(kind, callback) {
55
- if (index_1.Custom.Has(kind))
51
+ /** Sets whether `null` should validate for void types. The default is `false` */
52
+ TypeSystem.AllowVoidNull = false;
53
+ /** Creates a new type */
54
+ function Type(kind, check) {
55
+ if (Types.TypeRegistry.Has(kind))
56
56
  throw new TypeSystemDuplicateTypeKind(kind);
57
- index_1.Custom.Set(kind, callback);
58
- return (options = {}) => typebox_1.Type.Unsafe({ ...options, [typebox_1.Kind]: kind });
57
+ Types.TypeRegistry.Set(kind, check);
58
+ return (options = {}) => Types.Type.Unsafe({ ...options, [Types.Kind]: kind });
59
59
  }
60
- TypeSystem.CreateType = CreateType;
61
- /** Creates a custom string format */
62
- function CreateFormat(format, callback) {
63
- if (index_2.Format.Has(format))
60
+ TypeSystem.Type = Type;
61
+ /** Creates a new string format */
62
+ function Format(format, check) {
63
+ if (Types.FormatRegistry.Has(format))
64
64
  throw new TypeSystemDuplicateFormat(format);
65
- index_2.Format.Set(format, callback);
66
- return callback;
65
+ Types.FormatRegistry.Set(format, check);
66
+ return format;
67
67
  }
68
- TypeSystem.CreateFormat = CreateFormat;
68
+ TypeSystem.Format = Format;
69
69
  })(TypeSystem = exports.TypeSystem || (exports.TypeSystem = {}));