arktype 0.5.1 → 1.0.0-alpha

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 (93) hide show
  1. package/README.md +1 -1
  2. package/dist/api.cjs +4 -2
  3. package/dist/api.d.ts +1 -1
  4. package/dist/api.mjs +1 -1
  5. package/dist/cjs/nodes/branch.js +3 -3
  6. package/dist/cjs/nodes/compose.js +4 -4
  7. package/dist/cjs/nodes/discriminate.js +2 -2
  8. package/dist/cjs/nodes/node.js +33 -30
  9. package/dist/cjs/nodes/predicate.js +1 -7
  10. package/dist/cjs/nodes/rules/props.js +39 -0
  11. package/dist/cjs/nodes/rules/rules.js +5 -2
  12. package/dist/cjs/parse/ast/config.js +13 -0
  13. package/dist/cjs/parse/ast/distributableFunction.js +2 -2
  14. package/dist/cjs/parse/ast/keyof.js +1 -1
  15. package/dist/cjs/parse/ast/morph.js +4 -3
  16. package/dist/cjs/parse/ast/narrow.js +8 -1
  17. package/dist/cjs/{nodes/infer.js → parse/ast/node.js} +0 -0
  18. package/dist/cjs/parse/ast/tuple.js +2 -1
  19. package/dist/cjs/parse/definition.js +2 -2
  20. package/dist/cjs/parse/string/reduce/dynamic.js +2 -2
  21. package/dist/cjs/parse/string/shift/operand/unenclosed.js +1 -1
  22. package/dist/cjs/parse/string/string.js +3 -3
  23. package/dist/cjs/scopes/{standard.js → ark.js} +9 -8
  24. package/dist/cjs/scopes/expressions.js +9 -9
  25. package/dist/cjs/scopes/scope.js +73 -75
  26. package/dist/cjs/scopes/type.js +24 -38
  27. package/dist/cjs/scopes/validation/creditCard.js +47 -0
  28. package/dist/cjs/scopes/validation/date.js +63 -0
  29. package/dist/cjs/scopes/validation/validation.js +95 -0
  30. package/dist/cjs/traverse/problems.js +48 -19
  31. package/dist/cjs/traverse/traverse.js +80 -25
  32. package/dist/cjs/utils/generics.js +16 -0
  33. package/dist/cjs/utils/serialize.js +29 -53
  34. package/dist/mjs/nodes/branch.js +2 -2
  35. package/dist/mjs/nodes/compose.js +5 -5
  36. package/dist/mjs/nodes/discriminate.js +2 -2
  37. package/dist/mjs/nodes/node.js +31 -31
  38. package/dist/mjs/nodes/predicate.js +1 -6
  39. package/dist/mjs/nodes/rules/props.js +39 -0
  40. package/dist/mjs/nodes/rules/rules.js +5 -2
  41. package/dist/mjs/parse/ast/config.js +5 -0
  42. package/dist/mjs/parse/ast/distributableFunction.js +2 -2
  43. package/dist/mjs/parse/ast/keyof.js +1 -1
  44. package/dist/mjs/parse/ast/morph.js +5 -4
  45. package/dist/mjs/parse/ast/narrow.js +9 -2
  46. package/dist/mjs/{nodes/infer.js → parse/ast/node.js} +0 -0
  47. package/dist/mjs/parse/ast/tuple.js +2 -1
  48. package/dist/mjs/parse/definition.js +2 -2
  49. package/dist/mjs/parse/string/reduce/dynamic.js +2 -2
  50. package/dist/mjs/parse/string/shift/operand/unenclosed.js +1 -1
  51. package/dist/mjs/parse/string/string.js +3 -3
  52. package/dist/mjs/scopes/{standard.js → ark.js} +8 -7
  53. package/dist/mjs/scopes/expressions.js +9 -9
  54. package/dist/mjs/scopes/scope.js +70 -76
  55. package/dist/mjs/scopes/type.js +22 -38
  56. package/dist/mjs/scopes/validation/creditCard.js +34 -0
  57. package/dist/mjs/scopes/validation/date.js +49 -0
  58. package/dist/mjs/scopes/validation/validation.js +81 -0
  59. package/dist/mjs/traverse/problems.js +45 -18
  60. package/dist/mjs/traverse/traverse.js +82 -27
  61. package/dist/mjs/utils/generics.js +11 -0
  62. package/dist/mjs/utils/serialize.js +29 -52
  63. package/dist/tsconfig.temp.tsbuildinfo +1 -1
  64. package/dist/types/nodes/branch.d.ts +8 -6
  65. package/dist/types/nodes/node.d.ts +24 -12
  66. package/dist/types/nodes/predicate.d.ts +4 -8
  67. package/dist/types/nodes/rules/props.d.ts +23 -8
  68. package/dist/types/nodes/rules/rules.d.ts +2 -2
  69. package/dist/types/parse/ast/ast.d.ts +1 -1
  70. package/dist/types/parse/ast/config.d.ts +10 -0
  71. package/dist/types/parse/ast/distributableFunction.d.ts +1 -1
  72. package/dist/types/parse/ast/morph.d.ts +2 -2
  73. package/dist/types/parse/ast/narrow.d.ts +1 -1
  74. package/dist/types/{nodes/infer.d.ts → parse/ast/node.d.ts} +14 -14
  75. package/dist/types/parse/ast/tuple.d.ts +8 -7
  76. package/dist/types/parse/definition.d.ts +2 -2
  77. package/dist/types/parse/string/reduce/dynamic.d.ts +5 -5
  78. package/dist/types/parse/string/string.d.ts +3 -3
  79. package/dist/types/scopes/{standard.d.ts → ark.d.ts} +15 -86
  80. package/dist/types/scopes/expressions.d.ts +3 -3
  81. package/dist/types/scopes/scope.d.ts +24 -11
  82. package/dist/types/scopes/type.d.ts +37 -20
  83. package/dist/types/scopes/validation/creditCard.d.ts +2 -0
  84. package/dist/types/scopes/validation/date.d.ts +23 -0
  85. package/dist/types/scopes/validation/validation.d.ts +28 -0
  86. package/dist/types/traverse/problems.d.ts +14 -8
  87. package/dist/types/traverse/traverse.d.ts +18 -3
  88. package/dist/types/utils/generics.d.ts +10 -5
  89. package/dist/types/utils/serialize.d.ts +0 -1
  90. package/package.json +2 -2
  91. package/dist/cjs/scopes/validation.js +0 -79
  92. package/dist/mjs/scopes/validation.js +0 -66
  93. package/dist/types/scopes/validation.d.ts +0 -25
