@allkit/shared 0.0.1
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 +1 -0
- package/dist/README.md +1 -0
- package/dist/clipboard/index.d.ts +9 -0
- package/dist/cloneDeep/index.d.ts +47 -0
- package/dist/constants.d.ts +26 -0
- package/dist/cookie/index.d.ts +31 -0
- package/dist/date/index.d.ts +133 -0
- package/dist/device/index.d.ts +70 -0
- package/dist/element/index.d.ts +12 -0
- package/dist/index.d.ts +13 -0
- package/dist/is/index.d.ts +181 -0
- package/dist/lodash/index.d.ts +184 -0
- package/dist/number/index.d.ts +84 -0
- package/dist/package.json +21 -0
- package/dist/shared.es.d.ts +2 -0
- package/dist/shared.es.js +1367 -0
- package/dist/shared.umd.js +1 -0
- package/dist/storage/index.d.ts +144 -0
- package/dist/string/index.d.ts +40 -0
- package/dist/timer/index.d.ts +9 -0
- package/eslint.config.js +10 -0
- package/package.json +26 -0
- package/scripts/build.mjs +92 -0
- package/skill/SKILL.md +240 -0
- package/skill/examples/usage.ts +67 -0
- package/skill/references/clipboard.md +39 -0
- package/skill/references/cloneDeep.md +60 -0
- package/skill/references/cookie.md +56 -0
- package/skill/references/date.md +466 -0
- package/skill/references/device.md +138 -0
- package/skill/references/element.md +99 -0
- package/skill/references/is.md +415 -0
- package/skill/references/lodash.md +472 -0
- package/skill/references/number.md +248 -0
- package/skill/references/storage.md +113 -0
- package/skill/references/string.md +126 -0
- package/skill/references/timer.md +78 -0
- package/src/clipboard/index.ts +26 -0
- package/src/cloneDeep/__test__/cloneDeep.test.ts +92 -0
- package/src/cloneDeep/index.ts +168 -0
- package/src/constants.ts +27 -0
- package/src/cookie/index.ts +44 -0
- package/src/date/__test__/date-diff.test.ts +23 -0
- package/src/date/__test__/date-duration.test.ts +140 -0
- package/src/date/__test__/date-from.test.ts +64 -0
- package/src/date/__test__/date.test.ts +67 -0
- package/src/date/index.ts +331 -0
- package/src/device/__test__/device.test.ts +138 -0
- package/src/device/index.ts +125 -0
- package/src/element/index.ts +100 -0
- package/src/index.ts +14 -0
- package/src/is/__test__/is.test.ts +320 -0
- package/src/is/index.ts +293 -0
- package/src/lodash/__test__/lodash.test.ts +111 -0
- package/src/lodash/__test__/obj-string.test.ts +107 -0
- package/src/lodash/__test__/uniqueId.test.ts +40 -0
- package/src/lodash/index.ts +396 -0
- package/src/number/__test__/number.test.ts +137 -0
- package/src/number/index.ts +161 -0
- package/src/storage/__test__/storage.test.ts +44 -0
- package/src/storage/index.ts +185 -0
- package/src/string/__test__/string.test.ts +24 -0
- package/src/string/index.ts +49 -0
- package/src/timer/index.ts +15 -0
- package/tsconfig.json +25 -0
- package/types/global.d.ts +13 -0
- package/vite.config.ts +16 -0
- package/vitest.config.ts +28 -0
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 删除对象中的某些键值对
|
|
3
|
+
* @param obj - 源对象
|
|
4
|
+
* @param fields - 需要删除的字段数组
|
|
5
|
+
* @param ignoreEmpty - 是否忽略 undefined | null
|
|
6
|
+
* @returns 返回新的对象
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* const obj = {
|
|
10
|
+
a: 1,
|
|
11
|
+
b: {
|
|
12
|
+
c: 2,
|
|
13
|
+
d: {
|
|
14
|
+
e: 3,
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
c: '',
|
|
18
|
+
d: undefined,
|
|
19
|
+
}
|
|
20
|
+
const cloneObj = omit(obj, ['a'])
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function omit<T extends Record<string, any>, K extends keyof T>(obj: T, fields: K[] | string[], ignoreEmpty?: boolean): Omit<T, K>;
|
|
24
|
+
export type Writeable<T> = {
|
|
25
|
+
-readonly [P in keyof T]: T[P];
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* 从对象中取出指定的键值对
|
|
29
|
+
* @param obj - 源对象
|
|
30
|
+
* @param keys - 需要取出的键值对
|
|
31
|
+
* @param ignoreEmpty - 是否忽略 undefined
|
|
32
|
+
* @returns 返回新的对象
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* const obj = {
|
|
36
|
+
a: 1,
|
|
37
|
+
b: {
|
|
38
|
+
c: 2,
|
|
39
|
+
d: {
|
|
40
|
+
e: 3,
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
}
|
|
44
|
+
const cloneObj = pick(obj, ['b'])
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function pick<T, U extends keyof T>(obj: T, keys: ReadonlyArray<U> | string[], ignoreUndefined?: boolean): Writeable<Pick<T, U>>;
|
|
48
|
+
/**
|
|
49
|
+
* 从对象中取出指定的键值对,第二个参数predicate(断言函数)
|
|
50
|
+
* @param obj - 源对象
|
|
51
|
+
* @param predicate - 断言函数,判断为真值的属性会被返回
|
|
52
|
+
* @returns 返回新的对象
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* const obj = {
|
|
56
|
+
a: 1,
|
|
57
|
+
b: {
|
|
58
|
+
c: 2,
|
|
59
|
+
d: {
|
|
60
|
+
e: 3,
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
c: '',
|
|
64
|
+
d: undefined,
|
|
65
|
+
}
|
|
66
|
+
const cloneObj = pickBy(obj, (value) => !!value)
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export declare function pickBy<T>(obj: T, predicate: (val: NonNullable<T>[keyof T], key: keyof T) => boolean): Partial<T>;
|
|
70
|
+
type OmitBy<T, F> = {
|
|
71
|
+
[K in keyof T as F extends T[K] ? never : K]: T[K];
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* 从对象中去除属性,通过第二个参数predicate(断言函数)
|
|
75
|
+
* 与 {@link pickBy} 反向版
|
|
76
|
+
* @param obj - 源对象
|
|
77
|
+
* @param predicate - 断言函数,判断为真值的属性会被**去除**
|
|
78
|
+
* @returns 返回新的对象
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* const obj = {
|
|
82
|
+
a: 1,
|
|
83
|
+
b: {
|
|
84
|
+
c: 2,
|
|
85
|
+
d: {
|
|
86
|
+
e: 3,
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
c: '',
|
|
90
|
+
d: undefined,
|
|
91
|
+
}
|
|
92
|
+
const cloneObj = omitBy(obj, (value) => !value)
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
export declare function omitBy<T>(object: T, predicate: (value: T[keyof T], key: keyof T) => boolean): OmitBy<T, T[keyof T]>;
|
|
96
|
+
/**
|
|
97
|
+
* 防抖函数
|
|
98
|
+
* @param fn - 需要防抖的函数
|
|
99
|
+
* @param delay - 防抖的时间
|
|
100
|
+
* @example
|
|
101
|
+
* ```ts
|
|
102
|
+
* let handleSearch =()=>{}
|
|
103
|
+
* const debounceSearch = debounce(handleSearch)
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export declare const debounce: (fn: Function, delay?: number) => (this: unknown, ...args: any[]) => void;
|
|
107
|
+
/**
|
|
108
|
+
* 节流函数
|
|
109
|
+
* @param fn - 需要节流的函数
|
|
110
|
+
* @param limit - 节流的时间
|
|
111
|
+
* @param exeLastFunc - 是否执行最后一次函数
|
|
112
|
+
* @example
|
|
113
|
+
* ```ts
|
|
114
|
+
* let handleSearch =()=>{}
|
|
115
|
+
* const throttleSearch = throttle(handleSearch)
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
export declare const throttle: <T extends (...args: any) => any>(fn: T, limit?: number, exeLastFunc?: boolean) => (this: unknown, ...args: Parameters<T>) => void;
|
|
119
|
+
/**
|
|
120
|
+
* 生成当前浏览器唯一id
|
|
121
|
+
* (自增+页面渲染时间+ random随机数)
|
|
122
|
+
* 对于一般的唯一ID 生成来说是足够的
|
|
123
|
+
* @param length -随机数长度 默认16
|
|
124
|
+
* @example
|
|
125
|
+
* ```ts
|
|
126
|
+
* let uid11 = uniqueId(11) //11位
|
|
127
|
+
* let uid16 = uniqueId() //16位
|
|
128
|
+
* let uid19 = uniqueId(19) //19 位
|
|
129
|
+
* let uid32 = uniqueId(32)
|
|
130
|
+
* ```
|
|
131
|
+
* @returns 唯一id
|
|
132
|
+
*/
|
|
133
|
+
export declare function uniqueId(length?: number): string;
|
|
134
|
+
/**
|
|
135
|
+
* 将 Blob 对象转换为 base64 字符串
|
|
136
|
+
* @param blob - Blob 对象
|
|
137
|
+
* @param ignorePrefix - 是否忽略 dateUrl 前缀
|
|
138
|
+
* @example
|
|
139
|
+
* ```ts
|
|
140
|
+
* let base64 = blobToBase64(blob)
|
|
141
|
+
* let base64 = blobToBase64(blob,false)
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
export declare function blobToBase64(blob: Blob, ignorePrefix?: boolean): Promise<string>;
|
|
145
|
+
type DeepKeyOf<T> = T extends object ? {
|
|
146
|
+
[K in keyof T]-?: K extends string ? K | `${K}.${DeepKeyOf<T[K]>}` : never;
|
|
147
|
+
}[keyof T] : never;
|
|
148
|
+
type DeepValueOf<T, K extends string> = K extends `${infer P}.${infer Rest}` ? P extends keyof T ? DeepValueOf<T[P], Rest> : '' : K extends keyof T ? T[K] : '';
|
|
149
|
+
/**
|
|
150
|
+
* 从对象中获取指定路径的值
|
|
151
|
+
* @param object -对象
|
|
152
|
+
* @param path - 指定路径
|
|
153
|
+
* @example
|
|
154
|
+
* ```ts
|
|
155
|
+
* const obj = {
|
|
156
|
+
* a: { b: { c: 3 } }
|
|
157
|
+
* }
|
|
158
|
+
* const value = get(obj, 'a.b.c')
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
export declare function get<T, K extends DeepKeyOf<T>>(obj: T, path: K): DeepValueOf<T, K>;
|
|
162
|
+
/**
|
|
163
|
+
* 对象转查询字符串
|
|
164
|
+
* @param obj - 对象
|
|
165
|
+
* @returns 查询字符串
|
|
166
|
+
* @example
|
|
167
|
+
* ```ts
|
|
168
|
+
* const str = objToQString({ a: 1, b: 2 })
|
|
169
|
+
* // 输出: 'a=1&b=2'
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
export declare function objToQString(obj: Record<string, any>): string;
|
|
173
|
+
/**
|
|
174
|
+
* 查询字符串转对象
|
|
175
|
+
* @param qString - 查询字符串
|
|
176
|
+
* @returns 对象
|
|
177
|
+
* @example
|
|
178
|
+
* ```ts
|
|
179
|
+
* const obj = qStringToObj('a=1&b=2')
|
|
180
|
+
* // 输出: { a: 1, b: 2 }
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
export declare function qStringToObj(qString: string | null): Record<string, any>;
|
|
184
|
+
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { default as Big, RoundingMode } from 'big.js';
|
|
2
|
+
type BigSource = number | string | Big;
|
|
3
|
+
/**
|
|
4
|
+
* 返回一个实例化的Big对象
|
|
5
|
+
* @param n - 待处理的数字/字符串数字
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* const value = useNumber('1')
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export declare function useNumber(n: BigSource): Big;
|
|
12
|
+
/**
|
|
13
|
+
* 4舍5入(精度兼容)
|
|
14
|
+
* @param m - 数字
|
|
15
|
+
* @param dp - 保留位数
|
|
16
|
+
* @param rm - 0: 向下取整 1: 四舍五入 2: 向上取整
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const value = round(5.23, 1, 1)
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function round(m: BigSource, dp: number, rm?: RoundingMode): number;
|
|
23
|
+
export interface FormatOptions {
|
|
24
|
+
/**
|
|
25
|
+
* 保留小数位数
|
|
26
|
+
*/
|
|
27
|
+
precision?: number;
|
|
28
|
+
/**
|
|
29
|
+
* 千位分隔符
|
|
30
|
+
*/
|
|
31
|
+
thousandSeparator?: string;
|
|
32
|
+
/**
|
|
33
|
+
* 分割的位数(3位代表千分位分割)
|
|
34
|
+
*/
|
|
35
|
+
bit?: number;
|
|
36
|
+
/**
|
|
37
|
+
* 0: 向下取整 1: 四舍五入, 2: roundHalfEven, 3: 向上取整
|
|
38
|
+
*/
|
|
39
|
+
roundMode?: RoundingMode;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* 格式化数字, 默认千位分隔符为","
|
|
43
|
+
* @param val - 要格式化的数字
|
|
44
|
+
* @param options - 配置项
|
|
45
|
+
* @returns 格式化后的数字字符串
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* formatNumber(1000) //输出 "1,000"
|
|
49
|
+
* formatNumber(1234567) //输出 "1,234,567"
|
|
50
|
+
* formatNumber(1234.5678, { precision: 2, thousandSeparator: "-" }) // 输出: "1-234.5678"
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare function formatNumber(val: number | string, options?: FormatOptions): string;
|
|
54
|
+
export interface MoneyFormatOptions {
|
|
55
|
+
/**
|
|
56
|
+
* 亿的单位字符串,默认 '亿'
|
|
57
|
+
*/
|
|
58
|
+
yi?: string;
|
|
59
|
+
/**
|
|
60
|
+
* 万的单位字符串,默认 '万'
|
|
61
|
+
*/
|
|
62
|
+
wan?: string;
|
|
63
|
+
/**
|
|
64
|
+
* 千位分隔符,默认 ',',传空字符串或不传则不启用千位分隔
|
|
65
|
+
*/
|
|
66
|
+
thousandSeparator?: string;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* 格式化金钱(支持万、亿)
|
|
70
|
+
* @param num - 数字
|
|
71
|
+
* @param options - 配置项
|
|
72
|
+
* @returns 格式化后的金钱字符串
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* formatMoney(1234567) // '1,234,567'
|
|
76
|
+
* formatMoney(10000000) // '1,000万'
|
|
77
|
+
* formatMoney(100000000) // '1亿'
|
|
78
|
+
* formatMoney(123456789) // '1亿2,345万6,789'
|
|
79
|
+
* formatMoney(123456789, { yi: 'y', wan: 'w' }) // '1y2,345w6,789'
|
|
80
|
+
* formatMoney(123456789, { thousandSeparator: '' }) // '1亿2345万6789'
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export declare function formatMoney(num: number, options?: MoneyFormatOptions): string;
|
|
84
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@allkit/shared",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "this is a shared package",
|
|
5
|
+
"main": "./shared.umd.js",
|
|
6
|
+
"module":"./shared.es.js",
|
|
7
|
+
"types": "index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./shared.es.js",
|
|
11
|
+
"require": "./shared.umd.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"keywords": ["lodash", "dayjs", "big.js","@allkit/shared"],
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"author": "Spig",
|
|
17
|
+
"publishConfig":{"access":"public"},
|
|
18
|
+
"dependencies":{"@types/big.js":"^6.1.6","@types/js-cookie":"^3.0.3","big.js":"^6.2.1","dayjs":"^1.11.10","js-cookie":"^3.0.5"},
|
|
19
|
+
"peerDependencies": {}
|
|
20
|
+
}
|
|
21
|
+
|