@vtj/utils 0.5.2 → 0.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/types/axios.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import { AxiosInstance } from 'axios';
2
- export * from 'axios';
3
- declare const instance: AxiosInstance;
4
- export default instance;
@@ -1,47 +0,0 @@
1
- import type { AxiosRequestConfig, AxiosResponse } from './axios';
2
- import { AxiosError } from './axios';
3
- import instance from './axios';
4
- declare const LOCAL_REQUEST_ID = "Local-Request-Id";
5
- export interface ApiResponse<T = any> {
6
- code: number;
7
- data: T | null;
8
- msg: string;
9
- success: boolean;
10
- promise?: Promise<any>;
11
- }
12
- export interface ApiSettings<OriginResponse, ValidSuccess> {
13
- loading?: boolean;
14
- showLoading?: () => void;
15
- hideLoading?: () => void;
16
- loadingTime?: number;
17
- type?: 'form' | 'json' | 'data';
18
- originResponse?: OriginResponse;
19
- validSuccess?: ValidSuccess;
20
- validate?: (res: AxiosResponse) => boolean;
21
- failMessage?: boolean;
22
- showError?: (msg: string, e: AxiosError | AxiosResponse<ApiResponse>) => void;
23
- headers?: Record<string, string> | ((config: ApiRequestConfig) => Record<string, string>);
24
- defaults?: Record<string, any>;
25
- trim?: boolean;
26
- picked?: boolean;
27
- pickFilter?: (v: any) => boolean;
28
- skipWarnResponseCode?: number;
29
- skipWarnExecutor?: () => void;
30
- skipWarnCallback?: () => void;
31
- skipWarnFinally?: () => void;
32
- skipWarn?: boolean;
33
- }
34
- export type ApiRequestConfig<RequestData = any, OriginResponse = boolean, ValidSuccess = boolean> = AxiosRequestConfig<RequestData> & {
35
- settings?: ApiSettings<OriginResponse, ValidSuccess>;
36
- };
37
- declare const __settings__: ApiSettings<boolean, boolean>;
38
- export declare function setRequestSettings(settings: ApiSettings<boolean, boolean>): void;
39
- declare function request<Req = any, Res = any>(options: ApiRequestConfig<Req, false, true>, currentSettings?: ApiSettings<boolean, boolean>): Promise<Res>;
40
- declare function request<Req = any, Res = any>(options: ApiRequestConfig<Req, false, false>, currentSettings?: ApiSettings<boolean, boolean>): Promise<ApiResponse<Res>>;
41
- declare function request<Req = any, Res = any>(options: ApiRequestConfig<Req, true, boolean>, currentSettings?: ApiSettings<boolean, boolean>): Promise<AxiosResponse<ApiResponse<Res>>>;
42
- export declare function setRequest(success: any, fail?: any): any;
43
- export declare function setResponse(success: any, fail?: any): any;
44
- declare function createApi<Req = any, Res = any>(options: string | ApiRequestConfig<Req, false, true>): (data?: Req, currentSettings?: ApiSettings<boolean, boolean>) => Promise<Res>;
45
- declare function createApi<Req = any, Res = any>(options: string | ApiRequestConfig<Req, false, false>): (data?: Req, currentSettings?: ApiSettings<boolean, boolean>) => Promise<ApiResponse<Res>>;
46
- declare function createApi<Req = any, Res = any>(options: string | ApiRequestConfig<Req, true, boolean>): (data?: Req, currentSettings?: ApiSettings<boolean, boolean>) => Promise<AxiosResponse<ApiResponse<Res>>>;
47
- export { request, createApi, instance as axiosInstance, __settings__ as requestSettings, LOCAL_REQUEST_ID };
@@ -1,46 +0,0 @@
1
- /**
2
- * 缓存操作模块,提供sessionStorage和localStorage操作
3
- * @module storage
4
- * @author 陈华春
5
- */
6
- /**
7
- * 保存缓存
8
- * @param {string} key 缓存key
9
- * @param {String|Object|Array} value 缓存值,对象、数组类型自动JSON.stringify成字符串
10
- * @param {object} [opts] 选项
11
- * @param {Object} [opts.type=cache] 存储方式 local、 session、cache
12
- * @param {number} [opts.expired=0] 过期时间,单位毫秒
13
- * @param {string} [opts.prefix=__NewPearl__] key 前缀
14
- */
15
- export declare function save(key: string, value?: any, opts?: {}): void;
16
- /**
17
- * 获取缓存
18
- * @param {string} key 缓存key
19
- * @param {object} [opts] 选项
20
- * @param {Object} [opts.type=cache] 存储方式 local、 session、cache
21
- * @param {number} [opts.expired=0] 过期时间,单位毫秒
22
- * @param {string} [opts.prefix=__NewPearl__] key 前缀
23
- * @returns {String|Object|Array}
24
- */
25
- export declare function get(key: string, opts?: {}): any;
26
- /**
27
- * 删除缓存
28
- * @param {string} key 缓存key
29
- * @param {object} [opts] 选项
30
- * @param {Object} [opts.type=cache] 存储方式 local、 session、cache
31
- * @param {string} [opts.prefix=__NewPearl__] key 前缀
32
- */
33
- export declare function remove(key: string, opts?: {}): void;
34
- /**
35
- * 删除全部缓存
36
- * @param {object} [opts] 选项
37
- * @param {Object} [opts.type=cache] 存储方式 local、 session、cache
38
- */
39
- export declare function clear(opts?: {}): void;
40
- declare const _default: {
41
- save: typeof save;
42
- get: typeof get;
43
- remove: typeof remove;
44
- clear: typeof clear;
45
- };
46
- export default _default;