@modulify/validator 0.2.1 → 0.3.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 (84) hide show
  1. package/CHANGELOG.md +27 -1
  2. package/README.md +12 -2
  3. package/dist/assert-BDOtHdLx.cjs +289 -0
  4. package/dist/assert-CzMg5aO7.mjs +206 -0
  5. package/dist/assert.cjs +7 -65
  6. package/dist/assert.d.cts +37 -0
  7. package/dist/assert.d.mts +37 -0
  8. package/dist/assert.d.ts +24 -3
  9. package/dist/assert.mjs +2 -66
  10. package/dist/assertions-DPYCHREw.mjs +297 -0
  11. package/dist/assertions-nfOKqcjs.cjs +476 -0
  12. package/dist/assertions.cjs +34 -206
  13. package/dist/assertions.d.cts +56 -0
  14. package/dist/assertions.d.mts +56 -0
  15. package/dist/assertions.d.ts +43 -45
  16. package/dist/assertions.mjs +3 -207
  17. package/dist/checkers.d.cts +8 -0
  18. package/dist/checkers.d.mts +8 -0
  19. package/dist/checkers.d.ts +1 -1
  20. package/dist/combinators.cjs +303 -304
  21. package/dist/combinators.d.cts +16 -0
  22. package/dist/combinators.d.mts +16 -0
  23. package/dist/combinators.d.ts +15 -16
  24. package/dist/combinators.mjs +304 -315
  25. package/dist/constraints.d.cts +4 -0
  26. package/dist/constraints.d.mts +4 -0
  27. package/dist/constraints.d.ts +2 -2
  28. package/dist/extractors.d.cts +2 -0
  29. package/dist/extractors.d.mts +2 -0
  30. package/dist/index.cjs +210 -213
  31. package/dist/index.d.cts +12 -0
  32. package/dist/index.d.mts +12 -0
  33. package/dist/index.d.ts +9 -9
  34. package/dist/index.mjs +165 -218
  35. package/dist/json-schema.cjs +364 -489
  36. package/dist/json-schema.d.cts +14 -0
  37. package/dist/json-schema.d.mts +14 -0
  38. package/dist/json-schema.d.ts +3 -3
  39. package/dist/json-schema.mjs +365 -492
  40. package/dist/metadata.cjs +6 -7
  41. package/dist/metadata.d.cts +8 -0
  42. package/dist/metadata.d.mts +8 -0
  43. package/dist/metadata.d.ts +2 -2
  44. package/dist/metadata.mjs +2 -8
  45. package/dist/predicates.cjs +98 -41
  46. package/dist/predicates.d.cts +77 -0
  47. package/dist/predicates.d.mts +77 -0
  48. package/dist/predicates.d.ts +25 -4
  49. package/dist/predicates.mjs +92 -66
  50. package/dist/types/index.d.cts +984 -0
  51. package/dist/types/index.d.mts +984 -0
  52. package/dist/types/index.d.ts +984 -0
  53. package/dist/types/json-schema.d.cts +75 -0
  54. package/dist/types/json-schema.d.mts +75 -0
  55. package/dist/types/json-schema.d.ts +75 -0
  56. package/dist/violations.d.cts +29 -0
  57. package/dist/violations.d.mts +29 -0
  58. package/dist/violations.d.ts +1 -1
  59. package/docs/RELEASING.md +66 -0
  60. package/docs/en/00-index.md +2 -0
  61. package/docs/en/01-shape-api.md +35 -10
  62. package/docs/en/02-metadata-and-introspection.md +2 -1
  63. package/docs/en/03-violations.md +1 -1
  64. package/docs/en/04-json-schema-export.md +5 -0
  65. package/docs/en/05-public-api.md +35 -3
  66. package/docs/en/06-common-recipes.md +2 -1
  67. package/docs/en/07-ai-reference.md +5 -2
  68. package/docs/en/08-violation-code-types.md +28 -2
  69. package/docs/en/09-migration.md +75 -0
  70. package/docs/ru/00-index.md +2 -0
  71. package/docs/ru/01-shape-api.md +35 -10
  72. package/docs/ru/02-metadata-and-introspection.md +2 -1
  73. package/docs/ru/03-violations.md +1 -1
  74. package/docs/ru/04-json-schema-export.md +5 -0
  75. package/docs/ru/05-public-api.md +35 -3
  76. package/docs/ru/06-common-recipes.md +2 -1
  77. package/docs/ru/07-ai-reference.md +5 -2
  78. package/docs/ru/08-violation-code-types.md +28 -2
  79. package/docs/ru/09-migration.md +76 -0
  80. package/docs/ru/README.md +10 -2
  81. package/package.json +63 -37
  82. package/types/index.d.ts +275 -115
  83. package/dist/metadata.cjs.js +0 -130
  84. package/dist/metadata.es.js +0 -131
