ddan-js 2.1.8 → 2.1.9

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.
@@ -84,6 +84,7 @@ const _merge = (target, source, options = {}) => {
84
84
  }
85
85
  return result;
86
86
  };
87
+ // <T extends object>
87
88
  const merge = (target, source, options = {}) => {
88
89
  let result = {};
89
90
  if (target && typeof target === 'object' && !Array.isArray(target)) {
@@ -57,7 +57,6 @@ function now() {
57
57
  * 倒计时格式
58
58
  * @param endTime 结束时间
59
59
  * @param reg 格式
60
- * @param def
61
60
  * @returns
62
61
  */
63
62
  const countdown = (endTime, reg = "") => {
@@ -1,4 +1,4 @@
1
- import { dd } from "../typings";
1
+ import { xh } from "../typings";
2
2
  export declare class DTrack {
3
3
  id: string;
4
4
  /** 开始时间戳 */
@@ -41,7 +41,7 @@ export declare class DTracker {
41
41
  get list(): DTrack[];
42
42
  get size(): number;
43
43
  _endId: (id: string) => string;
44
- report(cb?: dd.TAction<DTrack, number>): void;
44
+ report(cb?: xh.Func2<DTrack, number>): void;
45
45
  }
46
46
  declare const tracker: DTracker;
47
47
  export default tracker;
@@ -34,7 +34,7 @@ declare const _default: {
34
34
  exec: (func: Function, taskId?: string) => Promise<any[]>;
35
35
  debounce: typeof import("./modules/hook/debounce").default;
36
36
  throttle: typeof import("./modules/hook/throttle").default;
37
- task: (param?: import("./typings").dd.TTask | undefined) => import("./class/pipeTask").default;
37
+ task: (param?: import("./typings").xh.Func1<any, any> | undefined) => import("./class/pipeTask").default;
38
38
  delay: (time?: number) => Promise<unknown>;
39
39
  mutex: typeof import("./modules/hook/mutex").default;
40
40
  };
@@ -90,12 +90,12 @@ declare const _default: {
90
90
  isPromise: (value: any) => boolean;
91
91
  };
92
92
  list: {
93
- stepAction: <T_1>(list: T_1[], func: import("./typings").dd.TArrayFunction<T_1>, stepCount?: number) => void;
93
+ stepAction: <T_1>(list: T_1[], func: import("./typings").xh.Task<T_1, void>, stepCount?: number) => void;
94
94
  skip: <T_2>(list: T_2[], count: number) => T_2[];
95
95
  take: <T_3>(list: T_3[], count: number, skip?: number) => T_3[];
96
96
  distinct: <T_4>(list: T_4[]) => T_4[];
97
97
  randoms: <T_5>(list: T_5[], count?: number, repeat?: boolean) => T_5[];
98
- toKV: (list: import("./typings").dd.KV<any>[], key: string, value: string) => import("./typings").dd.KV<any>;
98
+ toKV: (list: import("./typings").xh.KV<any>[], key: string, value: string) => import("./typings").xh.KV<any>;
99
99
  groupBy: <T_6>(list: T_6[], key: string) => Record<string, T_6[]>;
100
100
  first: <T_7>(list: T_7[]) => T_7 | undefined;
101
101
  last: <T_8>(list: T_8[]) => T_8 | undefined;
@@ -1,4 +1,4 @@
1
- import { dd } from '../../typings';
1
+ import { dd, xh } from '../../typings';
2
2
  /**
3
3
  * 防抖 一段时间内,规定时间间隔多次执行,回调触发一次
4
4
  * @param func
@@ -6,7 +6,7 @@ import { dd } from '../../typings';
6
6
  * @param options 参数:leading 开始执行, trailing结束执行
7
7
  * @returns
8
8
  */
9
- declare function debounce(func: dd.TAnyFunction, wait?: number, options?: dd.IDebounceOption): {
9
+ declare function debounce(func: xh.Callback, wait?: number, options?: dd.IDebounceOption): {
10
10
  (...debouncedArgs: any[]): any;
11
11
  cancel: () => void;
12
12
  flush: () => any;
@@ -2,14 +2,14 @@ import debounce from "./debounce";
2
2
  import throttle from "./throttle";
3
3
  import mutex from "./mutex";
4
4
  import DPipeTask from "../../class/pipeTask";
5
- import { dd } from "../../typings";
5
+ import { xh } from "../../typings";
6
6
  declare const _default: {
7
7
  sleep: (time?: number) => Promise<unknown>;
8
8
  run: (task?: Function | Promise<any> | undefined, wait?: number) => Promise<any[]>;
9
9
  exec: (func: Function, taskId?: string) => Promise<any[]>;
10
10
  debounce: typeof debounce;
11
11
  throttle: typeof throttle;
12
- task: (param?: dd.TTask | undefined) => DPipeTask;
12
+ task: (param?: xh.Func1<any, any> | undefined) => DPipeTask;
13
13
  delay: (time?: number) => Promise<unknown>;
14
14
  mutex: typeof mutex;
15
15
  };
@@ -1,3 +1,3 @@
1
- import { dd } from '../../typings';
2
- declare function mutex(func: dd.TAnyFunction): (...args: any[]) => Promise<false | undefined>;
1
+ import { xh } from '../../typings';
2
+ declare function mutex(func: xh.Callback): (...args: any[]) => Promise<false | undefined>;
3
3
  export default mutex;
@@ -1,4 +1,4 @@
1
- import { dd } from "../../typings";
1
+ import { dd, xh } from "../../typings";
2
2
  /**
3
3
  * 节流 每个间隔内,触发一次
4
4
  * @param func
@@ -6,7 +6,7 @@ import { dd } from "../../typings";
6
6
  * @param options 参数:leading 开始执行, trailing结束执行
7
7
  * @returns
8
8
  */
9
- declare function throttle(func: dd.TAnyFunction, wait?: number, options?: Omit<dd.IDebounceOption, 'maxWait'>): {
9
+ declare function throttle(func: xh.Callback, wait?: number, options?: Omit<dd.IDebounceOption, 'maxWait'>): {
10
10
  (...debouncedArgs: any[]): any;
11
11
  cancel: () => void;
12
12
  flush: () => any;
@@ -1,5 +1,5 @@
1
1
  import Interceptor from "./interceptor";
2
- import { dd } from "../../typings";
2
+ import { dd, xh } from "../../typings";
3
3
  export default class Http implements dd.IHttp {
4
4
  host: string;
5
5
  reqConfig: {};
@@ -32,5 +32,5 @@ export default class Http implements dd.IHttp {
32
32
  * @param {object} req
33
33
  */
34
34
  getIdFromReqUrl(req: any): any;
35
- fetch(name: string, payload?: dd.KV): Promise<any>;
35
+ fetch(name: string, payload?: xh.KV): Promise<any>;
36
36
  }
@@ -1,4 +1,4 @@
1
- import { dd } from "../../typings";
1
+ import { xh } from "../../typings";
2
2
  /**
3
3
  * 分步动作
4
4
  * @param list 列表
@@ -6,7 +6,7 @@ import { dd } from "../../typings";
6
6
  * @param stepCount 每步数量
7
7
  * @returns
8
8
  */
9
- declare function stepAction<T>(list: T[], func: dd.TArrayFunction<T>, stepCount?: number): void;
9
+ declare function stepAction<T>(list: T[], func: xh.Task<T>, stepCount?: number): void;
10
10
  /**
11
11
  * 跳过数据
12
12
  * @param list 列表
@@ -35,7 +35,7 @@ declare const _default: {
35
35
  take: typeof take;
36
36
  distinct: typeof distinct;
37
37
  randoms: typeof randoms;
38
- toKV: (list: dd.KV<any>[], key: string, value: string) => dd.KV<any>;
38
+ toKV: (list: xh.KV<any>[], key: string, value: string) => xh.KV<any>;
39
39
  groupBy: <T>(list: T[], key: string) => Record<string, T[]>;
40
40
  first: <T_1>(list: T_1[]) => T_1 | undefined;
41
41
  last: <T_2>(list: T_2[]) => T_2 | undefined;
@@ -1,9 +1,16 @@
1
1
  import DPersist from "../class/persist";
2
+ export declare namespace xh {
3
+ type KV<T = any> = Record<string, T>;
4
+ type Callback<T extends any[] = unknown[], R = void> = (...args: T) => R;
5
+ type Action<T extends any[] = unknown[], R = any> = Callback<T, R>;
6
+ type Task<T = any, R = void> = Callback<[T[]], R>;
7
+ type Func<R = any> = Callback<[], R>;
8
+ type Func1<T = any, R = any> = Callback<[T], R>;
9
+ type Func2<T0 = any, T1 = any, R = any> = Callback<[T0, T1], R>;
10
+ type Func3<T0 = any, T1 = any, T2 = any, R = any> = Callback<[T0, T1, T2], R>;
11
+ type Func4<T0 = any, T1 = any, T2 = any, T3 = any, R = any> = Callback<[T0, T1, T2, T3], R>;
12
+ }
2
13
  export declare namespace dd {
3
- type TAction<T = any, T1 = any, T2 = any, T3 = any> = (...args: unknown extends T3 ? (unknown extends T2 ? (unknown extends T1 ? [T] : [T, T1]) : [T, T1, T2]) : [T, T1, T2, T3]) => void;
4
- type TFunc<R = any, T = any, T1 = any, T2 = any, T3 = any> = (...args: unknown extends T3 ? (unknown extends T2 ? (unknown extends T1 ? [T] : [T, T1]) : [T, T1, T2]) : [T, T1, T2, T3]) => R;
5
- type TAnyFunction<T = void> = (...args: any[]) => T;
6
- type TArrayFunction<T> = (args: T[]) => void;
7
14
  type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;
8
15
  /**
9
16
  * leading 开始执行
@@ -41,9 +48,6 @@ export declare namespace dd {
41
48
  fields: string[];
42
49
  storage: DStorage;
43
50
  }
44
- type TTask = (arg: any) => any;
45
- type KV<T = any> = Record<string, T>;
46
- type Callback<T extends any[] = unknown[], R = void> = (...args: T) => R;
47
51
  interface IHttpRequest {
48
52
  url: string;
49
53
  host: string;
@@ -52,14 +56,14 @@ export declare namespace dd {
52
56
  interface IHttpApiConfig {
53
57
  [key: string]: IHttpRequestInit;
54
58
  }
55
- type ResponseInterceptFunc = (arg: IHttpResponse) => any;
56
- type RequestInterceptFunc = (arg: IHttpRequest) => IHttpRequest;
59
+ type ResponseInterceptFunc = xh.Func1<IHttpResponse>;
60
+ type RequestInterceptFunc = xh.Func1<IHttpRequest, IHttpRequest>;
57
61
  interface IHttpConfig {
58
62
  host?: string;
59
63
  config: IHttpApiConfig;
60
64
  handleRequest?: RequestInterceptFunc | RequestInterceptFunc[];
61
65
  handleResponse?: ResponseInterceptFunc | ResponseInterceptFunc[];
62
- handleError?: (error: any) => void;
66
+ handleError?: xh.Func1;
63
67
  }
64
68
  interface IHttpRequestInit extends RequestInit {
65
69
  [key: string]: any;
@@ -80,7 +84,7 @@ export declare namespace dd {
80
84
  }
81
85
  interface IHttpResponse {
82
86
  response: Response & Record<string, any>;
83
- config?: KV;
87
+ config?: xh.KV;
84
88
  refetch: () => Promise<any>;
85
89
  }
86
90
  interface IMiniHttpOptions {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ddan-js",
3
- "version": "2.1.8",
3
+ "version": "2.1.9",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "main": "bin/ddan-js.js",