@hairy/utils 1.0.20 → 1.0.21
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/index.cjs.js +33 -123
- package/index.d.ts +113 -200
- package/index.esm.js +27 -101
- package/index.iife.js +34 -123
- package/index.iife.min.js +1 -1
- package/package.json +38 -38
package/index.cjs.js
CHANGED
|
@@ -2,100 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
var lodash = require('lodash');
|
|
7
|
-
|
|
8
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
9
|
-
|
|
10
|
-
var dayjs__default = /*#__PURE__*/_interopDefaultLegacy(dayjs);
|
|
11
|
-
|
|
12
|
-
const colourBlend = (colorOne, colorTwo, ratio) => {
|
|
13
|
-
ratio = Math.max(Math.min(Number(ratio), 1), 0);
|
|
14
|
-
const r1 = parseInt(colorOne.slice(1, 3), 16);
|
|
15
|
-
const g1 = parseInt(colorOne.slice(3, 5), 16);
|
|
16
|
-
const b1 = parseInt(colorOne.slice(5, 7), 16);
|
|
17
|
-
const r2 = parseInt(colorTwo.slice(1, 3), 16);
|
|
18
|
-
const g2 = parseInt(colorTwo.slice(3, 5), 16);
|
|
19
|
-
const b2 = parseInt(colorTwo.slice(5, 7), 16);
|
|
20
|
-
let r = Math.round(r1 * (1 - ratio) + r2 * ratio);
|
|
21
|
-
let g = Math.round(g1 * (1 - ratio) + g2 * ratio);
|
|
22
|
-
let b = Math.round(b1 * (1 - ratio) + b2 * ratio);
|
|
23
|
-
r = ("0" + (r || 0).toString(16)).slice(-2);
|
|
24
|
-
g = ("0" + (g || 0).toString(16)).slice(-2);
|
|
25
|
-
b = ("0" + (b || 0).toString(16)).slice(-2);
|
|
26
|
-
return "#" + r + g + b;
|
|
27
|
-
};
|
|
28
|
-
const hexToRgba = (hex, opacity) => {
|
|
29
|
-
const RGBA = "rgba(" + parseInt("0x" + hex.slice(1, 3)) + "," + parseInt("0x" + hex.slice(3, 5)) + "," + parseInt("0x" + hex.slice(5, 7)) + "," + opacity + ")";
|
|
30
|
-
return {
|
|
31
|
-
red: parseInt("0x" + hex.slice(1, 3)),
|
|
32
|
-
green: parseInt("0x" + hex.slice(3, 5)),
|
|
33
|
-
blue: parseInt("0x" + hex.slice(5, 7)),
|
|
34
|
-
rgba: RGBA
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
const fuseThemeColor = (color) => ({
|
|
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
|
-
});
|
|
51
|
-
|
|
52
|
-
const formatClearHtml = (string_) => string_.replace(/<[!/]*[^<>]*>/gi, "");
|
|
53
|
-
const formatPrice = (value) => {
|
|
54
|
-
return value.replace(/^[^\d+]/, "").replace(/[^\d,.{|}]/g, "").replace(".", "$#$").replace(/\./g, "").replace("$#$", ".").replace(/\.{2,}/g, ".").replace(/^(-)*(\d+)\.(\d\d).*$/, "$1$2.$3");
|
|
55
|
-
};
|
|
56
|
-
const formatInteger = (value) => {
|
|
57
|
-
return value.replace(/^(0+)|\D+/g, "");
|
|
58
|
-
};
|
|
59
|
-
const formatThousandBitSeparator = (target, unit = ",") => {
|
|
60
|
-
if (target === "")
|
|
61
|
-
return "";
|
|
62
|
-
const part = String(target).split(".");
|
|
63
|
-
for (let index = 0; index < part.length; index++) {
|
|
64
|
-
part[index] = part[index].replace(new RegExp("(\\d)(?=(\\d{3})+$)", "ig"), `$1${unit || ""}`);
|
|
65
|
-
}
|
|
66
|
-
return part.join(".");
|
|
67
|
-
};
|
|
68
|
-
const formatUnix = (timestamp, format = "YYYY-MM-DD HH:mm:ss") => {
|
|
69
|
-
return dayjs__default["default"].unix(timestamp).format(format);
|
|
70
|
-
};
|
|
71
|
-
const formatCoverPhone = (phone) => {
|
|
72
|
-
return phone.replace(/^(\d{3})\d{4}(\d{4})$/, "$1****$2");
|
|
73
|
-
};
|
|
74
|
-
const prefixZero = (number_, lh = 2) => {
|
|
75
|
-
return (new Array(lh).join("0") + number_).slice(-lh);
|
|
76
|
-
};
|
|
77
|
-
const capitalizeCamelCase = (string_) => {
|
|
78
|
-
let result = lodash.camelCase(string_);
|
|
79
|
-
result = result.slice(0, 1).toLocaleUpperCase() + result.slice(1);
|
|
80
|
-
return result;
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const isBrowser = typeof window !== "undefined";
|
|
84
|
-
const isWeex = typeof WXEnvironment !== "undefined" && !!WXEnvironment.platform;
|
|
85
|
-
const weexPlatform = isWeex && WXEnvironment.platform.toLowerCase();
|
|
86
|
-
const UA = isBrowser && window.navigator.userAgent.toLowerCase();
|
|
87
|
-
const isIE = UA && /msie|trident/.test(UA);
|
|
88
|
-
const isIE9 = UA && UA.indexOf("msie 9.0") > 0;
|
|
89
|
-
const isIE11 = isBrowser && navigator.userAgent.includes("Trident") && navigator.userAgent.includes("rv:11.0");
|
|
90
|
-
const isEdge = UA && UA.indexOf("edge/") > 0;
|
|
91
|
-
const isAndroid = UA && UA.indexOf("android") > 0 || weexPlatform === "android";
|
|
92
|
-
const isIOS = UA && /iphone|ipad|ipod|ios/.test(UA) || weexPlatform === "ios";
|
|
93
|
-
const isChrome = UA && /chrome\/\d+/.test(UA) && !isEdge;
|
|
94
|
-
const isPhantomJS = UA && /phantomjs/.test(UA);
|
|
95
|
-
const isFF = typeof UA == "string" && UA.match(/firefox\/(\d+)/);
|
|
96
|
-
const isMobile = isBrowser && navigator.userAgent.toLowerCase().includes("mobile");
|
|
97
|
-
const isFormData = (value) => lodash.isObject(value) && value instanceof FormData;
|
|
98
|
-
const isWindow = (value) => typeof window !== "undefined" && toString.call(value) === "[object Window]";
|
|
5
|
+
var lodashEs = require('lodash-es');
|
|
99
6
|
|
|
100
7
|
const formDataToObject = (formData) => {
|
|
101
8
|
return Object.fromEntries(formData.entries());
|
|
@@ -107,12 +14,12 @@ const objectToFormData = (object) => {
|
|
|
107
14
|
}
|
|
108
15
|
return formData;
|
|
109
16
|
};
|
|
110
|
-
const pickByParams = (params,
|
|
111
|
-
deep &&
|
|
112
|
-
if (
|
|
113
|
-
params[key] = pickByParams(params[key],
|
|
17
|
+
const pickByParams = (params, filter, deep = false) => {
|
|
18
|
+
deep && lodashEs.forIn(params, (value, key) => {
|
|
19
|
+
if (lodashEs.isObject(value))
|
|
20
|
+
params[key] = pickByParams(params[key], filter, deep);
|
|
114
21
|
});
|
|
115
|
-
const pickValue =
|
|
22
|
+
const pickValue = lodashEs.pickBy(params, (value) => !filter.includes(value));
|
|
116
23
|
if (Array.isArray(params)) {
|
|
117
24
|
return Object.values(pickValue);
|
|
118
25
|
}
|
|
@@ -122,7 +29,7 @@ const objectFlat = (object, deep = 1) => {
|
|
|
122
29
|
const flatDeep = (object2, deep2 = 1) => {
|
|
123
30
|
let _object = {};
|
|
124
31
|
for (const [key, value] of Object.entries(object2)) {
|
|
125
|
-
if (
|
|
32
|
+
if (lodashEs.isPlainObject(value)) {
|
|
126
33
|
_object = { ..._object, ...deep2 > 0 ? flatDeep(value, deep2 - 1) : value };
|
|
127
34
|
continue;
|
|
128
35
|
}
|
|
@@ -133,21 +40,21 @@ const objectFlat = (object, deep = 1) => {
|
|
|
133
40
|
return flatDeep(object, deep);
|
|
134
41
|
};
|
|
135
42
|
|
|
136
|
-
const
|
|
137
|
-
const empty = !(
|
|
43
|
+
const toUnit = (value, unit = "px") => {
|
|
44
|
+
const empty = !(lodashEs.isString(value) || lodashEs.isNumber(value));
|
|
138
45
|
if (empty)
|
|
139
46
|
return "";
|
|
140
|
-
return
|
|
47
|
+
return lodashEs.isString(value) && /\D/g.test(value) ? value : value + unit;
|
|
141
48
|
};
|
|
142
|
-
const
|
|
49
|
+
const toSize = (size, unit) => {
|
|
143
50
|
if (typeof size === "string" || typeof size === "number") {
|
|
144
|
-
return { width:
|
|
51
|
+
return { width: toUnit(size, unit), height: toUnit(size, unit) };
|
|
145
52
|
}
|
|
146
53
|
if (Array.isArray(size)) {
|
|
147
|
-
return { width:
|
|
54
|
+
return { width: toUnit(size[0], unit), height: toUnit(size[1], unit) };
|
|
148
55
|
}
|
|
149
56
|
if (typeof size === "object") {
|
|
150
|
-
return { width:
|
|
57
|
+
return { width: toUnit(size.width, unit), height: toUnit(size.height, unit) };
|
|
151
58
|
}
|
|
152
59
|
return { width: "", height: "" };
|
|
153
60
|
};
|
|
@@ -167,8 +74,6 @@ const generateArray = (start, end) => {
|
|
|
167
74
|
end = end > start ? end : start;
|
|
168
75
|
return [...new Array(end + 1).keys()].slice(start);
|
|
169
76
|
};
|
|
170
|
-
const noop = () => {
|
|
171
|
-
};
|
|
172
77
|
const checkedTypeof = (target) => {
|
|
173
78
|
const value = Object.prototype.toString.call(target).slice(8, -1).toLocaleLowerCase();
|
|
174
79
|
return value;
|
|
@@ -179,24 +84,29 @@ const assert = (condition, ...infos) => {
|
|
|
179
84
|
return condition;
|
|
180
85
|
};
|
|
181
86
|
|
|
87
|
+
const isBrowser = typeof window !== "undefined";
|
|
88
|
+
const isWeex = typeof WXEnvironment !== "undefined" && !!WXEnvironment.platform;
|
|
89
|
+
const weexPlatform = isWeex && WXEnvironment.platform.toLowerCase();
|
|
90
|
+
const UA = isBrowser && window.navigator.userAgent.toLowerCase();
|
|
91
|
+
const isIE = UA && /msie|trident/.test(UA);
|
|
92
|
+
const isIE9 = UA && UA.indexOf("msie 9.0") > 0;
|
|
93
|
+
const isIE11 = isBrowser && navigator.userAgent.includes("Trident") && navigator.userAgent.includes("rv:11.0");
|
|
94
|
+
const isEdge = UA && UA.indexOf("edge/") > 0;
|
|
95
|
+
const isAndroid = UA && UA.indexOf("android") > 0 || weexPlatform === "android";
|
|
96
|
+
const isIOS = UA && /iphone|ipad|ipod|ios/.test(UA) || weexPlatform === "ios";
|
|
97
|
+
const isChrome = UA && /chrome\/\d+/.test(UA) && !isEdge;
|
|
98
|
+
const isPhantomJS = UA && /phantomjs/.test(UA);
|
|
99
|
+
const isFF = typeof UA == "string" && UA.match(/firefox\/(\d+)/);
|
|
100
|
+
const isMobile = isBrowser && navigator.userAgent.toLowerCase().includes("mobile");
|
|
101
|
+
const isFormData = (value) => lodashEs.isObject(value) && value instanceof FormData;
|
|
102
|
+
const isWindow = (value) => typeof window !== "undefined" && toString.call(value) === "[object Window]";
|
|
103
|
+
|
|
182
104
|
exports.UA = UA;
|
|
183
|
-
exports.analySize = analySize;
|
|
184
|
-
exports.analyUnit = analyUnit;
|
|
185
105
|
exports.assert = assert;
|
|
186
106
|
exports.awaitPromise = awaitPromise;
|
|
187
|
-
exports.capitalizeCamelCase = capitalizeCamelCase;
|
|
188
107
|
exports.checkedTypeof = checkedTypeof;
|
|
189
|
-
exports.colourBlend = colourBlend;
|
|
190
108
|
exports.formDataToObject = formDataToObject;
|
|
191
|
-
exports.formatClearHtml = formatClearHtml;
|
|
192
|
-
exports.formatCoverPhone = formatCoverPhone;
|
|
193
|
-
exports.formatInteger = formatInteger;
|
|
194
|
-
exports.formatPrice = formatPrice;
|
|
195
|
-
exports.formatThousandBitSeparator = formatThousandBitSeparator;
|
|
196
|
-
exports.formatUnix = formatUnix;
|
|
197
|
-
exports.fuseThemeColor = fuseThemeColor;
|
|
198
109
|
exports.generateArray = generateArray;
|
|
199
|
-
exports.hexToRgba = hexToRgba;
|
|
200
110
|
exports.isAndroid = isAndroid;
|
|
201
111
|
exports.isBrowser = isBrowser;
|
|
202
112
|
exports.isChrome = isChrome;
|
|
@@ -211,10 +121,10 @@ exports.isMobile = isMobile;
|
|
|
211
121
|
exports.isPhantomJS = isPhantomJS;
|
|
212
122
|
exports.isWeex = isWeex;
|
|
213
123
|
exports.isWindow = isWindow;
|
|
214
|
-
exports.noop = noop;
|
|
215
124
|
exports.objectFlat = objectFlat;
|
|
216
125
|
exports.objectToFormData = objectToFormData;
|
|
217
126
|
exports.pickByParams = pickByParams;
|
|
218
|
-
exports.
|
|
127
|
+
exports.toSize = toSize;
|
|
128
|
+
exports.toUnit = toUnit;
|
|
219
129
|
exports.urlParamsAnaly = urlParamsAnaly;
|
|
220
130
|
exports.weexPlatform = weexPlatform;
|
package/index.d.ts
CHANGED
|
@@ -1,208 +1,121 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @param
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
*
|
|
13
|
-
* @
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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;
|
|
38
|
-
};
|
|
39
|
-
|
|
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
|
-
*/
|
|
84
|
-
declare const capitalizeCamelCase: (string_: string) => string;
|
|
85
|
-
|
|
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;
|
|
99
|
-
declare const isMobile: boolean;
|
|
100
|
-
declare const isFormData: (value: any) => value is FormData;
|
|
101
|
-
declare const isWindow: (value: any) => value is Window;
|
|
102
|
-
|
|
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
|
-
*/
|
|
1
|
+
/**
|
|
2
|
+
* 将 formData 转换为 object
|
|
3
|
+
* @param formData
|
|
4
|
+
*/
|
|
5
|
+
declare const formDataToObject: (formData: FormData) => Record<string, string>;
|
|
6
|
+
/**
|
|
7
|
+
* 将 object 转换为 formData
|
|
8
|
+
* @param object
|
|
9
|
+
*/
|
|
10
|
+
declare const objectToFormData: (object: Record<string, string | number>) => FormData;
|
|
11
|
+
/**
|
|
12
|
+
* 过滤对象|数组中 filter 中的值
|
|
13
|
+
* @param params
|
|
14
|
+
* @param filter
|
|
15
|
+
*/
|
|
16
|
+
declare const pickByParams: <T extends object>(params: T, filter: any[], deep?: boolean) => Partial<T>;
|
|
17
|
+
/**
|
|
18
|
+
* 对象扁平化处理
|
|
19
|
+
* @param object 对象
|
|
20
|
+
* @param deep 深度
|
|
21
|
+
*/
|
|
124
22
|
declare const objectFlat: (object: Record<string, any>, deep?: number) => Record<string, any>;
|
|
125
23
|
|
|
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>[];
|
|
24
|
+
declare type PlainObject = {
|
|
25
|
+
[key: string]: any;
|
|
26
|
+
};
|
|
27
|
+
declare type LooseNumber = string | number;
|
|
28
|
+
declare type Key = string | number | symbol;
|
|
29
|
+
declare type DeepReadonly<T> = {
|
|
30
|
+
readonly [P in keyof T]: T[P] extends object ? DeepReadonly<T[P]> : T[P];
|
|
31
|
+
};
|
|
32
|
+
declare type DeepRequired<T> = {
|
|
33
|
+
[P in keyof T]-?: T[P] extends object ? DeepRequired<T[P]> : T[P];
|
|
34
|
+
};
|
|
35
|
+
declare type DeepPartial<T> = {
|
|
36
|
+
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
37
|
+
};
|
|
38
|
+
declare type DeepKeyof<T> = T extends object ? keyof T | DeepKeyof<T[keyof T]> : never;
|
|
39
|
+
declare type DeepReplace<T, K = unknown, V = unknown> = {
|
|
40
|
+
[P in keyof T]: K extends P ? V : DeepReplace<T[P], K, V>;
|
|
41
|
+
};
|
|
42
|
+
declare type Option<L extends Key = 'label', V extends Key = 'value', C extends Key = 'children'> = {
|
|
43
|
+
[P in L]?: string;
|
|
44
|
+
} & {
|
|
45
|
+
[P in V]?: LooseNumber;
|
|
46
|
+
} & {
|
|
47
|
+
[P in C]?: Option<L, V, C>[];
|
|
150
48
|
};
|
|
151
49
|
|
|
152
|
-
/**
|
|
153
|
-
* 如果有单位,如百分比,px单位等,直接返回,如果是纯粹的数值,则加上px单位
|
|
154
|
-
* @param
|
|
155
|
-
* @param unit
|
|
156
|
-
* @returns string
|
|
157
|
-
*/
|
|
158
|
-
declare const
|
|
159
|
-
/** size 转换配置 */
|
|
160
|
-
declare type
|
|
161
|
-
width: LooseNumber;
|
|
162
|
-
height: LooseNumber;
|
|
163
|
-
};
|
|
164
|
-
/**
|
|
165
|
-
* 将 size 转换为宽高
|
|
166
|
-
* @param size {
|
|
167
|
-
* @returns
|
|
168
|
-
*/
|
|
169
|
-
declare const
|
|
170
|
-
width: string;
|
|
171
|
-
height: string;
|
|
50
|
+
/**
|
|
51
|
+
* 如果有单位,如百分比,px单位等,直接返回,如果是纯粹的数值,则加上px单位
|
|
52
|
+
* @param value 尺寸
|
|
53
|
+
* @param unit 单位
|
|
54
|
+
* @returns string
|
|
55
|
+
*/
|
|
56
|
+
declare const toUnit: (value: LooseNumber, unit?: string) => string;
|
|
57
|
+
/** size 转换配置 */
|
|
58
|
+
declare type toSizeOption = LooseNumber | [LooseNumber, LooseNumber] | {
|
|
59
|
+
width: LooseNumber;
|
|
60
|
+
height: LooseNumber;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* 将 size 转换为宽高
|
|
64
|
+
* @param size { toSizeOption }
|
|
65
|
+
* @returns
|
|
66
|
+
*/
|
|
67
|
+
declare const toSize: (size: toSizeOption, unit?: string | undefined) => {
|
|
68
|
+
width: string;
|
|
69
|
+
height: string;
|
|
172
70
|
};
|
|
173
71
|
|
|
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
|
-
/**
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
*
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
*
|
|
203
|
-
|
|
204
|
-
* @param infos
|
|
205
|
-
*/
|
|
72
|
+
/**
|
|
73
|
+
* 地址参数计算
|
|
74
|
+
* @param url 传入url
|
|
75
|
+
* @param params 请求参数
|
|
76
|
+
* @returns 拼接url
|
|
77
|
+
*/
|
|
78
|
+
declare const urlParamsAnaly: (url: string, params: Record<string, any>) => string;
|
|
79
|
+
/**
|
|
80
|
+
* 自定义 Promise 等待
|
|
81
|
+
* @param code 等待时间
|
|
82
|
+
*/
|
|
83
|
+
declare const awaitPromise: (ms?: number) => Promise<unknown>;
|
|
84
|
+
/**
|
|
85
|
+
* 生成递进的数组
|
|
86
|
+
* @param start 开始数值
|
|
87
|
+
* @param end 结束数值
|
|
88
|
+
* @returns 递进的数组
|
|
89
|
+
*/
|
|
90
|
+
declare const generateArray: (start: number, end: number) => number[];
|
|
91
|
+
/**
|
|
92
|
+
* 获取数据类型
|
|
93
|
+
* @param target 检测对象
|
|
94
|
+
* @returns 返回字符串
|
|
95
|
+
*/
|
|
96
|
+
declare const checkedTypeof: (target: any) => "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | "null" | "regexp";
|
|
97
|
+
/**
|
|
98
|
+
* 不符合预期则弹出警告
|
|
99
|
+
* @param condition
|
|
100
|
+
* @param infos
|
|
101
|
+
*/
|
|
206
102
|
declare const assert: (condition: boolean, ...infos: any[]) => boolean;
|
|
207
103
|
|
|
208
|
-
|
|
104
|
+
declare const isBrowser: boolean;
|
|
105
|
+
declare const isWeex: boolean;
|
|
106
|
+
declare const weexPlatform: any;
|
|
107
|
+
declare const UA: string | false;
|
|
108
|
+
declare const isIE: boolean | "";
|
|
109
|
+
declare const isIE9: boolean | "";
|
|
110
|
+
declare const isIE11: boolean;
|
|
111
|
+
declare const isEdge: boolean | "";
|
|
112
|
+
declare const isAndroid: boolean;
|
|
113
|
+
declare const isIOS: boolean;
|
|
114
|
+
declare const isChrome: boolean | "";
|
|
115
|
+
declare const isPhantomJS: boolean | "";
|
|
116
|
+
declare const isFF: false | RegExpMatchArray | null;
|
|
117
|
+
declare const isMobile: boolean;
|
|
118
|
+
declare const isFormData: (value: any) => value is FormData;
|
|
119
|
+
declare const isWindow: (value: any) => value is Window;
|
|
120
|
+
|
|
121
|
+
export { DeepKeyof, DeepPartial, DeepReadonly, DeepReplace, DeepRequired, Key, LooseNumber, Option, PlainObject, UA, assert, awaitPromise, checkedTypeof, formDataToObject, generateArray, isAndroid, isBrowser, isChrome, isEdge, isFF, isFormData, isIE, isIE11, isIE9, isIOS, isMobile, isPhantomJS, isWeex, isWindow, objectFlat, objectToFormData, pickByParams, toSize, toSizeOption, toUnit, urlParamsAnaly, weexPlatform };
|
package/index.esm.js
CHANGED
|
@@ -1,93 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { camelCase, isObject, forIn, pickBy, isPlainObject, isString, isNumber } from 'lodash';
|
|
3
|
-
|
|
4
|
-
const colourBlend = (colorOne, colorTwo, ratio) => {
|
|
5
|
-
ratio = Math.max(Math.min(Number(ratio), 1), 0);
|
|
6
|
-
const r1 = parseInt(colorOne.slice(1, 3), 16);
|
|
7
|
-
const g1 = parseInt(colorOne.slice(3, 5), 16);
|
|
8
|
-
const b1 = parseInt(colorOne.slice(5, 7), 16);
|
|
9
|
-
const r2 = parseInt(colorTwo.slice(1, 3), 16);
|
|
10
|
-
const g2 = parseInt(colorTwo.slice(3, 5), 16);
|
|
11
|
-
const b2 = parseInt(colorTwo.slice(5, 7), 16);
|
|
12
|
-
let r = Math.round(r1 * (1 - ratio) + r2 * ratio);
|
|
13
|
-
let g = Math.round(g1 * (1 - ratio) + g2 * ratio);
|
|
14
|
-
let b = Math.round(b1 * (1 - ratio) + b2 * ratio);
|
|
15
|
-
r = ("0" + (r || 0).toString(16)).slice(-2);
|
|
16
|
-
g = ("0" + (g || 0).toString(16)).slice(-2);
|
|
17
|
-
b = ("0" + (b || 0).toString(16)).slice(-2);
|
|
18
|
-
return "#" + r + g + b;
|
|
19
|
-
};
|
|
20
|
-
const hexToRgba = (hex, opacity) => {
|
|
21
|
-
const RGBA = "rgba(" + parseInt("0x" + hex.slice(1, 3)) + "," + parseInt("0x" + hex.slice(3, 5)) + "," + parseInt("0x" + hex.slice(5, 7)) + "," + opacity + ")";
|
|
22
|
-
return {
|
|
23
|
-
red: parseInt("0x" + hex.slice(1, 3)),
|
|
24
|
-
green: parseInt("0x" + hex.slice(3, 5)),
|
|
25
|
-
blue: parseInt("0x" + hex.slice(5, 7)),
|
|
26
|
-
rgba: RGBA
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
const fuseThemeColor = (color) => ({
|
|
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
|
-
});
|
|
43
|
-
|
|
44
|
-
const formatClearHtml = (string_) => string_.replace(/<[!/]*[^<>]*>/gi, "");
|
|
45
|
-
const formatPrice = (value) => {
|
|
46
|
-
return value.replace(/^[^\d+]/, "").replace(/[^\d,.{|}]/g, "").replace(".", "$#$").replace(/\./g, "").replace("$#$", ".").replace(/\.{2,}/g, ".").replace(/^(-)*(\d+)\.(\d\d).*$/, "$1$2.$3");
|
|
47
|
-
};
|
|
48
|
-
const formatInteger = (value) => {
|
|
49
|
-
return value.replace(/^(0+)|\D+/g, "");
|
|
50
|
-
};
|
|
51
|
-
const formatThousandBitSeparator = (target, unit = ",") => {
|
|
52
|
-
if (target === "")
|
|
53
|
-
return "";
|
|
54
|
-
const part = String(target).split(".");
|
|
55
|
-
for (let index = 0; index < part.length; index++) {
|
|
56
|
-
part[index] = part[index].replace(new RegExp("(\\d)(?=(\\d{3})+$)", "ig"), `$1${unit || ""}`);
|
|
57
|
-
}
|
|
58
|
-
return part.join(".");
|
|
59
|
-
};
|
|
60
|
-
const formatUnix = (timestamp, format = "YYYY-MM-DD HH:mm:ss") => {
|
|
61
|
-
return dayjs.unix(timestamp).format(format);
|
|
62
|
-
};
|
|
63
|
-
const formatCoverPhone = (phone) => {
|
|
64
|
-
return phone.replace(/^(\d{3})\d{4}(\d{4})$/, "$1****$2");
|
|
65
|
-
};
|
|
66
|
-
const prefixZero = (number_, lh = 2) => {
|
|
67
|
-
return (new Array(lh).join("0") + number_).slice(-lh);
|
|
68
|
-
};
|
|
69
|
-
const capitalizeCamelCase = (string_) => {
|
|
70
|
-
let result = camelCase(string_);
|
|
71
|
-
result = result.slice(0, 1).toLocaleUpperCase() + result.slice(1);
|
|
72
|
-
return result;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
const isBrowser = typeof window !== "undefined";
|
|
76
|
-
const isWeex = typeof WXEnvironment !== "undefined" && !!WXEnvironment.platform;
|
|
77
|
-
const weexPlatform = isWeex && WXEnvironment.platform.toLowerCase();
|
|
78
|
-
const UA = isBrowser && window.navigator.userAgent.toLowerCase();
|
|
79
|
-
const isIE = UA && /msie|trident/.test(UA);
|
|
80
|
-
const isIE9 = UA && UA.indexOf("msie 9.0") > 0;
|
|
81
|
-
const isIE11 = isBrowser && navigator.userAgent.includes("Trident") && navigator.userAgent.includes("rv:11.0");
|
|
82
|
-
const isEdge = UA && UA.indexOf("edge/") > 0;
|
|
83
|
-
const isAndroid = UA && UA.indexOf("android") > 0 || weexPlatform === "android";
|
|
84
|
-
const isIOS = UA && /iphone|ipad|ipod|ios/.test(UA) || weexPlatform === "ios";
|
|
85
|
-
const isChrome = UA && /chrome\/\d+/.test(UA) && !isEdge;
|
|
86
|
-
const isPhantomJS = UA && /phantomjs/.test(UA);
|
|
87
|
-
const isFF = typeof UA == "string" && UA.match(/firefox\/(\d+)/);
|
|
88
|
-
const isMobile = isBrowser && navigator.userAgent.toLowerCase().includes("mobile");
|
|
89
|
-
const isFormData = (value) => isObject(value) && value instanceof FormData;
|
|
90
|
-
const isWindow = (value) => typeof window !== "undefined" && toString.call(value) === "[object Window]";
|
|
1
|
+
import { forIn, isObject, pickBy, isPlainObject, isString, isNumber } from 'lodash-es';
|
|
91
2
|
|
|
92
3
|
const formDataToObject = (formData) => {
|
|
93
4
|
return Object.fromEntries(formData.entries());
|
|
@@ -99,12 +10,12 @@ const objectToFormData = (object) => {
|
|
|
99
10
|
}
|
|
100
11
|
return formData;
|
|
101
12
|
};
|
|
102
|
-
const pickByParams = (params,
|
|
13
|
+
const pickByParams = (params, filter, deep = false) => {
|
|
103
14
|
deep && forIn(params, (value, key) => {
|
|
104
15
|
if (isObject(value))
|
|
105
|
-
params[key] = pickByParams(params[key],
|
|
16
|
+
params[key] = pickByParams(params[key], filter, deep);
|
|
106
17
|
});
|
|
107
|
-
const pickValue = pickBy(params, (value) => !
|
|
18
|
+
const pickValue = pickBy(params, (value) => !filter.includes(value));
|
|
108
19
|
if (Array.isArray(params)) {
|
|
109
20
|
return Object.values(pickValue);
|
|
110
21
|
}
|
|
@@ -125,21 +36,21 @@ const objectFlat = (object, deep = 1) => {
|
|
|
125
36
|
return flatDeep(object, deep);
|
|
126
37
|
};
|
|
127
38
|
|
|
128
|
-
const
|
|
39
|
+
const toUnit = (value, unit = "px") => {
|
|
129
40
|
const empty = !(isString(value) || isNumber(value));
|
|
130
41
|
if (empty)
|
|
131
42
|
return "";
|
|
132
43
|
return isString(value) && /\D/g.test(value) ? value : value + unit;
|
|
133
44
|
};
|
|
134
|
-
const
|
|
45
|
+
const toSize = (size, unit) => {
|
|
135
46
|
if (typeof size === "string" || typeof size === "number") {
|
|
136
|
-
return { width:
|
|
47
|
+
return { width: toUnit(size, unit), height: toUnit(size, unit) };
|
|
137
48
|
}
|
|
138
49
|
if (Array.isArray(size)) {
|
|
139
|
-
return { width:
|
|
50
|
+
return { width: toUnit(size[0], unit), height: toUnit(size[1], unit) };
|
|
140
51
|
}
|
|
141
52
|
if (typeof size === "object") {
|
|
142
|
-
return { width:
|
|
53
|
+
return { width: toUnit(size.width, unit), height: toUnit(size.height, unit) };
|
|
143
54
|
}
|
|
144
55
|
return { width: "", height: "" };
|
|
145
56
|
};
|
|
@@ -159,8 +70,6 @@ const generateArray = (start, end) => {
|
|
|
159
70
|
end = end > start ? end : start;
|
|
160
71
|
return [...new Array(end + 1).keys()].slice(start);
|
|
161
72
|
};
|
|
162
|
-
const noop = () => {
|
|
163
|
-
};
|
|
164
73
|
const checkedTypeof = (target) => {
|
|
165
74
|
const value = Object.prototype.toString.call(target).slice(8, -1).toLocaleLowerCase();
|
|
166
75
|
return value;
|
|
@@ -171,4 +80,21 @@ const assert = (condition, ...infos) => {
|
|
|
171
80
|
return condition;
|
|
172
81
|
};
|
|
173
82
|
|
|
174
|
-
|
|
83
|
+
const isBrowser = typeof window !== "undefined";
|
|
84
|
+
const isWeex = typeof WXEnvironment !== "undefined" && !!WXEnvironment.platform;
|
|
85
|
+
const weexPlatform = isWeex && WXEnvironment.platform.toLowerCase();
|
|
86
|
+
const UA = isBrowser && window.navigator.userAgent.toLowerCase();
|
|
87
|
+
const isIE = UA && /msie|trident/.test(UA);
|
|
88
|
+
const isIE9 = UA && UA.indexOf("msie 9.0") > 0;
|
|
89
|
+
const isIE11 = isBrowser && navigator.userAgent.includes("Trident") && navigator.userAgent.includes("rv:11.0");
|
|
90
|
+
const isEdge = UA && UA.indexOf("edge/") > 0;
|
|
91
|
+
const isAndroid = UA && UA.indexOf("android") > 0 || weexPlatform === "android";
|
|
92
|
+
const isIOS = UA && /iphone|ipad|ipod|ios/.test(UA) || weexPlatform === "ios";
|
|
93
|
+
const isChrome = UA && /chrome\/\d+/.test(UA) && !isEdge;
|
|
94
|
+
const isPhantomJS = UA && /phantomjs/.test(UA);
|
|
95
|
+
const isFF = typeof UA == "string" && UA.match(/firefox\/(\d+)/);
|
|
96
|
+
const isMobile = isBrowser && navigator.userAgent.toLowerCase().includes("mobile");
|
|
97
|
+
const isFormData = (value) => isObject(value) && value instanceof FormData;
|
|
98
|
+
const isWindow = (value) => typeof window !== "undefined" && toString.call(value) === "[object Window]";
|
|
99
|
+
|
|
100
|
+
export { UA, assert, awaitPromise, checkedTypeof, formDataToObject, generateArray, isAndroid, isBrowser, isChrome, isEdge, isFF, isFormData, isIE, isIE11, isIE9, isIOS, isMobile, isPhantomJS, isWeex, isWindow, objectFlat, objectToFormData, pickByParams, toSize, toUnit, urlParamsAnaly, weexPlatform };
|
package/index.iife.js
CHANGED
|
@@ -1,98 +1,6 @@
|
|
|
1
|
-
(function (exports,
|
|
1
|
+
(function (exports, lodashEs) {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
5
|
-
|
|
6
|
-
var dayjs__default = /*#__PURE__*/_interopDefaultLegacy(dayjs);
|
|
7
|
-
|
|
8
|
-
const colourBlend = (colorOne, colorTwo, ratio) => {
|
|
9
|
-
ratio = Math.max(Math.min(Number(ratio), 1), 0);
|
|
10
|
-
const r1 = parseInt(colorOne.slice(1, 3), 16);
|
|
11
|
-
const g1 = parseInt(colorOne.slice(3, 5), 16);
|
|
12
|
-
const b1 = parseInt(colorOne.slice(5, 7), 16);
|
|
13
|
-
const r2 = parseInt(colorTwo.slice(1, 3), 16);
|
|
14
|
-
const g2 = parseInt(colorTwo.slice(3, 5), 16);
|
|
15
|
-
const b2 = parseInt(colorTwo.slice(5, 7), 16);
|
|
16
|
-
let r = Math.round(r1 * (1 - ratio) + r2 * ratio);
|
|
17
|
-
let g = Math.round(g1 * (1 - ratio) + g2 * ratio);
|
|
18
|
-
let b = Math.round(b1 * (1 - ratio) + b2 * ratio);
|
|
19
|
-
r = ("0" + (r || 0).toString(16)).slice(-2);
|
|
20
|
-
g = ("0" + (g || 0).toString(16)).slice(-2);
|
|
21
|
-
b = ("0" + (b || 0).toString(16)).slice(-2);
|
|
22
|
-
return "#" + r + g + b;
|
|
23
|
-
};
|
|
24
|
-
const hexToRgba = (hex, opacity) => {
|
|
25
|
-
const RGBA = "rgba(" + parseInt("0x" + hex.slice(1, 3)) + "," + parseInt("0x" + hex.slice(3, 5)) + "," + parseInt("0x" + hex.slice(5, 7)) + "," + opacity + ")";
|
|
26
|
-
return {
|
|
27
|
-
red: parseInt("0x" + hex.slice(1, 3)),
|
|
28
|
-
green: parseInt("0x" + hex.slice(3, 5)),
|
|
29
|
-
blue: parseInt("0x" + hex.slice(5, 7)),
|
|
30
|
-
rgba: RGBA
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
const fuseThemeColor = (color) => ({
|
|
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
|
-
});
|
|
47
|
-
|
|
48
|
-
const formatClearHtml = (string_) => string_.replace(/<[!/]*[^<>]*>/gi, "");
|
|
49
|
-
const formatPrice = (value) => {
|
|
50
|
-
return value.replace(/^[^\d+]/, "").replace(/[^\d,.{|}]/g, "").replace(".", "$#$").replace(/\./g, "").replace("$#$", ".").replace(/\.{2,}/g, ".").replace(/^(-)*(\d+)\.(\d\d).*$/, "$1$2.$3");
|
|
51
|
-
};
|
|
52
|
-
const formatInteger = (value) => {
|
|
53
|
-
return value.replace(/^(0+)|\D+/g, "");
|
|
54
|
-
};
|
|
55
|
-
const formatThousandBitSeparator = (target, unit = ",") => {
|
|
56
|
-
if (target === "")
|
|
57
|
-
return "";
|
|
58
|
-
const part = String(target).split(".");
|
|
59
|
-
for (let index = 0; index < part.length; index++) {
|
|
60
|
-
part[index] = part[index].replace(new RegExp("(\\d)(?=(\\d{3})+$)", "ig"), `$1${unit || ""}`);
|
|
61
|
-
}
|
|
62
|
-
return part.join(".");
|
|
63
|
-
};
|
|
64
|
-
const formatUnix = (timestamp, format = "YYYY-MM-DD HH:mm:ss") => {
|
|
65
|
-
return dayjs__default["default"].unix(timestamp).format(format);
|
|
66
|
-
};
|
|
67
|
-
const formatCoverPhone = (phone) => {
|
|
68
|
-
return phone.replace(/^(\d{3})\d{4}(\d{4})$/, "$1****$2");
|
|
69
|
-
};
|
|
70
|
-
const prefixZero = (number_, lh = 2) => {
|
|
71
|
-
return (new Array(lh).join("0") + number_).slice(-lh);
|
|
72
|
-
};
|
|
73
|
-
const capitalizeCamelCase = (string_) => {
|
|
74
|
-
let result = lodash.camelCase(string_);
|
|
75
|
-
result = result.slice(0, 1).toLocaleUpperCase() + result.slice(1);
|
|
76
|
-
return result;
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
const isBrowser = typeof window !== "undefined";
|
|
80
|
-
const isWeex = typeof WXEnvironment !== "undefined" && !!WXEnvironment.platform;
|
|
81
|
-
const weexPlatform = isWeex && WXEnvironment.platform.toLowerCase();
|
|
82
|
-
const UA = isBrowser && window.navigator.userAgent.toLowerCase();
|
|
83
|
-
const isIE = UA && /msie|trident/.test(UA);
|
|
84
|
-
const isIE9 = UA && UA.indexOf("msie 9.0") > 0;
|
|
85
|
-
const isIE11 = isBrowser && navigator.userAgent.includes("Trident") && navigator.userAgent.includes("rv:11.0");
|
|
86
|
-
const isEdge = UA && UA.indexOf("edge/") > 0;
|
|
87
|
-
const isAndroid = UA && UA.indexOf("android") > 0 || weexPlatform === "android";
|
|
88
|
-
const isIOS = UA && /iphone|ipad|ipod|ios/.test(UA) || weexPlatform === "ios";
|
|
89
|
-
const isChrome = UA && /chrome\/\d+/.test(UA) && !isEdge;
|
|
90
|
-
const isPhantomJS = UA && /phantomjs/.test(UA);
|
|
91
|
-
const isFF = typeof UA == "string" && UA.match(/firefox\/(\d+)/);
|
|
92
|
-
const isMobile = isBrowser && navigator.userAgent.toLowerCase().includes("mobile");
|
|
93
|
-
const isFormData = (value) => lodash.isObject(value) && value instanceof FormData;
|
|
94
|
-
const isWindow = (value) => typeof window !== "undefined" && toString.call(value) === "[object Window]";
|
|
95
|
-
|
|
96
4
|
const formDataToObject = (formData) => {
|
|
97
5
|
return Object.fromEntries(formData.entries());
|
|
98
6
|
};
|
|
@@ -103,12 +11,12 @@
|
|
|
103
11
|
}
|
|
104
12
|
return formData;
|
|
105
13
|
};
|
|
106
|
-
const pickByParams = (params,
|
|
107
|
-
deep &&
|
|
108
|
-
if (
|
|
109
|
-
params[key] = pickByParams(params[key],
|
|
14
|
+
const pickByParams = (params, filter, deep = false) => {
|
|
15
|
+
deep && lodashEs.forIn(params, (value, key) => {
|
|
16
|
+
if (lodashEs.isObject(value))
|
|
17
|
+
params[key] = pickByParams(params[key], filter, deep);
|
|
110
18
|
});
|
|
111
|
-
const pickValue =
|
|
19
|
+
const pickValue = lodashEs.pickBy(params, (value) => !filter.includes(value));
|
|
112
20
|
if (Array.isArray(params)) {
|
|
113
21
|
return Object.values(pickValue);
|
|
114
22
|
}
|
|
@@ -118,7 +26,7 @@
|
|
|
118
26
|
const flatDeep = (object2, deep2 = 1) => {
|
|
119
27
|
let _object = {};
|
|
120
28
|
for (const [key, value] of Object.entries(object2)) {
|
|
121
|
-
if (
|
|
29
|
+
if (lodashEs.isPlainObject(value)) {
|
|
122
30
|
_object = { ..._object, ...deep2 > 0 ? flatDeep(value, deep2 - 1) : value };
|
|
123
31
|
continue;
|
|
124
32
|
}
|
|
@@ -129,21 +37,21 @@
|
|
|
129
37
|
return flatDeep(object, deep);
|
|
130
38
|
};
|
|
131
39
|
|
|
132
|
-
const
|
|
133
|
-
const empty = !(
|
|
40
|
+
const toUnit = (value, unit = "px") => {
|
|
41
|
+
const empty = !(lodashEs.isString(value) || lodashEs.isNumber(value));
|
|
134
42
|
if (empty)
|
|
135
43
|
return "";
|
|
136
|
-
return
|
|
44
|
+
return lodashEs.isString(value) && /\D/g.test(value) ? value : value + unit;
|
|
137
45
|
};
|
|
138
|
-
const
|
|
46
|
+
const toSize = (size, unit) => {
|
|
139
47
|
if (typeof size === "string" || typeof size === "number") {
|
|
140
|
-
return { width:
|
|
48
|
+
return { width: toUnit(size, unit), height: toUnit(size, unit) };
|
|
141
49
|
}
|
|
142
50
|
if (Array.isArray(size)) {
|
|
143
|
-
return { width:
|
|
51
|
+
return { width: toUnit(size[0], unit), height: toUnit(size[1], unit) };
|
|
144
52
|
}
|
|
145
53
|
if (typeof size === "object") {
|
|
146
|
-
return { width:
|
|
54
|
+
return { width: toUnit(size.width, unit), height: toUnit(size.height, unit) };
|
|
147
55
|
}
|
|
148
56
|
return { width: "", height: "" };
|
|
149
57
|
};
|
|
@@ -163,8 +71,6 @@
|
|
|
163
71
|
end = end > start ? end : start;
|
|
164
72
|
return [...new Array(end + 1).keys()].slice(start);
|
|
165
73
|
};
|
|
166
|
-
const noop = () => {
|
|
167
|
-
};
|
|
168
74
|
const checkedTypeof = (target) => {
|
|
169
75
|
const value = Object.prototype.toString.call(target).slice(8, -1).toLocaleLowerCase();
|
|
170
76
|
return value;
|
|
@@ -175,24 +81,29 @@
|
|
|
175
81
|
return condition;
|
|
176
82
|
};
|
|
177
83
|
|
|
84
|
+
const isBrowser = typeof window !== "undefined";
|
|
85
|
+
const isWeex = typeof WXEnvironment !== "undefined" && !!WXEnvironment.platform;
|
|
86
|
+
const weexPlatform = isWeex && WXEnvironment.platform.toLowerCase();
|
|
87
|
+
const UA = isBrowser && window.navigator.userAgent.toLowerCase();
|
|
88
|
+
const isIE = UA && /msie|trident/.test(UA);
|
|
89
|
+
const isIE9 = UA && UA.indexOf("msie 9.0") > 0;
|
|
90
|
+
const isIE11 = isBrowser && navigator.userAgent.includes("Trident") && navigator.userAgent.includes("rv:11.0");
|
|
91
|
+
const isEdge = UA && UA.indexOf("edge/") > 0;
|
|
92
|
+
const isAndroid = UA && UA.indexOf("android") > 0 || weexPlatform === "android";
|
|
93
|
+
const isIOS = UA && /iphone|ipad|ipod|ios/.test(UA) || weexPlatform === "ios";
|
|
94
|
+
const isChrome = UA && /chrome\/\d+/.test(UA) && !isEdge;
|
|
95
|
+
const isPhantomJS = UA && /phantomjs/.test(UA);
|
|
96
|
+
const isFF = typeof UA == "string" && UA.match(/firefox\/(\d+)/);
|
|
97
|
+
const isMobile = isBrowser && navigator.userAgent.toLowerCase().includes("mobile");
|
|
98
|
+
const isFormData = (value) => lodashEs.isObject(value) && value instanceof FormData;
|
|
99
|
+
const isWindow = (value) => typeof window !== "undefined" && toString.call(value) === "[object Window]";
|
|
100
|
+
|
|
178
101
|
exports.UA = UA;
|
|
179
|
-
exports.analySize = analySize;
|
|
180
|
-
exports.analyUnit = analyUnit;
|
|
181
102
|
exports.assert = assert;
|
|
182
103
|
exports.awaitPromise = awaitPromise;
|
|
183
|
-
exports.capitalizeCamelCase = capitalizeCamelCase;
|
|
184
104
|
exports.checkedTypeof = checkedTypeof;
|
|
185
|
-
exports.colourBlend = colourBlend;
|
|
186
105
|
exports.formDataToObject = formDataToObject;
|
|
187
|
-
exports.formatClearHtml = formatClearHtml;
|
|
188
|
-
exports.formatCoverPhone = formatCoverPhone;
|
|
189
|
-
exports.formatInteger = formatInteger;
|
|
190
|
-
exports.formatPrice = formatPrice;
|
|
191
|
-
exports.formatThousandBitSeparator = formatThousandBitSeparator;
|
|
192
|
-
exports.formatUnix = formatUnix;
|
|
193
|
-
exports.fuseThemeColor = fuseThemeColor;
|
|
194
106
|
exports.generateArray = generateArray;
|
|
195
|
-
exports.hexToRgba = hexToRgba;
|
|
196
107
|
exports.isAndroid = isAndroid;
|
|
197
108
|
exports.isBrowser = isBrowser;
|
|
198
109
|
exports.isChrome = isChrome;
|
|
@@ -207,14 +118,14 @@
|
|
|
207
118
|
exports.isPhantomJS = isPhantomJS;
|
|
208
119
|
exports.isWeex = isWeex;
|
|
209
120
|
exports.isWindow = isWindow;
|
|
210
|
-
exports.noop = noop;
|
|
211
121
|
exports.objectFlat = objectFlat;
|
|
212
122
|
exports.objectToFormData = objectToFormData;
|
|
213
123
|
exports.pickByParams = pickByParams;
|
|
214
|
-
exports.
|
|
124
|
+
exports.toSize = toSize;
|
|
125
|
+
exports.toUnit = toUnit;
|
|
215
126
|
exports.urlParamsAnaly = urlParamsAnaly;
|
|
216
127
|
exports.weexPlatform = weexPlatform;
|
|
217
128
|
|
|
218
129
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
219
130
|
|
|
220
|
-
})(this.hairyUtils = this.hairyUtils || {},
|
|
131
|
+
})(this.hairyUtils = this.hairyUtils || {}, _);
|
package/index.iife.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t
|
|
1
|
+
!function(e,t){"use strict";const i=(e,r,o=!1)=>{o&&t.forIn(e,((n,s)=>{t.isObject(n)&&(e[s]=i(e[s],r,o))}));const n=t.pickBy(e,(e=>!r.includes(e)));return Array.isArray(e)?Object.values(n):n},r=(e,i="px")=>!(t.isString(e)||t.isNumber(e))?"":t.isString(e)&&/\D/g.test(e)?e:e+i,o="undefined"!=typeof window,n="undefined"!=typeof WXEnvironment&&!!WXEnvironment.platform,s=n&&WXEnvironment.platform.toLowerCase(),a=o&&window.navigator.userAgent.toLowerCase(),c=a&&/msie|trident/.test(a),d=a&&a.indexOf("msie 9.0")>0,m=o&&navigator.userAgent.includes("Trident")&&navigator.userAgent.includes("rv:11.0"),f=a&&a.indexOf("edge/")>0,l=a&&a.indexOf("android")>0||"android"===s,h=a&&/iphone|ipad|ipod|ios/.test(a)||"ios"===s,u=a&&/chrome\/\d+/.test(a)&&!f,g=a&&/phantomjs/.test(a),w="string"==typeof a&&a.match(/firefox\/(\d+)/),p=o&&navigator.userAgent.toLowerCase().includes("mobile");e.UA=a,e.assert=(e,...t)=>(e||console.warn(...t),e),e.awaitPromise=(e=1e3)=>new Promise((t=>setTimeout(t,e))),e.checkedTypeof=e=>Object.prototype.toString.call(e).slice(8,-1).toLocaleLowerCase(),e.formDataToObject=e=>Object.fromEntries(e.entries()),e.generateArray=(e,t)=>(e=Number(e),t=(t=Number(t))>e?t:e,[...new Array(t+1).keys()].slice(e)),e.isAndroid=l,e.isBrowser=o,e.isChrome=u,e.isEdge=f,e.isFF=w,e.isFormData=e=>t.isObject(e)&&e instanceof FormData,e.isIE=c,e.isIE11=m,e.isIE9=d,e.isIOS=h,e.isMobile=p,e.isPhantomJS=g,e.isWeex=n,e.isWindow=e=>"undefined"!=typeof window&&"[object Window]"===toString.call(e),e.objectFlat=(e,i=1)=>{const r=(e,i=1)=>{let o={};for(const[n,s]of Object.entries(e))t.isPlainObject(s)?o={...o,...i>0?r(s,i-1):s}:o[n]=s;return o};return r(e,i)},e.objectToFormData=e=>{const t=new FormData;for(const[i,r]of Object.entries(e))t.append(i,String(r));return t},e.pickByParams=i,e.toSize=(e,t)=>"string"==typeof e||"number"==typeof e?{width:r(e,t),height:r(e,t)}:Array.isArray(e)?{width:r(e[0],t),height:r(e[1],t)}:"object"==typeof e?{width:r(e.width,t),height:r(e.height,t)}:{width:"",height:""},e.toUnit=r,e.urlParamsAnaly=(e,t)=>{const i=Object.keys(t).map((e=>`${e}=${t[e]}`));return i.length>0&&(e+="?"+i.join("&")),e},e.weexPlatform=s,Object.defineProperty(e,"__esModule",{value:!0})}(this.hairyUtils=this.hairyUtils||{},_);
|
package/package.json
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@hairy/utils",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"license": "MIT",
|
|
5
|
-
"dependencies": {
|
|
6
|
-
"dayjs": "^1.10.6",
|
|
7
|
-
"lodash": "^4"
|
|
8
|
-
},
|
|
9
|
-
"devDependencies": {
|
|
10
|
-
"@types/lodash": "^4"
|
|
11
|
-
},
|
|
12
|
-
"main": "./index.cjs.js",
|
|
13
|
-
"types": "./index.d.ts",
|
|
14
|
-
"module": "./index.esm.js",
|
|
15
|
-
"unpkg": "./index.iife.min.js",
|
|
16
|
-
"jsdelivr": "./index.iife.min.js",
|
|
17
|
-
"author": "Anthony Fu<https://github.com/TuiMao233>",
|
|
18
|
-
"repository": {
|
|
19
|
-
"type": "git",
|
|
20
|
-
"url": "git+https://github.com/TuiMao233/hairylib.git"
|
|
21
|
-
},
|
|
22
|
-
"bugs": {
|
|
23
|
-
"url": "https://github.com/TuiMao233/hairylib/issues"
|
|
24
|
-
},
|
|
25
|
-
"homepage": "https://github.com/TuiMao233/hairylib#readme",
|
|
26
|
-
"description": "Utilities core for Mr.Mao",
|
|
27
|
-
"exports": {
|
|
28
|
-
".": {
|
|
29
|
-
"import": "./index.esm.js",
|
|
30
|
-
"require": "./index.cjs.js"
|
|
31
|
-
},
|
|
32
|
-
"./*": "./*"
|
|
33
|
-
},
|
|
34
|
-
"gitHead": "
|
|
35
|
-
"publishConfig": {
|
|
36
|
-
"access": "public"
|
|
37
|
-
}
|
|
38
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@hairy/utils",
|
|
3
|
+
"version": "1.0.21",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"dayjs": "^1.10.6",
|
|
7
|
+
"lodash-es": "^4"
|
|
8
|
+
},
|
|
9
|
+
"devDependencies": {
|
|
10
|
+
"@types/lodash-es": "^4"
|
|
11
|
+
},
|
|
12
|
+
"main": "./index.cjs.js",
|
|
13
|
+
"types": "./index.d.ts",
|
|
14
|
+
"module": "./index.esm.js",
|
|
15
|
+
"unpkg": "./index.iife.min.js",
|
|
16
|
+
"jsdelivr": "./index.iife.min.js",
|
|
17
|
+
"author": "Anthony Fu<https://github.com/TuiMao233>",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/TuiMao233/hairylib.git"
|
|
21
|
+
},
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/TuiMao233/hairylib/issues"
|
|
24
|
+
},
|
|
25
|
+
"homepage": "https://github.com/TuiMao233/hairylib#readme",
|
|
26
|
+
"description": "Utilities core for Mr.Mao",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"import": "./index.esm.js",
|
|
30
|
+
"require": "./index.cjs.js"
|
|
31
|
+
},
|
|
32
|
+
"./*": "./*"
|
|
33
|
+
},
|
|
34
|
+
"gitHead": "9682f0fdcb39beaab4b6b44a3d6eba020f98bd39",
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
}
|
|
38
|
+
}
|