@@ -1,116 +1,142 @@
1
+ //#region src/predicates.ts
2
+ /** Checks if a value has a property */
1
3
  function hasProperty(key) {
2
- return (value) => {
3
- return isObject(value) && !isNull(value) && Object.prototype.hasOwnProperty.call(value, key);
4
- };
4
+ return (value) => {
5
+ return isObject(value) && !isNull(value) && Object.prototype.hasOwnProperty.call(value, key);
6
+ };
5
7
  }
8
+ /** Checks if a value is an array */
6
9
  function isArray(value) {
7
- return Array.isArray(value);
10
+ return Array.isArray(value);
8
11
  }
12
+ /** Checks if a value is a boolean */
9
13
  function isBoolean(value) {
10
- return typeof value === "boolean";
14
+ return typeof value === "boolean";
11
15
  }
16
+ /** Checks if a value is a bigint */
12
17
  function isBigInt(value) {
13
- return typeof value === "bigint";
18
+ return typeof value === "bigint";
14
19
  }
20
+ /** Checks if a value is a Blob */
15
21
  function isBlob(value) {
16
- return typeof Blob !== "undefined" && value instanceof Blob;
22
+ return typeof Blob !== "undefined" && value instanceof Blob;
17
23
  }
24
+ /** Checks if value is Date */
18
25
  function isDate(value) {
19
- return value instanceof Date;
26
+ return value instanceof Date;
20
27
  }
28
+ /** Checks if value is a valid Date */
29
+ function isValidDate(value) {
30
+ return isDate(value) && !Number.isNaN(value.getTime());
31
+ }
32
+ /** Checks if a value is an email */
21
33
  function isEmail(value) {
22
- const pattern = /^(([^<>()[\].,;:\s@"]+(\.[^<>()[\].,;:\s@"]+)*)|(".+"))@(([^<>()[\].,;:\s@"]+\.)+[^<>()[\].,;:\s@"]{2,})$/i;
23
- return isString(value) && pattern.test(value);
34
+ return isString(value) && /^(([^<>()[\].,;:\s@"]+(\.[^<>()[\].,;:\s@"]+)*)|(".+"))@(([^<>()[\].,;:\s@"]+\.)+[^<>()[\].,;:\s@"]{2,})$/i.test(value);
24
35
  }
36
+ /** Creates a predicate that checks if a value is equal to specified */
25
37
  function isExact(exact) {
26
- return (value) => value === exact;
38
+ return (value) => value === exact;
27
39
  }
40
+ /** Checks if a value is a File */
28
41
  function isFile(value) {
29
- return typeof File !== "undefined" && value instanceof File;
42
+ return typeof File !== "undefined" && value instanceof File;
43
+ }
44
+ /** Checks if a value is an Error */
45
+ function isError(value) {
46
+ return value instanceof Error;
30
47
  }
48
+ /** Checks if a value is a function */
31
49
  function isFunction(value) {
32
- return typeof value === "function";
50
+ return typeof value === "function";
33
51
  }
52
+ /** Checks if a value is a Map */
34
53
  function isMap(value) {
35
- return value instanceof Map;
54
+ return value instanceof Map;
36
55
  }
56
+ /** Checks if a value is NaN */
37
57
  function isNaN(value) {
38
- return typeof value === "number" && Number.isNaN(value);
58
+ return typeof value === "number" && Number.isNaN(value);
39
59
  }
60
+ /** Checks if a value is null */
40
61
  function isNull(value) {
41
- return value === null;
62
+ return value === null;
42
63
  }
64
+ /** Checks if a value is a number */
43
65
  function isNumber(value) {
44
- return typeof value === "number" && !isNaN(value);
66
+ return typeof value === "number" && !isNaN(value);
67
+ }
68
+ /** Checks if a value is a finite number */
69
+ function isFiniteNumber(value) {
70
+ return isNumber(value) && Number.isFinite(value);
71
+ }
72
+ /** Checks if a value is an integer */
73
+ function isInteger(value) {
74
+ return isNumber(value) && Number.isInteger(value);
45
75
  }
