@anjianshi/utils 2.4.12 → 2.4.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anjianshi/utils",
3
- "version": "2.4.12",
3
+ "version": "2.4.13",
4
4
  "description": "Common JavaScript Utils",
5
5
  "homepage": "https://github.com/anjianshi/js-packages/utils",
6
6
  "bugs": {
@@ -27,9 +27,9 @@
27
27
  "redis": "^4.7.0",
28
28
  "typescript": "^5.6.3",
29
29
  "vconsole": "^3.15.1",
30
- "@anjianshi/presets-eslint-node": "4.0.14",
31
30
  "@anjianshi/presets-eslint-typescript": "5.0.11",
32
31
  "@anjianshi/presets-prettier": "3.0.1",
32
+ "@anjianshi/presets-eslint-node": "4.0.14",
33
33
  "@anjianshi/presets-typescript": "3.2.3",
34
34
  "@anjianshi/presets-eslint-react": "4.0.13"
35
35
  },
@@ -12,7 +12,7 @@ export type PrimitiveType = string | boolean | number | PrimitiveType[] | [...Pr
12
12
  /**
13
13
  * validator 通用参数
14
14
  */
15
- export interface CommonOptions<Value = unknown> {
15
+ export interface CommonOptions<Value = any> {
16
16
  /** 是否允许 null 值 @default false */
17
17
  null?: boolean;
18
18
  /** 字段是否必须有值(不能是 undefined) @default true */
@@ -22,7 +22,7 @@ export interface CommonOptions<Value = unknown> {
22
22
  * 指定后 required 选项将失去作用。
23
23
  */
24
24
  defaults?: Value;
25
- custom?: <T extends Value>(input: T) => MaySuccess<T>;
25
+ custom?: (input: Value) => MaySuccess<Value>;
26
26
  [key: string]: unknown;
27
27
  }
28
28
  /**
@@ -78,5 +78,5 @@ export declare function getValidatorGenerator<Value, Options extends CommonOptio
78
78
  * 返回只进行基本检查,不带定制的验证逻辑的 validator。
79
79
  * 同时也是定制 validator 最小化实现的例子。
80
80
  */
81
- export declare const getAnyValidator: <const InputOptions extends CommonOptions<unknown>>(inputOptions: InputOptions) => Validator<unknown, InputOptions>;
81
+ export declare const getAnyValidator: <const InputOptions extends CommonOptions<any>>(inputOptions: InputOptions) => Validator<unknown, InputOptions>;
82
82
  export {};
@@ -7,6 +7,7 @@ import { success, failed } from '../lang/index.js';
7
7
  export function getValidatorGenerator(validate) {
8
8
  return function validatorGenerator(inputOptions) {
9
9
  function validator(field, input) {
10
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
10
11
  const { null: allowNull = false, required = true, defaults, custom } = inputOptions;
11
12
  if (typeof field !== 'string') {
12
13
  input = field;
@@ -99,3 +99,10 @@ export function getValidator(definition) {
99
99
  // ],
100
100
  // defaults: true,
101
101
  // })(1)
102
+ // const v11 = getValidator({
103
+ // type: 'string',
104
+ // custom(value) {
105
+ // return { success: true, data: value }
106
+ // },
107
+ // defaults: 'some text',
108
+ // })(1)