@vtj/utils 0.0.9 → 0.0.11

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/src/util.ts DELETED
@@ -1,77 +0,0 @@
1
- export {
2
- get,
3
- set,
4
- isPlainObject,
5
- cloneDeep,
6
- merge,
7
- debounce,
8
- throttle,
9
- isEqual,
10
- camelCase,
11
- upperFirst,
12
- template
13
- } from 'lodash-es';
14
-
15
- export function uid() {
16
- return Number(Math.random().toString().substring(2, 5) + Date.now()).toString(
17
- 36
18
- );
19
- }
20
-
21
- export function isFunction(val: any): boolean {
22
- return typeof val === 'function';
23
- }
24
-
25
- /**
26
- * 提取对象属性
27
- * @param object
28
- * @param filter
29
- * @returns
30
- */
31
- export function pick(
32
- object: Record<string, any>,
33
- filter?: (v: any) => boolean
34
- ) {
35
- const obj: Record<string, any> = Object.create(null);
36
- const match = filter || ((v) => v !== null && v !== undefined);
37
- Object.entries(object).forEach(([n, v]) => {
38
- if (match(v)) {
39
- obj[n] = v;
40
- }
41
- });
42
- return obj;
43
- }
44
-
45
- /**
46
- * 递归对象或数组清除文本类型值的两边空格
47
- * @param {Object|Array} obj
48
- * @return {Object|Array}
49
- */
50
- export function trim(obj: any): any {
51
- const type = typeof obj;
52
- if (type === 'string') {
53
- return obj.trim();
54
- }
55
- if (Array.isArray(obj)) {
56
- return obj.map((n: any) => trim(n));
57
- }
58
- if (obj && type === 'object') {
59
- Object.entries(obj).forEach(([k, v]) => {
60
- obj[k] = trim(v);
61
- });
62
- return obj;
63
- }
64
- return obj;
65
- }
66
-
67
- /**
68
- * 截取几位小数
69
- * @param {number} value 浮点数
70
- * @param {number} [number=2] 保留几位小数
71
- * @param {boolean} [round] 是否四舍五入
72
- * @returns {number}
73
- */
74
- export function toFixed(value: number, number = 2, round: boolean) {
75
- const method = round ? Math.round : Math.floor;
76
- return method(Math.pow(10, number) * value) / Math.pow(10, number);
77
- }
@@ -1,7 +0,0 @@
1
- /// <reference types="vite/client" />
2
-
3
- declare module '*.vue' {
4
- import type { DefineComponent } from 'vue';
5
- const component: DefineComponent<{}, {}, any>;
6
- export default component;
7
- }
@@ -1,2 +0,0 @@
1
- import axios from 'axios';
2
- export { axios };
@@ -1,10 +0,0 @@
1
- export interface ICookieOptions {
2
- expires?: number;
3
- path?: string;
4
- domain?: string;
5
- secure?: boolean;
6
- sameSite?: string;
7
- }
8
- export declare function set(name: string, value: string, opts?: ICookieOptions): void;
9
- export declare function get(name: string): string | undefined;
10
- export declare function remove(name: string, opts?: ICookieOptions): void;
@@ -1 +0,0 @@
1
- export declare function md5(content: string): string;
@@ -1,2 +0,0 @@
1
- import * as dayjs from 'dayjs';
2
- export { dayjs };
@@ -1,9 +0,0 @@
1
- export * from './util';
2
- export * from './axios';
3
- export * from './request';
4
- export * as cookie from './cookie';
5
- export * as storage from './storage';
6
- export * as crypto from './crypto';
7
- export * as url from './url';
8
- export { dayjs } from './dayjs';
9
- export { jsonp } from './jsonp';
@@ -1,8 +0,0 @@
1
- export interface JSONPOptions {
2
- cache?: boolean;
3
- timeout?: number;
4
- prefix?: string;
5
- param?: string;
6
- name?: string;
7
- }
8
- export declare function jsonp(url: string, params?: Record<string, any>, options?: JSONPOptions): Promise<unknown>;
@@ -1,41 +0,0 @@
1
- declare const instance: import("axios").AxiosInstance;
2
- export interface ISettings {
3
- loading?: boolean;
4
- showLoading?: () => void;
5
- hideLoading?: () => void;
6
- loadingTime?: number;
7
- type?: 'form' | 'json' | 'data';
8
- originResponse?: boolean;
9
- validSuccess?: boolean;
10
- validate?: (res: any) => boolean;
11
- failMessage?: boolean;
12
- showError?: (msg: any) => void;
13
- injectHeaders?: (options: IOptions) => Record<string, string>;
14
- defaults?: Record<string, any>;
15
- trim?: boolean;
16
- picked?: boolean;
17
- pickFilter?: (v: any) => boolean;
18
- skipWarnResponseCode?: number;
19
- skipWarnExecutor?: () => void;
20
- skipWarnCallback?: () => void;
21
- skipWarnFinally?: () => void;
22
- skipWarn?: boolean;
23
- }
24
- declare const __settings__: ISettings;
25
- export declare function setConfig(config: ISettings): void;
26
- export interface IOptions {
27
- url: string;
28
- method?: 'get' | 'GET' | 'delete' | 'DELETE' | 'head' | 'HEAD' | 'options' | 'OPTIONS' | 'post' | 'POST' | 'put' | 'PUT' | 'patch' | 'PATCH';
29
- baseURL?: string;
30
- headers?: Record<string, string>;
31
- params?: any;
32
- data?: any;
33
- timeout?: number;
34
- settings?: ISettings;
35
- }
36
- export declare type IApiOptions = string | IOptions;
37
- declare function request(options: IOptions, currentSettings?: ISettings): Promise<unknown>;
38
- export declare function createApi(options: IApiOptions): (data: any, currentOptions?: {}) => void;
39
- export declare function setRequest(success: any, fail?: any): any;
40
- export declare function setResponse(success: any, fail?: any): any;
41
- export { request, instance as axiosInstance, __settings__ as RequestSettings };
@@ -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;
@@ -1,44 +0,0 @@
1
- export declare const UrlRegex: RegExp;
2
- export declare function isUrl(txt: string): boolean;
3
- /**
4
- * 获取当前页面的 host
5
- * @param {boolean} includePath 带上 pathname
6
- * @return {string}
7
- */
8
- export declare function getCurrentHost(includePath: boolean): string;
9
- /**
10
- * 获取指定url的host
11
- * @param {string} url
12
- * @return {string} host
13
- */
14
- export declare function getHost(url?: string): string;
15
- /**
16
- * 键值对转换成查询字符串
17
- * @param {object} query 键值对,对象
18
- * @returns {string} 查询参数字符串
19
- */
20
- export declare function stringify(query: Record<string, any>): string;
21
- /**
22
- * 参数字符串转换成对象形式,如:a=1&b=2 转换成 {a:1, b:2}
23
- * @param {String} str 需要转换的字符串
24
- * @param {String} [sep=&] 连接符,可选,默认 &
25
- * @param {String} [eq==] 键值间隔符,可选,默认 =
26
- * @returns {Object}
27
- */
28
- export declare function parse(str: string, sep?: string, eq?: string): Record<string, any>;
29
- /**
30
- * 在url追加参数
31
- * @param {string} url 原本的url
32
- * @param {string|object} query 需要追加的参数,Object|String
33
- * @returns {string} 追加参数后的url
34
- */
35
- export declare function append(url: string, query: string | Record<string, any>): string;
36
- declare const _default: {
37
- isUrl: typeof isUrl;
38
- getCurrentHost: typeof getCurrentHost;
39
- getHost: typeof getHost;
40
- stringify: typeof stringify;
41
- parse: typeof parse;
42
- append: typeof append;
43
- };
44
- export default _default;
@@ -1,24 +0,0 @@
1
- export { get, set, isPlainObject, cloneDeep, merge, debounce, throttle, isEqual, camelCase, upperFirst, template } from 'lodash-es';
2
- export declare function uid(): string;
3
- export declare function isFunction(val: any): boolean;
4
- /**
5
- * 提取对象属性
6
- * @param object
7
- * @param filter
8
- * @returns
9
- */
10
- export declare function pick(object: Record<string, any>, filter?: (v: any) => boolean): Record<string, any>;
11
- /**
12
- * 递归对象或数组清除文本类型值的两边空格
13
- * @param {Object|Array} obj
14
- * @return {Object|Array}
15
- */
16
- export declare function trim(obj: any): any;
17
- /**
18
- * 截取几位小数
19
- * @param {number} value 浮点数
20
- * @param {number} [number=2] 保留几位小数
21
- * @param {boolean} [round] 是否四舍五入
22
- * @returns {number}
23
- */
24
- export declare function toFixed(value: number, number: number | undefined, round: boolean): number;
@@ -1,3 +0,0 @@
1
- export { get, set, isPlainObject, cloneDeep, merge, debounce, throttle, isEqual } from 'lodash-es';
2
- export declare function uid(): string;
3
- export declare function isFunction(val: any): boolean;