@litert/typeguard 1.0.0 → 1.2.0

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 (74) hide show
  1. package/CHANGES.md +15 -0
  2. package/lib/BuiltInTypeCompiler.d.ts +4 -4
  3. package/lib/BuiltInTypeCompiler.d.ts.map +1 -1
  4. package/lib/BuiltInTypeCompiler.js +167 -166
  5. package/lib/BuiltInTypeCompiler.js.map +1 -1
  6. package/lib/BuiltInTypes.d.ts +1 -1
  7. package/lib/BuiltInTypes.js +37 -36
  8. package/lib/BuiltInTypes.js.map +1 -1
  9. package/lib/Common.d.ts +13 -9
  10. package/lib/Common.d.ts.map +1 -1
  11. package/lib/Common.js +1 -1
  12. package/lib/Compiler.d.ts +2 -2
  13. package/lib/Compiler.d.ts.map +1 -1
  14. package/lib/Compiler.js +77 -72
  15. package/lib/Compiler.js.map +1 -1
  16. package/lib/Context.d.ts +2 -2
  17. package/lib/Context.js +3 -2
  18. package/lib/Context.js.map +1 -1
  19. package/lib/FilterCompiler.d.ts +5 -5
  20. package/lib/FilterCompiler.d.ts.map +1 -1
  21. package/lib/FilterCompiler.js +25 -24
  22. package/lib/FilterCompiler.js.map +1 -1
  23. package/lib/InlineCompiler.d.ts +12 -5
  24. package/lib/InlineCompiler.d.ts.map +1 -1
  25. package/lib/InlineCompiler.js +14 -5
  26. package/lib/InlineCompiler.js.map +1 -1
  27. package/lib/Internal.d.ts +2 -1
  28. package/lib/Internal.d.ts.map +1 -1
  29. package/lib/Internal.js +12 -10
  30. package/lib/Internal.js.map +1 -1
  31. package/lib/Modifiers.d.ts +1 -1
  32. package/lib/Modifiers.js +2 -1
  33. package/lib/Modifiers.js.map +1 -1
  34. package/lib/index.d.ts +5 -5
  35. package/lib/index.js +19 -7
  36. package/lib/index.js.map +1 -1
  37. package/lib/langs/JavaScript.d.ts +2 -2
  38. package/lib/langs/JavaScript.d.ts.map +1 -1
  39. package/lib/langs/JavaScript.js +30 -23
  40. package/lib/langs/JavaScript.js.map +1 -1
  41. package/package.json +18 -13
  42. package/src/{samples → examples}/quick-start.ts +22 -12
  43. package/src/lib/BuiltInTypeCompiler.ts +171 -171
  44. package/src/lib/BuiltInTypes.ts +36 -36
  45. package/src/lib/Common.ts +15 -10
  46. package/src/lib/Compiler.ts +213 -208
  47. package/src/lib/Context.ts +3 -3
  48. package/src/lib/FilterCompiler.ts +84 -84
  49. package/src/lib/InlineCompiler.ts +35 -14
  50. package/src/lib/Internal.ts +12 -10
  51. package/src/lib/Modifiers.ts +2 -2
  52. package/src/lib/index.ts +5 -5
  53. package/src/lib/langs/JavaScript.ts +34 -24
  54. package/src/test/00-all.ts +11 -9
  55. package/src/test/01-elemental-types.ts +1111 -1110
  56. package/src/test/02-array-and-list.ts +75 -75
  57. package/src/test/03-tuple.ts +87 -87
  58. package/src/test/04-from-string.ts +849 -848
  59. package/src/test/05-string-asserts.ts +422 -422
  60. package/src/test/06-structure.ts +107 -107
  61. package/src/test/07-modifiers.ts +151 -42
  62. package/src/test/08-map-and-dict.ts +46 -46
  63. package/src/test/09-exceptions.ts +67 -0
  64. package/src/test/abstracts.ts +52 -43
  65. package/dist/typeguard.amd.d.ts +0 -588
  66. package/dist/typeguard.amd.d.ts.map +0 -1
  67. package/dist/typeguard.amd.js +0 -2063
  68. package/dist/typeguard.amd.js.map +0 -1
  69. package/dist/typeguard.system.d.ts +0 -588
  70. package/dist/typeguard.system.d.ts.map +0 -1
  71. package/dist/typeguard.system.js +0 -2179
  72. package/dist/typeguard.system.js.map +0 -1
  73. package/tsconfig-amd.json +0 -72
  74. package/tsconfig-systemjs.json +0 -72
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2019 Angus.Fenying <fenying@litert.org>
2
+ * Copyright 2022 Angus Fenying <fenying@litert.org>
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -14,72 +14,72 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- export const STRING = "string";
17
+ export const STRING = 'string';
18
18
 
19
- export const ASCII_STRING = "ascii_string";
19
+ export const ASCII_STRING = 'ascii_string';
20
20
 
21
- export const HEX_STRING = "hex_string";
21
+ export const HEX_STRING = 'hex_string';
22
22
 
23
- export const LATIN_STRING = "latin_string";
23
+ export const LATIN_STRING = 'latin_string';
24
24
 
25
- export const NUMERIC = "numeric";
25
+ export const NUMERIC = 'numeric';
26
26
 