76
+ /** Checks if a value is an object, excluding null value */
46
77
  function isObject(value) {
47
- return typeof value === "object" && value !== null;
78
+ return typeof value === "object" && value !== null;
48
79
  }
80
+ /** Checks if a value is promise-like */
81
+ function isPromiseLike(value) {
82
+ return (isObject(value) || isFunction(value)) && "then" in value && isFunction(value.then);
83
+ }
84
+ /** Checks if a value is a regular expression */
85
+ function isRegExp(value) {
86
+ return value instanceof RegExp;
87
+ }
88
+ /** Check if a value is a record like Record<PropertyKey, unknown> */
49
89
  function isRecord(value) {
50
- return isObject(value) && !isNull(value) && constructorOf(value) === Object && Object.keys(prototypeOf(value)).length === 0;
90
+ return isObject(value) && !isNull(value) && constructorOf(value) === Object && Object.keys(prototypeOf(value)).length === 0;
51
91
  }
92
+ /** Checks if a value is a safe integer */
93
+ function isSafeInteger(value) {
94
+ return isNumber(value) && Number.isSafeInteger(value);
95
+ }
96
+ /** Checks if a value is a Set */
52
97
  function isSet(value) {
53
- return value instanceof Set;
98
+ return value instanceof Set;
54
99
  }
100
+ /** Checks if a value is a string */
55
101
  function isString(value) {
56
- return typeof value === "string";
102
+ return typeof value === "string";
57
103
  }
104
+ /** Checks if a value is a symbol */
58
105
  function isSymbol(value) {
59
- return typeof value === "symbol";
106
+ return typeof value === "symbol";
60
107
  }
108
+ /** Checks if a value is undefined */
61
109
  function isUndefined(value) {
62
- return typeof value === "undefined";
110
+ return typeof value === "undefined";
63
111
  }
64
112
  function constructorOf(value) {
65
- return prototypeOf(value).constructor;
113
+ return prototypeOf(value).constructor;
66
114
  }
67
115
  function prototypeOf(value) {
68
- return Object.getPrototypeOf(value);
116
+ return Object.getPrototypeOf(value);
69
117
  }
70
118
  function And(...predicates) {
71
- return (value) => {
72
- return predicates.every((predicate) => predicate(value));
73
- };
119
+ return (value) => {
120
+ return predicates.every((predicate) => predicate(value));
121
+ };
74
122
  }
75
123
  function Or(...predicates) {
76
- return (value) => {
77
- return predicates.some((predicate) => predicate(value));
78
- };
124
+ return (value) => {
125
+ return predicates.some((predicate) => predicate(value));
126
+ };
79
127
  }
80
128
  function Not(predicate) {
81
- return (value) => !predicate(value);
82
- }
83
- const isShape = (shape) => {
84
- const properties = Object.keys(shape);
85
- return (value) => isObject(value) && properties.every((p) => {
86
- const config = shape[p];
87
- const [predicate, required] = isArray(config) ? config : [config, true];
88
- return p in value && value[p] !== void 0 && predicate(value[p]) || !required;
89
- });
90
- };
91
- export {
92
- And,
93
- Not,
94
- Or,
95
- hasProperty,
96
- isArray,
97
- isBigInt,
98
- isBlob,
99
- isBoolean,
100
- isDate,
101
- isEmail,
102
- isExact,
103
- isFile,
104
- isFunction,
105
- isMap,
106
- isNaN,
107
- isNull,
108
- isNumber,
109
- isObject,
110
- isRecord,
111
- isSet,
112
- isShape,
113
- isString,
114
- isSymbol,
115
- isUndefined
129
+ return (value) => !predicate(value);
130
+ }
131
+ /** Checks present fields with their predicates; optional fields may be absent. */
132
+ var isShape = (shape) => {
133
+ const properties = Object.keys(shape);
134
+ return (value) => isObject(value) && properties.every((p) => {
135
+ const config = shape[p];
136
+ const [predicate, required] = isArray(config) ? config : [config, true];
137
+ if (!(p in value)) return !required;
138
+ return predicate(value[p]);
139
+ });
116
140
  };
141
+ //#endregion
142
+ export { And, Not, Or, hasProperty, isArray, isBigInt, isBlob, isBoolean, isDate, isEmail, isError, isExact, isFile, isFiniteNumber, isFunction, isInteger, isMap, isNaN, isNull, isNumber, isObject, isPromiseLike, isRecord, isRegExp, isSafeInteger, isSet, isShape, isString, isSymbol, isUndefined, isValidDate };