@hairy/utils 1.0.16 → 1.0.20
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/LICENSE +23 -23
- package/index.cjs.js +66 -64
- package/index.d.ts +196 -198
- package/index.esm.js +67 -64
- package/index.iife.js +66 -64
- package/index.iife.min.js +1 -1
- package/package.json +4 -4
package/LICENSE
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2019-PRESENT Anthony Fu<https://github.com/TuiMao233>
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
22
|
-
|
|
23
|
-
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019-PRESENT Anthony Fu<https://github.com/TuiMao233>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
|
package/index.cjs.js
CHANGED
|
@@ -9,7 +9,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
9
9
|
|
|
10
10
|
var dayjs__default = /*#__PURE__*/_interopDefaultLegacy(dayjs);
|
|
11
11
|
|
|
12
|
-
const
|
|
12
|
+
const colourBlend = (colorOne, colorTwo, ratio) => {
|
|
13
13
|
ratio = Math.max(Math.min(Number(ratio), 1), 0);
|
|
14
14
|
const r1 = parseInt(colorOne.slice(1, 3), 16);
|
|
15
15
|
const g1 = parseInt(colorOne.slice(3, 5), 16);
|
|
@@ -35,18 +35,18 @@ const hexToRgba = (hex, opacity) => {
|
|
|
35
35
|
};
|
|
36
36
|
};
|
|
37
37
|
const fuseThemeColor = (color) => ({
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
38
|
+
"light-2": colourBlend("#ffffff", color, 0.8),
|
|
39
|
+
"light-4": colourBlend("#ffffff", color, 0.6),
|
|
40
|
+
"light-6": colourBlend("#ffffff", color, 0.4),
|
|
41
|
+
"light-8": colourBlend("#ffffff", color, 0.2),
|
|
42
|
+
"dark-2": colourBlend("#000000", color, 0.8),
|
|
43
|
+
"dark-4": colourBlend("#000000", color, 0.6),
|
|
44
|
+
"dark-6": colourBlend("#000000", color, 0.4),
|
|
45
|
+
"dark-8": colourBlend("#000000", color, 0.2),
|
|
46
|
+
"opacity-2": hexToRgba(color, 0.8).rgba,
|
|
47
|
+
"opacity-4": hexToRgba(color, 0.6).rgba,
|
|
48
|
+
"opacity-6": hexToRgba(color, 0.4).rgba,
|
|
49
|
+
"opacity-8": hexToRgba(color, 0.2).rgba
|
|
50
50
|
});
|
|
51
51
|
|
|
52
52
|
const formatClearHtml = (string_) => string_.replace(/<[!/]*[^<>]*>/gi, "");
|
|
@@ -94,49 +94,18 @@ const isChrome = UA && /chrome\/\d+/.test(UA) && !isEdge;
|
|
|
94
94
|
const isPhantomJS = UA && /phantomjs/.test(UA);
|
|
95
95
|
const isFF = typeof UA == "string" && UA.match(/firefox\/(\d+)/);
|
|
96
96
|
const isMobile = isBrowser && navigator.userAgent.toLowerCase().includes("mobile");
|
|
97
|
-
|
|
98
|
-
const analyUnit = (size, unit = "px") => {
|
|
99
|
-
return lodash.isString(size) && /\D/g.test(size) ? size : size + unit;
|
|
100
|
-
};
|
|
101
|
-
const analySize = (size, unit) => {
|
|
102
|
-
if (typeof size === "string" || typeof size === "number") {
|
|
103
|
-
return { width: analyUnit(size, unit), height: analyUnit(size, unit) };
|
|
104
|
-
}
|
|
105
|
-
if (Array.isArray(size)) {
|
|
106
|
-
return { width: analyUnit(size[0], unit), height: analyUnit(size[1], unit) };
|
|
107
|
-
}
|
|
108
|
-
if (typeof size === "object") {
|
|
109
|
-
return { width: analyUnit(size.width, unit), height: analyUnit(size.height, unit) };
|
|
110
|
-
}
|
|
111
|
-
return { width: "", height: "" };
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
const checkedTypeof = (target) => {
|
|
115
|
-
return Object.prototype.toString.call(target).slice(8, -1);
|
|
116
|
-
};
|
|
117
|
-
const assert = (condition, ...infos) => {
|
|
118
|
-
if (!condition)
|
|
119
|
-
console.warn(...infos);
|
|
120
|
-
return condition;
|
|
121
|
-
};
|
|
122
|
-
const isClient = typeof window !== "undefined";
|
|
123
97
|
const isFormData = (value) => lodash.isObject(value) && value instanceof FormData;
|
|
124
98
|
const isWindow = (value) => typeof window !== "undefined" && toString.call(value) === "[object Window]";
|
|
125
99
|
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
if (queryString.length > 0)
|
|
129
|
-
url += "?" + queryString.join("&");
|
|
130
|
-
return url;
|
|
131
|
-
};
|
|
132
|
-
const awaitPromise = (code = 1e3) => {
|
|
133
|
-
return new Promise((resolve) => setTimeout(resolve, code));
|
|
100
|
+
const formDataToObject = (formData) => {
|
|
101
|
+
return Object.fromEntries(formData.entries());
|
|
134
102
|
};
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
103
|
+
const objectToFormData = (object) => {
|
|
104
|
+
const formData = new FormData();
|
|
105
|
+
for (const [key, value] of Object.entries(object)) {
|
|
106
|
+
formData.append(key, String(value));
|
|
107
|
+
}
|
|
108
|
+
return formData;
|
|
140
109
|
};
|
|
141
110
|
const pickByParams = (params, filters, deep = false) => {
|
|
142
111
|
deep && lodash.forIn(params, (value, key) => {
|
|
@@ -149,16 +118,6 @@ const pickByParams = (params, filters, deep = false) => {
|
|
|
149
118
|
}
|
|
150
119
|
return pickValue;
|
|
151
120
|
};
|
|
152
|
-
const formDataToObject = (formData) => {
|
|
153
|
-
return Object.fromEntries(formData.entries());
|
|
154
|
-
};
|
|
155
|
-
const objectToFormData = (object) => {
|
|
156
|
-
const formData = new FormData();
|
|
157
|
-
for (const [key, value] of Object.entries(object)) {
|
|
158
|
-
formData.append(key, value);
|
|
159
|
-
}
|
|
160
|
-
return formData;
|
|
161
|
-
};
|
|
162
121
|
const objectFlat = (object, deep = 1) => {
|
|
163
122
|
const flatDeep = (object2, deep2 = 1) => {
|
|
164
123
|
let _object = {};
|
|
@@ -173,17 +132,61 @@ const objectFlat = (object, deep = 1) => {
|
|
|
173
132
|
};
|
|
174
133
|
return flatDeep(object, deep);
|
|
175
134
|
};
|
|
135
|
+
|
|
136
|
+
const analyUnit = (value, unit = "px") => {
|
|
137
|
+
const empty = !(lodash.isString(value) || lodash.isNumber(value));
|
|
138
|
+
if (empty)
|
|
139
|
+
return "";
|
|
140
|
+
return lodash.isString(value) && /\D/g.test(value) ? value : value + unit;
|
|
141
|
+
};
|
|
142
|
+
const analySize = (size, unit) => {
|
|
143
|
+
if (typeof size === "string" || typeof size === "number") {
|
|
144
|
+
return { width: analyUnit(size, unit), height: analyUnit(size, unit) };
|
|
145
|
+
}
|
|
146
|
+
if (Array.isArray(size)) {
|
|
147
|
+
return { width: analyUnit(size[0], unit), height: analyUnit(size[1], unit) };
|
|
148
|
+
}
|
|
149
|
+
if (typeof size === "object") {
|
|
150
|
+
return { width: analyUnit(size.width, unit), height: analyUnit(size.height, unit) };
|
|
151
|
+
}
|
|
152
|
+
return { width: "", height: "" };
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
const urlParamsAnaly = (url, params) => {
|
|
156
|
+
const queryString = Object.keys(params).map((key) => `${key}=${params[key]}`);
|
|
157
|
+
if (queryString.length > 0)
|
|
158
|
+
url += "?" + queryString.join("&");
|
|
159
|
+
return url;
|
|
160
|
+
};
|
|
161
|
+
const awaitPromise = (ms = 1e3) => {
|
|
162
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
163
|
+
};
|
|
164
|
+
const generateArray = (start, end) => {
|
|
165
|
+
start = Number(start);
|
|
166
|
+
end = Number(end);
|
|
167
|
+
end = end > start ? end : start;
|
|
168
|
+
return [...new Array(end + 1).keys()].slice(start);
|
|
169
|
+
};
|
|
176
170
|
const noop = () => {
|
|
177
171
|
};
|
|
172
|
+
const checkedTypeof = (target) => {
|
|
173
|
+
const value = Object.prototype.toString.call(target).slice(8, -1).toLocaleLowerCase();
|
|
174
|
+
return value;
|
|
175
|
+
};
|
|
176
|
+
const assert = (condition, ...infos) => {
|
|
177
|
+
if (!condition)
|
|
178
|
+
console.warn(...infos);
|
|
179
|
+
return condition;
|
|
180
|
+
};
|
|
178
181
|
|
|
179
182
|
exports.UA = UA;
|
|
180
183
|
exports.analySize = analySize;
|
|
181
184
|
exports.analyUnit = analyUnit;
|
|
182
185
|
exports.assert = assert;
|
|
183
186
|
exports.awaitPromise = awaitPromise;
|
|
184
|
-
exports.blendColor = blendColor;
|
|
185
187
|
exports.capitalizeCamelCase = capitalizeCamelCase;
|
|
186
188
|
exports.checkedTypeof = checkedTypeof;
|
|
189
|
+
exports.colourBlend = colourBlend;
|
|
187
190
|
exports.formDataToObject = formDataToObject;
|
|
188
191
|
exports.formatClearHtml = formatClearHtml;
|
|
189
192
|
exports.formatCoverPhone = formatCoverPhone;
|
|
@@ -197,7 +200,6 @@ exports.hexToRgba = hexToRgba;
|
|
|
197
200
|
exports.isAndroid = isAndroid;
|
|
198
201
|
exports.isBrowser = isBrowser;
|
|
199
202
|
exports.isChrome = isChrome;
|
|
200
|
-
exports.isClient = isClient;
|
|
201
203
|
exports.isEdge = isEdge;
|
|
202
204
|
exports.isFF = isFF;
|
|
203
205
|
exports.isFormData = isFormData;
|
package/index.d.ts
CHANGED
|
@@ -1,210 +1,208 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
* @param
|
|
6
|
-
* @
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
*
|
|
13
|
-
* @
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
'
|
|
29
|
-
'
|
|
30
|
-
'
|
|
31
|
-
'
|
|
32
|
-
'
|
|
33
|
-
'
|
|
34
|
-
'
|
|
35
|
-
'
|
|
36
|
-
'
|
|
37
|
-
'
|
|
38
|
-
'primaryColorOpacity-6': string;
|
|
39
|
-
'primaryColorOpacity-8': string;
|
|
1
|
+
/**
|
|
2
|
+
* 颜色混合器 - 仅支持 hex 颜色完整值
|
|
3
|
+
* @param colorOne 颜色值
|
|
4
|
+
* @param colorTwo 颜色值
|
|
5
|
+
* @param ratio 根据 colorTwo 混合比例, 0~1 区间, 1 则是完全的 colorTwo
|
|
6
|
+
* @returns 混合颜色
|
|
7
|
+
*/
|
|
8
|
+
declare const colourBlend: (colorOne: string, colorTwo: string, ratio: number) => string;
|
|
9
|
+
/**
|
|
10
|
+
* 将 hex 颜色转成 rgb
|
|
11
|
+
* @param hex
|
|
12
|
+
* @param opacity
|
|
13
|
+
* @returns rgba String
|
|
14
|
+
*/
|
|
15
|
+
declare const hexToRgba: (hex: string, opacity: number) => {
|
|
16
|
+
red: number;
|
|
17
|
+
green: number;
|
|
18
|
+
blue: number;
|
|
19
|
+
rgba: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* 根据颜色融合出黑色与白色, 透明度色
|
|
23
|
+
* @param color
|
|
24
|
+
*/
|
|
25
|
+
declare const fuseThemeColor: (color: string) => {
|
|
26
|
+
'light-2': string;
|
|
27
|
+
'light-4': string;
|
|
28
|
+
'light-6': string;
|
|
29
|
+
'light-8': string;
|
|
30
|
+
'dark-2': string;
|
|
31
|
+
'dark-4': string;
|
|
32
|
+
'dark-6': string;
|
|
33
|
+
'dark-8': string;
|
|
34
|
+
'opacity-2': string;
|
|
35
|
+
'opacity-4': string;
|
|
36
|
+
'opacity-6': string;
|
|
37
|
+
'opacity-8': string;
|
|
40
38
|
};
|
|
41
39
|
|
|
42
|
-
/**
|
|
43
|
-
* 格式化剔除字符串代码字段
|
|
44
|
-
* @param str 字符串
|
|
45
|
-
* @returns 剔除字符串
|
|
46
|
-
*/
|
|
47
|
-
declare const formatClearHtml: (string_: string) => string;
|
|
48
|
-
/**
|
|
49
|
-
* 格式化为价格(两位小数点)
|
|
50
|
-
* @param value 传入字符
|
|
51
|
-
*/
|
|
52
|
-
declare const formatPrice: (value: string) => string;
|
|
53
|
-
/**
|
|
54
|
-
* 格式化为正整数
|
|
55
|
-
* @param value 传入字符
|
|
56
|
-
*/
|
|
57
|
-
declare const formatInteger: (value: string) => string;
|
|
58
|
-
/**
|
|
59
|
-
* 格式化数字千位分隔符
|
|
60
|
-
* @param number_ 数值
|
|
61
|
-
* @param unit 单位
|
|
62
|
-
*/
|
|
63
|
-
declare const formatThousandBitSeparator: (target: number | string, unit?: string) => string;
|
|
64
|
-
/**
|
|
65
|
-
* 时间戳格式化(秒)
|
|
66
|
-
* @param timestamp 格式化时间戳(秒)
|
|
67
|
-
* @param format 格式化时间格式
|
|
68
|
-
* @returns 格式时间字符串
|
|
69
|
-
*/
|
|
70
|
-
declare const formatUnix: (timestamp: number, format?: string) => string;
|
|
71
|
-
/**
|
|
72
|
-
* 隐藏手机号中间四位
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
*
|
|
78
|
-
* @param
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
*
|
|
84
|
-
|
|
40
|
+
/**
|
|
41
|
+
* 格式化剔除字符串代码字段
|
|
42
|
+
* @param str 字符串
|
|
43
|
+
* @returns 剔除字符串
|
|
44
|
+
*/
|
|
45
|
+
declare const formatClearHtml: (string_: string) => string;
|
|
46
|
+
/**
|
|
47
|
+
* 格式化为价格(两位小数点)
|
|
48
|
+
* @param value 传入字符
|
|
49
|
+
*/
|
|
50
|
+
declare const formatPrice: (value: string) => string;
|
|
51
|
+
/**
|
|
52
|
+
* 格式化为正整数
|
|
53
|
+
* @param value 传入字符
|
|
54
|
+
*/
|
|
55
|
+
declare const formatInteger: (value: string) => string;
|
|
56
|
+
/**
|
|
57
|
+
* 格式化数字千位分隔符
|
|
58
|
+
* @param number_ 数值
|
|
59
|
+
* @param unit 单位
|
|
60
|
+
*/
|
|
61
|
+
declare const formatThousandBitSeparator: (target: number | string, unit?: string) => string;
|
|
62
|
+
/**
|
|
63
|
+
* 时间戳格式化(秒)
|
|
64
|
+
* @param timestamp 格式化时间戳(秒)
|
|
65
|
+
* @param format 格式化时间格式
|
|
66
|
+
* @returns 格式时间字符串
|
|
67
|
+
*/
|
|
68
|
+
declare const formatUnix: (timestamp: number, format?: string) => string;
|
|
69
|
+
/**
|
|
70
|
+
* 隐藏手机号中间四位
|
|
71
|
+
* @param phone 手机号
|
|
72
|
+
*/
|
|
73
|
+
declare const formatCoverPhone: (phone: string) => string;
|
|
74
|
+
/**
|
|
75
|
+
* 数字位数不够时,进行前补零
|
|
76
|
+
* @param num 数值
|
|
77
|
+
* @param lh 长度
|
|
78
|
+
*/
|
|
79
|
+
declare const prefixZero: (number_: number, lh?: number) => string;
|
|
80
|
+
/**
|
|
81
|
+
* 转换大写驼峰
|
|
82
|
+
* @param str
|
|
83
|
+
*/
|
|
85
84
|
declare const capitalizeCamelCase: (string_: string) => string;
|
|
86
85
|
|
|
87
|
-
declare const isBrowser: boolean;
|
|
88
|
-
declare const isWeex: boolean;
|
|
89
|
-
declare const weexPlatform: any;
|
|
90
|
-
declare const UA: string | false;
|
|
91
|
-
declare const isIE: boolean | "";
|
|
92
|
-
declare const isIE9: boolean | "";
|
|
93
|
-
declare const isIE11: boolean;
|
|
94
|
-
declare const isEdge: boolean | "";
|
|
95
|
-
declare const isAndroid: boolean;
|
|
96
|
-
declare const isIOS: boolean;
|
|
97
|
-
declare const isChrome: boolean | "";
|
|
98
|
-
declare const isPhantomJS: boolean | "";
|
|
99
|
-
declare const isFF: false | RegExpMatchArray | null;
|
|
86
|
+
declare const isBrowser: boolean;
|
|
87
|
+
declare const isWeex: boolean;
|
|
88
|
+
declare const weexPlatform: any;
|
|
89
|
+
declare const UA: string | false;
|
|
90
|
+
declare const isIE: boolean | "";
|
|
91
|
+
declare const isIE9: boolean | "";
|
|
92
|
+
declare const isIE11: boolean;
|
|
93
|
+
declare const isEdge: boolean | "";
|
|
94
|
+
declare const isAndroid: boolean;
|
|
95
|
+
declare const isIOS: boolean;
|
|
96
|
+
declare const isChrome: boolean | "";
|
|
97
|
+
declare const isPhantomJS: boolean | "";
|
|
98
|
+
declare const isFF: false | RegExpMatchArray | null;
|
|
100
99
|
declare const isMobile: boolean;
|
|
100
|
+
declare const isFormData: (value: any) => value is FormData;
|
|
101
|
+
declare const isWindow: (value: any) => value is Window;
|
|
101
102
|
|
|
102
|
-
/**
|
|
103
|
-
*
|
|
104
|
-
* @param
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
*
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
103
|
+
/**
|
|
104
|
+
* 将 formData 转换为 object
|
|
105
|
+
* @param formData
|
|
106
|
+
*/
|
|
107
|
+
declare const formDataToObject: (formData: FormData) => Record<string, string>;
|
|
108
|
+
/**
|
|
109
|
+
* 将 object 转换为 formData
|
|
110
|
+
* @param object
|
|
111
|
+
*/
|
|
112
|
+
declare const objectToFormData: (object: Record<string, string | number>) => FormData;
|
|
113
|
+
/**
|
|
114
|
+
* 过滤对象|数组中 filters 中的值
|
|
115
|
+
* @param params
|
|
116
|
+
* @param filters
|
|
117
|
+
*/
|
|
118
|
+
declare const pickByParams: <T extends object>(params: T, filters: any[], deep?: boolean) => Partial<T>;
|
|
119
|
+
/**
|
|
120
|
+
* 对象扁平化处理
|
|
121
|
+
* @param object 对象
|
|
122
|
+
* @param deep 深度
|
|
123
|
+
*/
|
|
124
|
+
declare const objectFlat: (object: Record<string, any>, deep?: number) => Record<string, any>;
|
|
123
125
|
|
|
124
|
-
declare type PlainObject = {
|
|
125
|
-
[key: string]: any;
|
|
126
|
-
};
|
|
127
|
-
declare type LooseNumber = string | number;
|
|
128
|
-
declare type Key = string | number | symbol;
|
|
129
|
-
declare type DeepReadonly<T> = {
|
|
130
|
-
readonly [P in keyof T]: T[P] extends object ? DeepReadonly<T[P]> : T[P];
|
|
131
|
-
};
|
|
132
|
-
declare type DeepRequired<T> = {
|
|
133
|
-
[P in keyof T]-?: T[P] extends object ? DeepRequired<T[P]> : T[P];
|
|
134
|
-
};
|
|
135
|
-
declare type DeepPartial<T> = {
|
|
136
|
-
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
137
|
-
};
|
|
138
|
-
declare type DeepKeyof<T> = T extends object ? keyof T | DeepKeyof<T[keyof T]> : never;
|
|
139
|
-
declare type DeepReplace<T, K = unknown, V = unknown> = {
|
|
140
|
-
[P in keyof T]: K extends P ? V : DeepReplace<T[P], K, V>;
|
|
141
|
-
};
|
|
142
|
-
declare type Option<L extends Key = 'label', V extends Key = 'value', C extends Key = 'children'> = {
|
|
143
|
-
[P in L]
|
|
144
|
-
} & {
|
|
145
|
-
[P in V]
|
|
146
|
-
} & {
|
|
147
|
-
[P in C]?: Option[];
|
|
126
|
+
declare type PlainObject = {
|
|
127
|
+
[key: string]: any;
|
|
128
|
+
};
|
|
129
|
+
declare type LooseNumber = string | number;
|
|
130
|
+
declare type Key = string | number | symbol;
|
|
131
|
+
declare type DeepReadonly<T> = {
|
|
132
|
+
readonly [P in keyof T]: T[P] extends object ? DeepReadonly<T[P]> : T[P];
|
|
133
|
+
};
|
|
134
|
+
declare type DeepRequired<T> = {
|
|
135
|
+
[P in keyof T]-?: T[P] extends object ? DeepRequired<T[P]> : T[P];
|
|
136
|
+
};
|
|
137
|
+
declare type DeepPartial<T> = {
|
|
138
|
+
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
139
|
+
};
|
|
140
|
+
declare type DeepKeyof<T> = T extends object ? keyof T | DeepKeyof<T[keyof T]> : never;
|
|
141
|
+
declare type DeepReplace<T, K = unknown, V = unknown> = {
|
|
142
|
+
[P in keyof T]: K extends P ? V : DeepReplace<T[P], K, V>;
|
|
143
|
+
};
|
|
144
|
+
declare type Option<L extends Key = 'label', V extends Key = 'value', C extends Key = 'children'> = {
|
|
145
|
+
[P in L]?: string;
|
|
146
|
+
} & {
|
|
147
|
+
[P in V]?: LooseNumber;
|
|
148
|
+
} & {
|
|
149
|
+
[P in C]?: Option<L, V, C>[];
|
|
148
150
|
};
|
|
149
151
|
|
|
150
|
-
/**
|
|
151
|
-
*
|
|
152
|
-
* @param
|
|
153
|
-
* @
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
152
|
+
/**
|
|
153
|
+
* 如果有单位,如百分比,px单位等,直接返回,如果是纯粹的数值,则加上px单位
|
|
154
|
+
* @param size 尺寸
|
|
155
|
+
* @param unit 单元
|
|
156
|
+
* @returns string
|
|
157
|
+
*/
|
|
158
|
+
declare const analyUnit: (value: LooseNumber, unit?: string) => string;
|
|
159
|
+
/** size 转换配置 */
|
|
160
|
+
declare type AnalySizeOption = LooseNumber | [LooseNumber, LooseNumber] | {
|
|
161
|
+
width: LooseNumber;
|
|
162
|
+
height: LooseNumber;
|
|
163
|
+
};
|
|
164
|
+
/**
|
|
165
|
+
* 将 size 转换为宽高
|
|
166
|
+
* @param size { AnalySizeOption }
|
|
167
|
+
* @returns
|
|
168
|
+
*/
|
|
169
|
+
declare const analySize: (size: AnalySizeOption, unit?: string | undefined) => {
|
|
170
|
+
width: string;
|
|
171
|
+
height: string;
|
|
172
|
+
};
|
|
165
173
|
|
|
166
|
-
/**
|
|
167
|
-
* 地址参数计算
|
|
168
|
-
* @param url 传入url
|
|
169
|
-
* @param params 请求参数
|
|
170
|
-
* @returns 拼接url
|
|
171
|
-
*/
|
|
172
|
-
declare const urlParamsAnaly: (url: string, params: Record<string, any>) => string;
|
|
173
|
-
/**
|
|
174
|
-
* 自定义 Promise 等待
|
|
175
|
-
* @param code 等待时间
|
|
176
|
-
*/
|
|
177
|
-
declare const awaitPromise: (
|
|
178
|
-
/**
|
|
179
|
-
* 生成递进的数组
|
|
180
|
-
* @param start 开始数值
|
|
181
|
-
* @param end 结束数值
|
|
182
|
-
* @returns 递进的数组
|
|
183
|
-
*/
|
|
184
|
-
declare const generateArray: (start: number, end: number) => number[];
|
|
185
|
-
/**
|
|
186
|
-
* 根据过滤返回对应数据
|
|
187
|
-
* @param params
|
|
188
|
-
* @param filters
|
|
189
|
-
*/
|
|
190
|
-
declare const pickByParams: <T extends object>(params: T, filters: any[], deep?: boolean) => Partial<T>;
|
|
191
|
-
/**
|
|
192
|
-
* 将 formData 转换为 ojbect
|
|
193
|
-
* @param formData
|
|
194
|
-
*/
|
|
195
|
-
declare const formDataToObject: (formData: FormData) => Record<string, string>;
|
|
196
|
-
/**
|
|
197
|
-
* 将 object 转换为 formData
|
|
198
|
-
* @param object
|
|
199
|
-
*/
|
|
200
|
-
declare const objectToFormData: (object: Record<string, string>) => FormData;
|
|
201
|
-
/**
|
|
202
|
-
* 对象扁平化处理
|
|
203
|
-
* @param object 对象
|
|
204
|
-
* @param deep 深度
|
|
205
|
-
*/
|
|
206
|
-
declare const objectFlat: (object: Record<string, any>, deep?: number) => Record<string, any>;
|
|
207
|
-
/** 空的方法 */
|
|
174
|
+
/**
|
|
175
|
+
* 地址参数计算
|
|
176
|
+
* @param url 传入url
|
|
177
|
+
* @param params 请求参数
|
|
178
|
+
* @returns 拼接url
|
|
179
|
+
*/
|
|
180
|
+
declare const urlParamsAnaly: (url: string, params: Record<string, any>) => string;
|
|
181
|
+
/**
|
|
182
|
+
* 自定义 Promise 等待
|
|
183
|
+
* @param code 等待时间
|
|
184
|
+
*/
|
|
185
|
+
declare const awaitPromise: (ms?: number) => Promise<unknown>;
|
|
186
|
+
/**
|
|
187
|
+
* 生成递进的数组
|
|
188
|
+
* @param start 开始数值
|
|
189
|
+
* @param end 结束数值
|
|
190
|
+
* @returns 递进的数组
|
|
191
|
+
*/
|
|
192
|
+
declare const generateArray: (start: number, end: number) => number[];
|
|
193
|
+
/** 空的方法 */
|
|
208
194
|
declare const noop: () => void;
|
|
195
|
+
/**
|
|
196
|
+
* 获取数据类型
|
|
197
|
+
* @param target 检测对象
|
|
198
|
+
* @returns 返回字符串
|
|
199
|
+
*/
|
|
200
|
+
declare const checkedTypeof: (target: any) => "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | "null" | "regexp";
|
|
201
|
+
/**
|
|
202
|
+
* 不符合预期则弹出警告
|
|
203
|
+
* @param condition
|
|
204
|
+
* @param infos
|
|
205
|
+
*/
|
|
206
|
+
declare const assert: (condition: boolean, ...infos: any[]) => boolean;
|
|
209
207
|
|
|
210
|
-
export { AnalySizeOption, DeepKeyof, DeepPartial, DeepReadonly, DeepReplace, DeepRequired, Key, LooseNumber, Option, PlainObject, UA, analySize, analyUnit, assert, awaitPromise,
|
|
208
|
+
export { AnalySizeOption, DeepKeyof, DeepPartial, DeepReadonly, DeepReplace, DeepRequired, Key, LooseNumber, Option, PlainObject, UA, analySize, analyUnit, assert, awaitPromise, capitalizeCamelCase, checkedTypeof, colourBlend, formDataToObject, formatClearHtml, formatCoverPhone, formatInteger, formatPrice, formatThousandBitSeparator, formatUnix, fuseThemeColor, generateArray, hexToRgba, isAndroid, isBrowser, isChrome, isEdge, isFF, isFormData, isIE, isIE11, isIE9, isIOS, isMobile, isPhantomJS, isWeex, isWindow, noop, objectFlat, objectToFormData, pickByParams, prefixZero, urlParamsAnaly, weexPlatform };
|
package/index.esm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import dayjs from 'dayjs';
|
|
2
|
-
import { camelCase,
|
|
2
|
+
import { camelCase, isObject, forIn, pickBy, isPlainObject, isString, isNumber } from 'lodash';
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const colourBlend = (colorOne, colorTwo, ratio) => {
|
|
5
5
|
ratio = Math.max(Math.min(Number(ratio), 1), 0);
|
|
6
6
|
const r1 = parseInt(colorOne.slice(1, 3), 16);
|
|
7
7
|
const g1 = parseInt(colorOne.slice(3, 5), 16);
|
|
@@ -27,18 +27,18 @@ const hexToRgba = (hex, opacity) => {
|
|
|
27
27
|
};
|
|
28
28
|
};
|
|
29
29
|
const fuseThemeColor = (color) => ({
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
30
|
+
"light-2": colourBlend("#ffffff", color, 0.8),
|
|
31
|
+
"light-4": colourBlend("#ffffff", color, 0.6),
|
|
32
|
+
"light-6": colourBlend("#ffffff", color, 0.4),
|
|
33
|
+
"light-8": colourBlend("#ffffff", color, 0.2),
|
|
34
|
+
"dark-2": colourBlend("#000000", color, 0.8),
|
|
35
|
+
"dark-4": colourBlend("#000000", color, 0.6),
|
|
36
|
+
"dark-6": colourBlend("#000000", color, 0.4),
|
|
37
|
+
"dark-8": colourBlend("#000000", color, 0.2),
|
|
38
|
+
"opacity-2": hexToRgba(color, 0.8).rgba,
|
|
39
|
+
"opacity-4": hexToRgba(color, 0.6).rgba,
|
|
40
|
+
"opacity-6": hexToRgba(color, 0.4).rgba,
|
|
41
|
+
"opacity-8": hexToRgba(color, 0.2).rgba
|
|
42
42
|
});
|
|
43
43
|
|
|
44
44
|
const formatClearHtml = (string_) => string_.replace(/<[!/]*[^<>]*>/gi, "");
|
|
@@ -86,49 +86,18 @@ const isChrome = UA && /chrome\/\d+/.test(UA) && !isEdge;
|
|
|
86
86
|
const isPhantomJS = UA && /phantomjs/.test(UA);
|
|
87
87
|
const isFF = typeof UA == "string" && UA.match(/firefox\/(\d+)/);
|
|
88
88
|
const isMobile = isBrowser && navigator.userAgent.toLowerCase().includes("mobile");
|
|
89
|
-
|
|
90
|
-
const analyUnit = (size, unit = "px") => {
|
|
91
|
-
return isString(size) && /\D/g.test(size) ? size : size + unit;
|
|
92
|
-
};
|
|
93
|
-
const analySize = (size, unit) => {
|
|
94
|
-
if (typeof size === "string" || typeof size === "number") {
|
|
95
|
-
return { width: analyUnit(size, unit), height: analyUnit(size, unit) };
|
|
96
|
-
}
|
|
97
|
-
if (Array.isArray(size)) {
|
|
98
|
-
return { width: analyUnit(size[0], unit), height: analyUnit(size[1], unit) };
|
|
99
|
-
}
|
|
100
|
-
if (typeof size === "object") {
|
|
101
|
-
return { width: analyUnit(size.width, unit), height: analyUnit(size.height, unit) };
|
|
102
|
-
}
|
|
103
|
-
return { width: "", height: "" };
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
const checkedTypeof = (target) => {
|
|
107
|
-
return Object.prototype.toString.call(target).slice(8, -1);
|
|
108
|
-
};
|
|
109
|
-
const assert = (condition, ...infos) => {
|
|
110
|
-
if (!condition)
|
|
111
|
-
console.warn(...infos);
|
|
112
|
-
return condition;
|
|
113
|
-
};
|
|
114
|
-
const isClient = typeof window !== "undefined";
|
|
115
89
|
const isFormData = (value) => isObject(value) && value instanceof FormData;
|
|
116
90
|
const isWindow = (value) => typeof window !== "undefined" && toString.call(value) === "[object Window]";
|
|
117
91
|
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
if (queryString.length > 0)
|
|
121
|
-
url += "?" + queryString.join("&");
|
|
122
|
-
return url;
|
|
123
|
-
};
|
|
124
|
-
const awaitPromise = (code = 1e3) => {
|
|
125
|
-
return new Promise((resolve) => setTimeout(resolve, code));
|
|
92
|
+
const formDataToObject = (formData) => {
|
|
93
|
+
return Object.fromEntries(formData.entries());
|
|
126
94
|
};
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
95
|
+
const objectToFormData = (object) => {
|
|
96
|
+
const formData = new FormData();
|
|
97
|
+
for (const [key, value] of Object.entries(object)) {
|
|
98
|
+
formData.append(key, String(value));
|
|
99
|
+
}
|
|
100
|
+
return formData;
|
|
132
101
|
};
|
|
133
102
|
const pickByParams = (params, filters, deep = false) => {
|
|
134
103
|
deep && forIn(params, (value, key) => {
|
|
@@ -141,16 +110,6 @@ const pickByParams = (params, filters, deep = false) => {
|
|
|
141
110
|
}
|
|
142
111
|
return pickValue;
|
|
143
112
|
};
|
|
144
|
-
const formDataToObject = (formData) => {
|
|
145
|
-
return Object.fromEntries(formData.entries());
|
|
146
|
-
};
|
|
147
|
-
const objectToFormData = (object) => {
|
|
148
|
-
const formData = new FormData();
|
|
149
|
-
for (const [key, value] of Object.entries(object)) {
|
|
150
|
-
formData.append(key, value);
|
|
151
|
-
}
|
|
152
|
-
return formData;
|
|
153
|
-
};
|
|
154
113
|
const objectFlat = (object, deep = 1) => {
|
|
155
114
|
const flatDeep = (object2, deep2 = 1) => {
|
|
156
115
|
let _object = {};
|
|
@@ -165,7 +124,51 @@ const objectFlat = (object, deep = 1) => {
|
|
|
165
124
|
};
|
|
166
125
|
return flatDeep(object, deep);
|
|
167
126
|
};
|
|
127
|
+
|
|
128
|
+
const analyUnit = (value, unit = "px") => {
|
|
129
|
+
const empty = !(isString(value) || isNumber(value));
|
|
130
|
+
if (empty)
|
|
131
|
+
return "";
|
|
132
|
+
return isString(value) && /\D/g.test(value) ? value : value + unit;
|
|
133
|
+
};
|
|
134
|
+
const analySize = (size, unit) => {
|
|
135
|
+
if (typeof size === "string" || typeof size === "number") {
|
|
136
|
+
return { width: analyUnit(size, unit), height: analyUnit(size, unit) };
|
|
137
|
+
}
|
|
138
|
+
if (Array.isArray(size)) {
|
|
139
|
+
return { width: analyUnit(size[0], unit), height: analyUnit(size[1], unit) };
|
|
140
|
+
}
|
|
141
|
+
if (typeof size === "object") {
|
|
142
|
+
return { width: analyUnit(size.width, unit), height: analyUnit(size.height, unit) };
|
|
143
|
+
}
|
|
144
|
+
return { width: "", height: "" };
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const urlParamsAnaly = (url, params) => {
|
|
148
|
+
const queryString = Object.keys(params).map((key) => `${key}=${params[key]}`);
|
|
149
|
+
if (queryString.length > 0)
|
|
150
|
+
url += "?" + queryString.join("&");
|
|
151
|
+
return url;
|
|
152
|
+
};
|
|
153
|
+
const awaitPromise = (ms = 1e3) => {
|
|
154
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
155
|
+
};
|
|
156
|
+
const generateArray = (start, end) => {
|
|
157
|
+
start = Number(start);
|
|
158
|
+
end = Number(end);
|
|
159
|
+
end = end > start ? end : start;
|
|
160
|
+
return [...new Array(end + 1).keys()].slice(start);
|
|
161
|
+
};
|
|
168
162
|
const noop = () => {
|
|
169
163
|
};
|
|
164
|
+
const checkedTypeof = (target) => {
|
|
165
|
+
const value = Object.prototype.toString.call(target).slice(8, -1).toLocaleLowerCase();
|
|
166
|
+
return value;
|
|
167
|
+
};
|
|
168
|
+
const assert = (condition, ...infos) => {
|
|
169
|
+
if (!condition)
|
|
170
|
+
console.warn(...infos);
|
|
171
|
+
return condition;
|
|
172
|
+
};
|
|
170
173
|
|
|
171
|
-
export { UA, analySize, analyUnit, assert, awaitPromise,
|
|
174
|
+
export { UA, analySize, analyUnit, assert, awaitPromise, capitalizeCamelCase, checkedTypeof, colourBlend, formDataToObject, formatClearHtml, formatCoverPhone, formatInteger, formatPrice, formatThousandBitSeparator, formatUnix, fuseThemeColor, generateArray, hexToRgba, isAndroid, isBrowser, isChrome, isEdge, isFF, isFormData, isIE, isIE11, isIE9, isIOS, isMobile, isPhantomJS, isWeex, isWindow, noop, objectFlat, objectToFormData, pickByParams, prefixZero, urlParamsAnaly, weexPlatform };
|
package/index.iife.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
var dayjs__default = /*#__PURE__*/_interopDefaultLegacy(dayjs);
|
|
7
7
|
|
|
8
|
-
const
|
|
8
|
+
const colourBlend = (colorOne, colorTwo, ratio) => {
|
|
9
9
|
ratio = Math.max(Math.min(Number(ratio), 1), 0);
|
|
10
10
|
const r1 = parseInt(colorOne.slice(1, 3), 16);
|
|
11
11
|
const g1 = parseInt(colorOne.slice(3, 5), 16);
|
|
@@ -31,18 +31,18 @@
|
|
|
31
31
|
};
|
|
32
32
|
};
|
|
33
33
|
const fuseThemeColor = (color) => ({
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
34
|
+
"light-2": colourBlend("#ffffff", color, 0.8),
|
|
35
|
+
"light-4": colourBlend("#ffffff", color, 0.6),
|
|
36
|
+
"light-6": colourBlend("#ffffff", color, 0.4),
|
|
37
|
+
"light-8": colourBlend("#ffffff", color, 0.2),
|
|
38
|
+
"dark-2": colourBlend("#000000", color, 0.8),
|
|
39
|
+
"dark-4": colourBlend("#000000", color, 0.6),
|
|
40
|
+
"dark-6": colourBlend("#000000", color, 0.4),
|
|
41
|
+
"dark-8": colourBlend("#000000", color, 0.2),
|
|
42
|
+
"opacity-2": hexToRgba(color, 0.8).rgba,
|
|
43
|
+
"opacity-4": hexToRgba(color, 0.6).rgba,
|
|
44
|
+
"opacity-6": hexToRgba(color, 0.4).rgba,
|
|
45
|
+
"opacity-8": hexToRgba(color, 0.2).rgba
|
|
46
46
|
});
|
|
47
47
|
|
|
48
48
|
const formatClearHtml = (string_) => string_.replace(/<[!/]*[^<>]*>/gi, "");
|
|
@@ -90,49 +90,18 @@
|
|
|
90
90
|
const isPhantomJS = UA && /phantomjs/.test(UA);
|
|
91
91
|
const isFF = typeof UA == "string" && UA.match(/firefox\/(\d+)/);
|
|
92
92
|
const isMobile = isBrowser && navigator.userAgent.toLowerCase().includes("mobile");
|
|
93
|
-
|
|
94
|
-
const analyUnit = (size, unit = "px") => {
|
|
95
|
-
return lodash.isString(size) && /\D/g.test(size) ? size : size + unit;
|
|
96
|
-
};
|
|
97
|
-
const analySize = (size, unit) => {
|
|
98
|
-
if (typeof size === "string" || typeof size === "number") {
|
|
99
|
-
return { width: analyUnit(size, unit), height: analyUnit(size, unit) };
|
|
100
|
-
}
|
|
101
|
-
if (Array.isArray(size)) {
|
|
102
|
-
return { width: analyUnit(size[0], unit), height: analyUnit(size[1], unit) };
|
|
103
|
-
}
|
|
104
|
-
if (typeof size === "object") {
|
|
105
|
-
return { width: analyUnit(size.width, unit), height: analyUnit(size.height, unit) };
|
|
106
|
-
}
|
|
107
|
-
return { width: "", height: "" };
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
const checkedTypeof = (target) => {
|
|
111
|
-
return Object.prototype.toString.call(target).slice(8, -1);
|
|
112
|
-
};
|
|
113
|
-
const assert = (condition, ...infos) => {
|
|
114
|
-
if (!condition)
|
|
115
|
-
console.warn(...infos);
|
|
116
|
-
return condition;
|
|
117
|
-
};
|
|
118
|
-
const isClient = typeof window !== "undefined";
|
|
119
93
|
const isFormData = (value) => lodash.isObject(value) && value instanceof FormData;
|
|
120
94
|
const isWindow = (value) => typeof window !== "undefined" && toString.call(value) === "[object Window]";
|
|
121
95
|
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
if (queryString.length > 0)
|
|
125
|
-
url += "?" + queryString.join("&");
|
|
126
|
-
return url;
|
|
127
|
-
};
|
|
128
|
-
const awaitPromise = (code = 1e3) => {
|
|
129
|
-
return new Promise((resolve) => setTimeout(resolve, code));
|
|
96
|
+
const formDataToObject = (formData) => {
|
|
97
|
+
return Object.fromEntries(formData.entries());
|
|
130
98
|
};
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
99
|
+
const objectToFormData = (object) => {
|
|
100
|
+
const formData = new FormData();
|
|
101
|
+
for (const [key, value] of Object.entries(object)) {
|
|
102
|
+
formData.append(key, String(value));
|
|
103
|
+
}
|
|
104
|
+
return formData;
|
|
136
105
|
};
|
|
137
106
|
const pickByParams = (params, filters, deep = false) => {
|
|
138
107
|
deep && lodash.forIn(params, (value, key) => {
|
|
@@ -145,16 +114,6 @@
|
|
|
145
114
|
}
|
|
146
115
|
return pickValue;
|
|
147
116
|
};
|
|
148
|
-
const formDataToObject = (formData) => {
|
|
149
|
-
return Object.fromEntries(formData.entries());
|
|
150
|
-
};
|
|
151
|
-
const objectToFormData = (object) => {
|
|
152
|
-
const formData = new FormData();
|
|
153
|
-
for (const [key, value] of Object.entries(object)) {
|
|
154
|
-
formData.append(key, value);
|
|
155
|
-
}
|
|
156
|
-
return formData;
|
|
157
|
-
};
|
|
158
117
|
const objectFlat = (object, deep = 1) => {
|
|
159
118
|
const flatDeep = (object2, deep2 = 1) => {
|
|
160
119
|
let _object = {};
|
|
@@ -169,17 +128,61 @@
|
|
|
169
128
|
};
|
|
170
129
|
return flatDeep(object, deep);
|
|
171
130
|
};
|
|
131
|
+
|
|
132
|
+
const analyUnit = (value, unit = "px") => {
|
|
133
|
+
const empty = !(lodash.isString(value) || lodash.isNumber(value));
|
|
134
|
+
if (empty)
|
|
135
|
+
return "";
|
|
136
|
+
return lodash.isString(value) && /\D/g.test(value) ? value : value + unit;
|
|
137
|
+
};
|
|
138
|
+
const analySize = (size, unit) => {
|
|
139
|
+
if (typeof size === "string" || typeof size === "number") {
|
|
140
|
+
return { width: analyUnit(size, unit), height: analyUnit(size, unit) };
|
|
141
|
+
}
|
|
142
|
+
if (Array.isArray(size)) {
|
|
143
|
+
return { width: analyUnit(size[0], unit), height: analyUnit(size[1], unit) };
|
|
144
|
+
}
|
|
145
|
+
if (typeof size === "object") {
|
|
146
|
+
return { width: analyUnit(size.width, unit), height: analyUnit(size.height, unit) };
|
|
147
|
+
}
|
|
148
|
+
return { width: "", height: "" };
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
const urlParamsAnaly = (url, params) => {
|
|
152
|
+
const queryString = Object.keys(params).map((key) => `${key}=${params[key]}`);
|
|
153
|
+
if (queryString.length > 0)
|
|
154
|
+
url += "?" + queryString.join("&");
|
|
155
|
+
return url;
|
|
156
|
+
};
|
|
157
|
+
const awaitPromise = (ms = 1e3) => {
|
|
158
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
159
|
+
};
|
|
160
|
+
const generateArray = (start, end) => {
|
|
161
|
+
start = Number(start);
|
|
162
|
+
end = Number(end);
|
|
163
|
+
end = end > start ? end : start;
|
|
164
|
+
return [...new Array(end + 1).keys()].slice(start);
|
|
165
|
+
};
|
|
172
166
|
const noop = () => {
|
|
173
167
|
};
|
|
168
|
+
const checkedTypeof = (target) => {
|
|
169
|
+
const value = Object.prototype.toString.call(target).slice(8, -1).toLocaleLowerCase();
|
|
170
|
+
return value;
|
|
171
|
+
};
|
|
172
|
+
const assert = (condition, ...infos) => {
|
|
173
|
+
if (!condition)
|
|
174
|
+
console.warn(...infos);
|
|
175
|
+
return condition;
|
|
176
|
+
};
|
|
174
177
|
|
|
175
178
|
exports.UA = UA;
|
|
176
179
|
exports.analySize = analySize;
|
|
177
180
|
exports.analyUnit = analyUnit;
|
|
178
181
|
exports.assert = assert;
|
|
179
182
|
exports.awaitPromise = awaitPromise;
|
|
180
|
-
exports.blendColor = blendColor;
|
|
181
183
|
exports.capitalizeCamelCase = capitalizeCamelCase;
|
|
182
184
|
exports.checkedTypeof = checkedTypeof;
|
|
185
|
+
exports.colourBlend = colourBlend;
|
|
183
186
|
exports.formDataToObject = formDataToObject;
|
|
184
187
|
exports.formatClearHtml = formatClearHtml;
|
|
185
188
|
exports.formatCoverPhone = formatCoverPhone;
|
|
@@ -193,7 +196,6 @@
|
|
|
193
196
|
exports.isAndroid = isAndroid;
|
|
194
197
|
exports.isBrowser = isBrowser;
|
|
195
198
|
exports.isChrome = isChrome;
|
|
196
|
-
exports.isClient = isClient;
|
|
197
199
|
exports.isEdge = isEdge;
|
|
198
200
|
exports.isFF = isFF;
|
|
199
201
|
exports.isFormData = isFormData;
|
package/index.iife.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,r
|
|
1
|
+
!function(e,t,r){"use strict";function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=i(t);const n=(e,t,r)=>{r=Math.max(Math.min(Number(r),1),0);const i=parseInt(e.slice(1,3),16),a=parseInt(e.slice(3,5),16),n=parseInt(e.slice(5,7),16),o=parseInt(t.slice(1,3),16),s=parseInt(t.slice(3,5),16),c=parseInt(t.slice(5,7),16);let l=Math.round(i*(1-r)+o*r),f=Math.round(a*(1-r)+s*r),d=Math.round(n*(1-r)+c*r);return l=("0"+(l||0).toString(16)).slice(-2),f=("0"+(f||0).toString(16)).slice(-2),d=("0"+(d||0).toString(16)).slice(-2),"#"+l+f+d},o=(e,t)=>{const r="rgba("+parseInt("0x"+e.slice(1,3))+","+parseInt("0x"+e.slice(3,5))+","+parseInt("0x"+e.slice(5,7))+","+t+")";return{red:parseInt("0x"+e.slice(1,3)),green:parseInt("0x"+e.slice(3,5)),blue:parseInt("0x"+e.slice(5,7)),rgba:r}},s="undefined"!=typeof window,c="undefined"!=typeof WXEnvironment&&!!WXEnvironment.platform,l=c&&WXEnvironment.platform.toLowerCase(),f=s&&window.navigator.userAgent.toLowerCase(),d=f&&/msie|trident/.test(f),p=f&&f.indexOf("msie 9.0")>0,g=s&&navigator.userAgent.includes("Trident")&&navigator.userAgent.includes("rv:11.0"),m=f&&f.indexOf("edge/")>0,u=f&&f.indexOf("android")>0||"android"===l,h=f&&/iphone|ipad|ipod|ios/.test(f)||"ios"===l,y=f&&/chrome\/\d+/.test(f)&&!m,b=f&&/phantomjs/.test(f),w="string"==typeof f&&f.match(/firefox\/(\d+)/),j=s&&navigator.userAgent.toLowerCase().includes("mobile"),x=(e,t,i=!1)=>{i&&r.forIn(e,((a,n)=>{r.isObject(a)&&(e[n]=x(e[n],t,i))}));const a=r.pickBy(e,(e=>!t.includes(e)));return Array.isArray(e)?Object.values(a):a},I=(e,t="px")=>!(r.isString(e)||r.isNumber(e))?"":r.isString(e)&&/\D/g.test(e)?e:e+t;e.UA=f,e.analySize=(e,t)=>"string"==typeof e||"number"==typeof e?{width:I(e,t),height:I(e,t)}:Array.isArray(e)?{width:I(e[0],t),height:I(e[1],t)}:"object"==typeof e?{width:I(e.width,t),height:I(e.height,t)}:{width:"",height:""},e.analyUnit=I,e.assert=(e,...t)=>(e||console.warn(...t),e),e.awaitPromise=(e=1e3)=>new Promise((t=>setTimeout(t,e))),e.capitalizeCamelCase=e=>{let t=r.camelCase(e);return t=t.slice(0,1).toLocaleUpperCase()+t.slice(1),t},e.checkedTypeof=e=>Object.prototype.toString.call(e).slice(8,-1).toLocaleLowerCase(),e.colourBlend=n,e.formDataToObject=e=>Object.fromEntries(e.entries()),e.formatClearHtml=e=>e.replace(/<[!/]*[^<>]*>/gi,""),e.formatCoverPhone=e=>e.replace(/^(\d{3})\d{4}(\d{4})$/,"$1****$2"),e.formatInteger=e=>e.replace(/^(0+)|\D+/g,""),e.formatPrice=e=>e.replace(/^[^\d+]/,"").replace(/[^\d,.{|}]/g,"").replace(".","$#$").replace(/\./g,"").replace("$#$",".").replace(/\.{2,}/g,".").replace(/^(-)*(\d+)\.(\d\d).*$/,"$1$2.$3"),e.formatThousandBitSeparator=(e,t=",")=>{if(""===e)return"";const r=String(e).split(".");for(let e=0;e<r.length;e++)r[e]=r[e].replace(new RegExp("(\\d)(?=(\\d{3})+$)","ig"),`$1${t||""}`);return r.join(".")},e.formatUnix=(e,t="YYYY-MM-DD HH:mm:ss")=>a.default.unix(e).format(t),e.fuseThemeColor=e=>({"light-2":n("#ffffff",e,.8),"light-4":n("#ffffff",e,.6),"light-6":n("#ffffff",e,.4),"light-8":n("#ffffff",e,.2),"dark-2":n("#000000",e,.8),"dark-4":n("#000000",e,.6),"dark-6":n("#000000",e,.4),"dark-8":n("#000000",e,.2),"opacity-2":o(e,.8).rgba,"opacity-4":o(e,.6).rgba,"opacity-6":o(e,.4).rgba,"opacity-8":o(e,.2).rgba}),e.generateArray=(e,t)=>(e=Number(e),t=(t=Number(t))>e?t:e,[...new Array(t+1).keys()].slice(e)),e.hexToRgba=o,e.isAndroid=u,e.isBrowser=s,e.isChrome=y,e.isEdge=m,e.isFF=w,e.isFormData=e=>r.isObject(e)&&e instanceof FormData,e.isIE=d,e.isIE11=g,e.isIE9=p,e.isIOS=h,e.isMobile=j,e.isPhantomJS=b,e.isWeex=c,e.isWindow=e=>"undefined"!=typeof window&&"[object Window]"===toString.call(e),e.noop=()=>{},e.objectFlat=(e,t=1)=>{const i=(e,t=1)=>{let a={};for(const[n,o]of Object.entries(e))r.isPlainObject(o)?a={...a,...t>0?i(o,t-1):o}:a[n]=o;return a};return i(e,t)},e.objectToFormData=e=>{const t=new FormData;for(const[r,i]of Object.entries(e))t.append(r,String(i));return t},e.pickByParams=x,e.prefixZero=(e,t=2)=>(new Array(t).join("0")+e).slice(-t),e.urlParamsAnaly=(e,t)=>{const r=Object.keys(t).map((e=>`${e}=${t[e]}`));return r.length>0&&(e+="?"+r.join("&")),e},e.weexPlatform=l,Object.defineProperty(e,"__esModule",{value:!0})}(this.hairyUtils=this.hairyUtils||{},dayjs,_);
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hairy/utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.20",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"dayjs": "^1.10.6",
|
|
7
|
-
"lodash": "^4
|
|
7
|
+
"lodash": "^4"
|
|
8
8
|
},
|
|
9
9
|
"devDependencies": {
|
|
10
|
-
"@types/lodash": "^4
|
|
10
|
+
"@types/lodash": "^4"
|
|
11
11
|
},
|
|
12
12
|
"main": "./index.cjs.js",
|
|
13
13
|
"types": "./index.d.ts",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"./*": "./*"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "5ff534a17318b4e424c9509a0e3459d860a4aac1",
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|
|
37
37
|
}
|