@hairy/utils 1.0.17 → 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/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
@@ -2,100 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var dayjs = require('dayjs');
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, filters, deep = false) => {
111
- deep && lodash.forIn(params, (value, key) => {
112
- if (lodash.isObject(value))
113
- params[key] = pickByParams(params[key], filters, deep);
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 = lodash.pickBy(params, (value) => !filters.includes(value));
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 (lodash.isPlainObject(value)) {
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 analyUnit = (value, unit = "px") => {
137
- const empty = !(lodash.isString(value) || lodash.isNumber(value));
43
+ const toUnit = (value, unit = "px") => {
44
+ const empty = !(lodashEs.isString(value) || lodashEs.isNumber(value));
138
45
  if (empty)
139
46
  return "";
140
- return lodash.isString(value) && /\D/g.test(value) ? value : value + unit;
47
+ return lodashEs.isString(value) && /\D/g.test(value) ? value : value + unit;
141
48
  };
142
- const analySize = (size, unit) => {
49
+ const toSize = (size, unit) => {
143
50
  if (typeof size === "string" || typeof size === "number") {
144
- return { width: analyUnit(size, unit), height: analyUnit(size, unit) };
51
+ return { width: toUnit(size, unit), height: toUnit(size, unit) };
145
52
  }
146
53
  if (Array.isArray(size)) {
147
- return { width: analyUnit(size[0], unit), height: analyUnit(size[1], unit) };
54
+ return { width: toUnit(size[0], unit), height: toUnit(size[1], unit) };
148
55
  }
149
56
  if (typeof size === "object") {
150
- return { width: analyUnit(size.width, unit), height: analyUnit(size.height, unit) };
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.prefixZero = prefixZero;
127
+ exports.toSize = toSize;
128
+ exports.toUnit = toUnit;
219
129
  exports.urlParamsAnaly = urlParamsAnaly;
220
130
  exports.weexPlatform = weexPlatform;
package/index.d.ts CHANGED
@@ -1,105 +1,3 @@
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;
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
1
  /**
104
2
  * 将 formData 转换为 object
105
3
  * @param formData
@@ -111,11 +9,11 @@ declare const formDataToObject: (formData: FormData) => Record<string, string>;
111
9
  */
112
10
  declare const objectToFormData: (object: Record<string, string | number>) => FormData;
113
11
  /**
114
- * 过滤对象|数组中 filters 中的值
12
+ * 过滤对象|数组中 filter 中的值
115
13
  * @param params
116
- * @param filters
14
+ * @param filter
117
15
  */
118
- declare const pickByParams: <T extends object>(params: T, filters: any[], deep?: boolean) => Partial<T>;
16
+ declare const pickByParams: <T extends object>(params: T, filter: any[], deep?: boolean) => Partial<T>;
119
17
  /**
120
18
  * 对象扁平化处理
121
19
  * @param object 对象
@@ -142,31 +40,31 @@ declare type DeepReplace<T, K = unknown, V = unknown> = {
142
40
  [P in keyof T]: K extends P ? V : DeepReplace<T[P], K, V>;
143
41
  };
144
42
  declare type Option<L extends Key = 'label', V extends Key = 'value', C extends Key = 'children'> = {
145
- [P in L]: string;
43
+ [P in L]?: string;
146
44
  } & {
147
- [P in V]: LooseNumber;
45
+ [P in V]?: LooseNumber;
148
46
  } & {
149
- [P in C]?: Option[];
47
+ [P in C]?: Option<L, V, C>[];
150
48
  };
151
49
 
152
50
  /**
153
51
  * 如果有单位,如百分比,px单位等,直接返回,如果是纯粹的数值,则加上px单位
154
- * @param size 尺寸
155
- * @param unit 单元
52
+ * @param value 尺寸
53
+ * @param unit 单位
156
54
  * @returns string
157
55
  */
158
- declare const analyUnit: (value: LooseNumber, unit?: string) => string;
56
+ declare const toUnit: (value: LooseNumber, unit?: string) => string;
159
57
  /** size 转换配置 */
160
- declare type AnalySizeOption = LooseNumber | [LooseNumber, LooseNumber] | {
58
+ declare type toSizeOption = LooseNumber | [LooseNumber, LooseNumber] | {
161
59
  width: LooseNumber;
162
60
  height: LooseNumber;
163
61
  };
164
62
  /**
165
63
  * 将 size 转换为宽高
166
- * @param size { AnalySizeOption }
64
+ * @param size { toSizeOption }
167
65
  * @returns
168
66
  */
169
- declare const analySize: (size: AnalySizeOption, unit?: string | undefined) => {
67
+ declare const toSize: (size: toSizeOption, unit?: string | undefined) => {
170
68
  width: string;
171
69
  height: string;
172
70
  };
@@ -190,8 +88,6 @@ declare const awaitPromise: (ms?: number) => Promise<unknown>;
190
88
  * @returns 递进的数组
191
89
  */
192
90
  declare const generateArray: (start: number, end: number) => number[];
193
- /** 空的方法 */
194
- declare const noop: () => void;
195
91
  /**
196
92
  * 获取数据类型
197
93
  * @param target 检测对象
@@ -205,4 +101,21 @@ declare const checkedTypeof: (target: any) => "string" | "number" | "bigint" | "
205
101
  */
206
102
  declare const assert: (condition: boolean, ...infos: any[]) => boolean;
207
103
 
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 };
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 dayjs from 'dayjs';
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, filters, deep = false) => {
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], filters, deep);
16
+ params[key] = pickByParams(params[key], filter, deep);
106
17
  });
107
- const pickValue = pickBy(params, (value) => !filters.includes(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 analyUnit = (value, unit = "px") => {
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 analySize = (size, unit) => {
45
+ const toSize = (size, unit) => {
135
46
  if (typeof size === "string" || typeof size === "number") {
136
- return { width: analyUnit(size, unit), height: analyUnit(size, unit) };
47
+ return { width: toUnit(size, unit), height: toUnit(size, unit) };
137
48
  }
138
49
  if (Array.isArray(size)) {
139
- return { width: analyUnit(size[0], unit), height: analyUnit(size[1], unit) };
50
+ return { width: toUnit(size[0], unit), height: toUnit(size[1], unit) };
140
51
  }
141
52
  if (typeof size === "object") {
142
- return { width: analyUnit(size.width, unit), height: analyUnit(size.height, unit) };
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
- 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 };
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, dayjs, lodash) {
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, filters, deep = false) => {
107
- deep && lodash.forIn(params, (value, key) => {
108
- if (lodash.isObject(value))
109
- params[key] = pickByParams(params[key], filters, deep);
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 = lodash.pickBy(params, (value) => !filters.includes(value));
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 (lodash.isPlainObject(value)) {
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 analyUnit = (value, unit = "px") => {
133
- const empty = !(lodash.isString(value) || lodash.isNumber(value));
40
+ const toUnit = (value, unit = "px") => {
41
+ const empty = !(lodashEs.isString(value) || lodashEs.isNumber(value));
134
42
  if (empty)
135
43
  return "";
136
- return lodash.isString(value) && /\D/g.test(value) ? value : value + unit;
44
+ return lodashEs.isString(value) && /\D/g.test(value) ? value : value + unit;
137
45
  };
138
- const analySize = (size, unit) => {
46
+ const toSize = (size, unit) => {
139
47
  if (typeof size === "string" || typeof size === "number") {
140
- return { width: analyUnit(size, unit), height: analyUnit(size, unit) };
48
+ return { width: toUnit(size, unit), height: toUnit(size, unit) };
141
49
  }
142
50
  if (Array.isArray(size)) {
143
- return { width: analyUnit(size[0], unit), height: analyUnit(size[1], unit) };
51
+ return { width: toUnit(size[0], unit), height: toUnit(size[1], unit) };
144
52
  }
145
53
  if (typeof size === "object") {
146
- return { width: analyUnit(size.width, unit), height: analyUnit(size.height, unit) };
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.prefixZero = prefixZero;
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 || {}, dayjs, _);
131
+ })(this.hairyUtils = this.hairyUtils || {}, _);
package/index.iife.min.js CHANGED
@@ -1 +1 @@
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,_);
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,40 +1,38 @@
1
- {
2
- "name": "@hairy/utils",
3
- "version": "1.0.17",
4
- "license": "MIT",
5
- "dependencies": {
6
- "dayjs": "^1.10.6"
7
- },
8
- "devDependencies": {
9
- "@types/lodash": "^4.14.171"
10
- },
11
- "peerDependencies": {
12
- "lodash": "^4.17.21"
13
- },
14
- "main": "./index.cjs.js",
15
- "types": "./index.d.ts",
16
- "module": "./index.esm.js",
17
- "unpkg": "./index.iife.min.js",
18
- "jsdelivr": "./index.iife.min.js",
19
- "author": "Anthony Fu<https://github.com/TuiMao233>",
20
- "repository": {
21
- "type": "git",
22
- "url": "git+https://github.com/TuiMao233/hairylib.git"
23
- },
24
- "bugs": {
25
- "url": "https://github.com/TuiMao233/hairylib/issues"
26
- },
27
- "homepage": "https://github.com/TuiMao233/hairylib#readme",
28
- "description": "Utilities core for Mr.Mao",
29
- "exports": {
30
- ".": {
31
- "import": "./index.esm.js",
32
- "require": "./index.cjs.js"
33
- },
34
- "./*": "./*"
35
- },
36
- "gitHead": "bca71be627bca344863814aa00ac4593a2e3f195",
37
- "publishConfig": {
38
- "access": "public"
39
- }
40
- }
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
+ }