@@ -1,79 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: all[name]
9
- });
10
- }
11
- _export(exports, {
12
- isLuhnValid: ()=>isLuhnValid,
13
- validationScope: ()=>validationScope,
14
- validation: ()=>validation
15
- });
16
- const _numericLiteralsTs = require("../utils/numericLiterals.js");
17
- const _scopeTs = require("./scope.js");
18
- const isLuhnValid = (creditCardInput)=>{
19
- const sanitized = creditCardInput.replace(/[- ]+/g, "");
20
- let sum = 0;
21
- let digit;
22
- let tmpNum;
23
- let shouldDouble;
24
- for(let i = sanitized.length - 1; i >= 0; i--){
25
- digit = sanitized.substring(i, i + 1);
26
- tmpNum = parseInt(digit, 10);
27
- if (shouldDouble) {
28
- tmpNum *= 2;
29
- if (tmpNum >= 10) {
30
- sum += tmpNum % 10 + 1;
31
- } else {
32
- sum += tmpNum;
33
- }
34
- } else {
35
- sum += tmpNum;
36
- }
37
- shouldDouble = !shouldDouble;
38
- }
39
- return !!(sum % 10 === 0 ? sanitized : false);
40
- };
41
- const validationScope = (0, _scopeTs.scope)({
42
- // Character sets
43
- alpha: /^[A-Za-z]*$/,
44
- alphanumeric: /^[A-Za-z\d]*$/,
45
- lowercase: /^[a-z]*$/,
46
- uppercase: /^[A-Z]*$/,
47
- // https://github.com/validatorjs/validator.js
48
- creditCard: [
49
- /^(?:4[0-9]{12}(?:[0-9]{3,6})?|5[1-5][0-9]{14}|(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}|6(?:011|5[0-9][0-9])[0-9]{12,15}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11}|6[27][0-9]{14}|^(81[0-9]{14,17}))$/,
50
- "=>",
51
- (s, problems)=>isLuhnValid(s) || !problems.add("mustBe", "a valid credit card number")
52
- ],
53
- // https://www.regular-expressions.info
54
- email: /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/,
55
- // https://github.com/validatorjs/validator.js
56
- uuid: /^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$/,
57
- parsedNumber: [
58
- _numericLiteralsTs.wellFormedNumberMatcher,
59
- "|>",
60
- (s)=>parseFloat(s)
61
- ],
62
- parsedInteger: [
63
- _numericLiteralsTs.wellFormedIntegerMatcher,
64
- "|>",
65
- (s)=>parseInt(s)
66
- ],
67
- integer: [
68
- "node",
69
- {
70
- number: {
71
- divisor: 1
72
- }
73
- }
74
- ]
75
- }, {
76
- name: "validation",
77
- standard: false
78
- });
79
- const validation = validationScope.compile();
@@ -1,66 +0,0 @@
1
- import { wellFormedIntegerMatcher, wellFormedNumberMatcher } from "../utils/numericLiterals.js";
2
- import { scope } from "./scope.js";
3
- // https://github.com/validatorjs/validator.js
4
- export const isLuhnValid = (creditCardInput)=>{
5
- const sanitized = creditCardInput.replace(/[- ]+/g, "");
6
- let sum = 0;
7
- let digit;
8
- let tmpNum;
9
- let shouldDouble;
10
- for(let i = sanitized.length - 1; i >= 0; i--){
11
- digit = sanitized.substring(i, i + 1);
12
- tmpNum = parseInt(digit, 10);
13
- if (shouldDouble) {
14
- tmpNum *= 2;
15
- if (tmpNum >= 10) {
16
- sum += tmpNum % 10 + 1;
17
- } else {
18
- sum += tmpNum;
19
- }
20
- } else {
21
- sum += tmpNum;
22
- }
23
- shouldDouble = !shouldDouble;
24
- }
25
- return !!(sum % 10 === 0 ? sanitized : false);
26
- };
27
- // Non-trivial expressions should have an explanation or attribution
28
- export const validationScope = scope({
29
- // Character sets
30
- alpha: /^[A-Za-z]*$/,
31
- alphanumeric: /^[A-Za-z\d]*$/,
32
- lowercase: /^[a-z]*$/,
33
- uppercase: /^[A-Z]*$/,
34
- // https://github.com/validatorjs/validator.js
35
- creditCard: [
36
- /^(?:4[0-9]{12}(?:[0-9]{3,6})?|5[1-5][0-9]{14}|(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}|6(?:011|5[0-9][0-9])[0-9]{12,15}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11}|6[27][0-9]{14}|^(81[0-9]{14,17}))$/,
37
- "=>",
38
- (s, problems)=>isLuhnValid(s) || !problems.add("mustBe", "a valid credit card number")
39
- ],
40
- // https://www.regular-expressions.info
41
- email: /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/,
42
- // https://github.com/validatorjs/validator.js
43
- uuid: /^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$/,
44
- parsedNumber: [
45
- wellFormedNumberMatcher,
46
- "|>",
47
- (s)=>parseFloat(s)
48
- ],
49
- parsedInteger: [
50
- wellFormedIntegerMatcher,
51
- "|>",
52
- (s)=>parseInt(s)
53
- ],
54
- integer: [
55
- "node",
56
- {
57
- number: {
58
- divisor: 1
59
- }
60
- }
61
- ]
62
- }, {
63
- name: "validation",
64
- standard: false
65
- });
66
- export const validation = validationScope.compile();
@@ -1,25 +0,0 @@
1
- export declare const isLuhnValid: (creditCardInput: string) => boolean;
2
- export declare const validationScope: import("./scope.js").Scope<[{
3
- alpha: string;
4
- alphanumeric: string;
5
- lowercase: string;
6
- uppercase: string;
7
- creditCard: string;
8
- email: string;
9
- uuid: string;
10
- parsedNumber: (In: string) => import("../parse/ast/morph.js").Out<number>;
11
- parsedInteger: (In: string) => import("../parse/ast/morph.js").Out<number>;
12
- integer: number;
13
- }, {}, false]>;
14
- export declare const validation: import("./scope.js").Space<{
15
- alpha: string;
16
- alphanumeric: string;
17
- lowercase: string;
18
- uppercase: string;
19
- creditCard: string;
20
- email: string;
21
- uuid: string;
22
- parsedNumber: (In: string) => import("../parse/ast/morph.js").Out<number>;
23
- parsedInteger: (In: string) => import("../parse/ast/morph.js").Out<number>;
24
- integer: number;
25
- }>;