@astral/validations 4.5.0 → 4.6.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.
package/README.md CHANGED
@@ -1120,7 +1120,7 @@ validate([1, 2]);
1120
1120
 
1121
1121
  ## any
1122
1122
 
1123
- Позволяет выключить любые проверки.
1123
+ Позволяет выключить любые проверки и делать композицию для правил, валидирующих любые значения.
1124
1124
 
1125
1125
  ```ts
1126
1126
  type Values = { name: string; isAgree: boolean };
@@ -1142,8 +1142,15 @@ toPrettyError(
1142
1142
  validate({ isAgree: true, name: '' })
1143
1143
  );
1144
1144
  ```
1145
+ ```ts
1146
+ const validate = any(transform((value) => new Date(value), date()));
1145
1147
 
1146
- ---
1148
+ // undefined
1149
+ validate('12.22.2022');
1150
+
1151
+ // invalid date error
1152
+ validate('13.22.2022');
1153
+ ```
1147
1154
 
1148
1155
  ## Define. Переопределение дефолтных параметров guard
1149
1156
 
package/any/any.d.ts CHANGED
@@ -1,5 +1,7 @@
1
+ import { ValidationRule } from '../core';
1
2
  /**
2
- * @description Выключает любые проверки
3
+ * @description Выключает любые проверки и валидирует value
4
+ * @param rules - правила, валидирующие любые значения
3
5
  * @example
4
6
  * ```ts
5
7
  * type Values = { name: string; surname?: string };
@@ -9,5 +11,13 @@
9
11
  * // undefined
10
12
  * validate({});
11
13
  * ```
14
+ * const validate = any(transform((value) => new Date(value), date()));
15
+ *
16
+ * // undefined
17
+ * validate('12.22.2022');
18
+ *
19
+ * // invalid date error
20
+ * validate('13.22.2022');
21
+ * ```
12
22
  */
13
- export declare const any: <TLastSchemaValues extends Record<string, unknown>>() => (value: unknown, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => import("../core").ValidationResult;
23
+ export declare const any: <TLastSchemaValues extends Record<string, unknown>>(...rules: ValidationRule<unknown, TLastSchemaValues>[]) => (value: unknown, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => import("../core").ValidationResult;
package/any/any.js CHANGED
@@ -1,6 +1,7 @@
1
- import { createRule } from '../core';
1
+ import { compose, createRule } from '../core';
2
2
  /**
3
- * @description Выключает любые проверки
3
+ * @description Выключает любые проверки и валидирует value
4
+ * @param rules - правила, валидирующие любые значения
4
5
  * @example
5
6
  * ```ts
6
7
  * type Values = { name: string; surname?: string };
@@ -10,5 +11,15 @@ import { createRule } from '../core';
10
11
  * // undefined
11
12
  * validate({});
12
13
  * ```
14
+ * const validate = any(transform((value) => new Date(value), date()));
15
+ *
16
+ * // undefined
17
+ * validate('12.22.2022');
18
+ *
19
+ * // invalid date error
20
+ * validate('13.22.2022');
21
+ * ```
13
22
  */
14
- export const any = () => createRule(() => undefined);
23
+ export const any = (...rules) => createRule((value, ctx) => {
24
+ return compose(...rules)(value, ctx);
25
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astral/validations",
3
- "version": "4.5.0",
3
+ "version": "4.6.0",
4
4
  "browser": "./index.js",
5
5
  "main": "./index.js",
6
6
  "dependencies": {