27
- export const SAFE_INT = "safe_int";
27
+ export const SAFE_INT = 'safe_int';
28
28
 
29
- export const INT = "int";
29
+ export const INT = 'int';
30
30
 
31
- export const INT8 = "int8";
31
+ export const INT8 = 'int8';
32
32
 
33
- export const INT16 = "int16";
33
+ export const INT16 = 'int16';
34
34
 
35
- export const INT32 = "int32";
35
+ export const INT32 = 'int32';
36
36
 
37
- export const INT64 = "int64";
37
+ export const INT64 = 'int64';
38
38
 
39
- export const SAFE_UINT = "safe_uint";
39
+ export const SAFE_UINT = 'safe_uint';
40
40
 
41
- export const UINT = "uint";
41
+ export const UINT = 'uint';
42
42
 
43
- export const UINT8 = "uint8";
43
+ export const UINT8 = 'uint8';
44
44
 
45
- export const UINT16 = "uint16";
45
+ export const UINT16 = 'uint16';
46
46
 
47
- export const UINT32 = "uint32";
47
+ export const UINT32 = 'uint32';
48
48
 
49
- export const UINT64 = "uint64";
49
+ export const UINT64 = 'uint64';
50
50
 
51
- export const BOOLEAN = "boolean";
51
+ export const BOOLEAN = 'boolean';
52
52
 
53
- export const ARRAY = "array";
53
+ export const ARRAY = 'array';
54
54
 
55
- export const ANY = "any";
55
+ export const ANY = 'any';
56
56
 
57
- export const STRUCT = "struct";
57
+ export const STRUCT = 'struct';
58
58
 
59
- export const NULL = "null";
59
+ export const NULL = 'null';
60
60
 
61
- export const UNDEFINED = "undefined";
61
+ export const UNDEFINED = 'undefined';
62
62
 
63
- export const VOID = "void";
63
+ export const VOID = 'void';
64
64
 
65
- export const FALSE = "false";
65
+ export const FALSE = 'false';
66
66
 
67
- export const TRUE = "true";
67
+ export const TRUE = 'true';
68
68
 
69
- export const FALSE_VALUE = "false_value";
69
+ export const FALSE_VALUE = 'false_value';
70
70
 
71
- export const TRUE_VALUE = "true_value";
71
+ export const TRUE_VALUE = 'true_value';
72
72
 
73
- export const OPTIONAL = "optional";
73
+ export const OPTIONAL = 'optional';
74
74
 
75
- export const REQUIRED = "required";
75
+ export const REQUIRED = 'required';
76
76
 
77
- export const DECIMAL = "decimal";
77
+ export const DECIMAL = 'decimal';
78
78
 
79
- export const NUMBER = "number";
79
+ export const NUMBER = 'number';
80
80
 
81
- export const FLOAT = "float";
81
+ export const FLOAT = 'float';
82
82
 
83
- export const UDECIMAL = "udecimal";
83
+ export const UDECIMAL = 'udecimal';
84
84
 
85
- export const UFLOAT = "ufloat";
85
+ export const UFLOAT = 'ufloat';
package/src/lib/Common.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright 2019 Angus.Fenying <fenying@litert.org>
2
+ * Copyright 2022 Angus Fenying <fenying@litert.org>
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -14,19 +14,24 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- export type TypeChecker<T> = (v: unknown) => v is T;
17
+ export type ITypeChecker<T> = (v: unknown) => v is T;
18
+
19
+ /**
20
+ * @deprecated Use `ITypeChecker` instead.
21
+ */
22
+ export type TypeChecker<T> = ITypeChecker<T>;
18
23
 
19
24
  export interface ICompileOutputArgument {
20
25
 
21
26
  /**
22
27
  * The name of argument.
23
28
  */
24
- "name": string;
29
+ 'name': string;
25
30
 
26
31
  /**
27
32
  * The type of argument.
28
33
  */
29
- "type": string;
34
+ 'type': string;
30
35
  }
31
36
 
32
37
  export interface ICompileResult {
@@ -34,22 +39,22 @@ export interface ICompileResult {
34
39
  /**
35
40
  * The arguments of checker.
36
41
  */
37
- "arguments": ICompileOutputArgument[];
42
+ 'arguments': ICompileOutputArgument[];
38
43
 
39
44
  /**
40
45
  * The variable name of pre-defined type checkers.
41
46
  */
42
- "typeSlotName": string;
47
+ 'typeSlotName': string;
43
48
 
44
49
  /**
45
50
  * The source code of checker.
46
51
  */
47
- "source": string;
52
+ 'source': string;
48
53
 
49
54
  /**
50
55
  * The predefined types used by this type.
51
56
  */
52
- "referredTypes": string[];
57
+ 'referredTypes': string[];
53
58
  }
54
59
 
55
60
  export interface ICompileOptions {
@@ -57,12 +62,12 @@ export interface ICompileOptions {
57
62
  /**
58
63
  * The rules to be compiled.
59
64
  */
60
- "rule": any;
65
+ 'rule': any;
61
66
 
62
67
  /**
63
68
  * Give this type a name, so it could be used as a pre-defined type.
64
69
  */
65
- "name"?: string;
70
+ 'name'?: string;
66
71
  }
67
72
 
68
73
  export interface ILanguageBuilder {