@hairy/utils 1.0.21 → 1.5.0

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.esm.js DELETED
@@ -1,100 +0,0 @@
1
- import { forIn, isObject, pickBy, isPlainObject, isString, isNumber } from 'lodash-es';
2
-
3
- const formDataToObject = (formData) => {
4
- return Object.fromEntries(formData.entries());
5
- };
6
- const objectToFormData = (object) => {
7
- const formData = new FormData();
8
- for (const [key, value] of Object.entries(object)) {
9
- formData.append(key, String(value));
10
- }
11
- return formData;
12
- };
13
- const pickByParams = (params, filter, deep = false) => {
14
- deep && forIn(params, (value, key) => {
15
- if (isObject(value))
16
- params[key] = pickByParams(params[key], filter, deep);
17
- });
18
- const pickValue = pickBy(params, (value) => !filter.includes(value));
19
- if (Array.isArray(params)) {
20
- return Object.values(pickValue);
21
- }
22
- return pickValue;
23
- };
24
- const objectFlat = (object, deep = 1) => {
25
- const flatDeep = (object2, deep2 = 1) => {
26
- let _object = {};
27
- for (const [key, value] of Object.entries(object2)) {
28
- if (isPlainObject(value)) {
29
- _object = { ..._object, ...deep2 > 0 ? flatDeep(value, deep2 - 1) : value };
30
- continue;
31
- }
32
- _object[key] = value;
33
- }
34
- return _object;
35
- };
36
- return flatDeep(object, deep);
37
- };
38
-
39
- const toUnit = (value, unit = "px") => {
40
- const empty = !(isString(value) || isNumber(value));
41
- if (empty)
42
- return "";
43
- return isString(value) && /\D/g.test(value) ? value : value + unit;
44
- };
45
- const toSize = (size, unit) => {
46
- if (typeof size === "string" || typeof size === "number") {
47
- return { width: toUnit(size, unit), height: toUnit(size, unit) };
48
- }
49
- if (Array.isArray(size)) {
50
- return { width: toUnit(size[0], unit), height: toUnit(size[1], unit) };
51
- }
52
- if (typeof size === "object") {
53
- return { width: toUnit(size.width, unit), height: toUnit(size.height, unit) };
54
- }
55
- return { width: "", height: "" };
56
- };
57
-
58
- const urlParamsAnaly = (url, params) => {
59
- const queryString = Object.keys(params).map((key) => `${key}=${params[key]}`);
60
- if (queryString.length > 0)
61
- url += "?" + queryString.join("&");
62
- return url;
63
- };
64
- const awaitPromise = (ms = 1e3) => {
65
- return new Promise((resolve) => setTimeout(resolve, ms));
66
- };
67
- const generateArray = (start, end) => {
68
- start = Number(start);
69
- end = Number(end);
70
- end = end > start ? end : start;
71
- return [...new Array(end + 1).keys()].slice(start);
72
- };
73
- const checkedTypeof = (target) => {
74
- const value = Object.prototype.toString.call(target).slice(8, -1).toLocaleLowerCase();
75
- return value;
76
- };
77
- const assert = (condition, ...infos) => {
78
- if (!condition)
79
- console.warn(...infos);
80
- return condition;
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) => 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 DELETED
@@ -1,131 +0,0 @@
1
- (function (exports, lodashEs) {
2
- 'use strict';
3
-
4
- const formDataToObject = (formData) => {
5
- return Object.fromEntries(formData.entries());
6
- };
7
- const objectToFormData = (object) => {
8
- const formData = new FormData();
9
- for (const [key, value] of Object.entries(object)) {
10
- formData.append(key, String(value));
11
- }
12
- return formData;
13
- };
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);
18
- });
19
- const pickValue = lodashEs.pickBy(params, (value) => !filter.includes(value));
20
- if (Array.isArray(params)) {
21
- return Object.values(pickValue);
22
- }
23
- return pickValue;
24
- };
25
- const objectFlat = (object, deep = 1) => {
26
- const flatDeep = (object2, deep2 = 1) => {
27
- let _object = {};
28
- for (const [key, value] of Object.entries(object2)) {
29
- if (lodashEs.isPlainObject(value)) {
30
- _object = { ..._object, ...deep2 > 0 ? flatDeep(value, deep2 - 1) : value };
31
- continue;
32
- }
33
- _object[key] = value;
34
- }
35
- return _object;
36
- };
37
- return flatDeep(object, deep);
38
- };
39
-
40
- const toUnit = (value, unit = "px") => {
41
- const empty = !(lodashEs.isString(value) || lodashEs.isNumber(value));
42
- if (empty)
43
- return "";
44
- return lodashEs.isString(value) && /\D/g.test(value) ? value : value + unit;
45
- };
46
- const toSize = (size, unit) => {
47
- if (typeof size === "string" || typeof size === "number") {
48
- return { width: toUnit(size, unit), height: toUnit(size, unit) };
49
- }
50
- if (Array.isArray(size)) {
51
- return { width: toUnit(size[0], unit), height: toUnit(size[1], unit) };
52
- }
53
- if (typeof size === "object") {
54
- return { width: toUnit(size.width, unit), height: toUnit(size.height, unit) };
55
- }
56
- return { width: "", height: "" };
57
- };
58
-
59
- const urlParamsAnaly = (url, params) => {
60
- const queryString = Object.keys(params).map((key) => `${key}=${params[key]}`);
61
- if (queryString.length > 0)
62
- url += "?" + queryString.join("&");
63
- return url;
64
- };
65
- const awaitPromise = (ms = 1e3) => {
66
- return new Promise((resolve) => setTimeout(resolve, ms));
67
- };
68
- const generateArray = (start, end) => {
69
- start = Number(start);
70
- end = Number(end);
71
- end = end > start ? end : start;
72
- return [...new Array(end + 1).keys()].slice(start);
73
- };
74
- const checkedTypeof = (target) => {
75
- const value = Object.prototype.toString.call(target).slice(8, -1).toLocaleLowerCase();
76
- return value;
77
- };
78
- const assert = (condition, ...infos) => {
79
- if (!condition)
80
- console.warn(...infos);
81
- return condition;
82
- };
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
-
101
- exports.UA = UA;
102
- exports.assert = assert;
103
- exports.awaitPromise = awaitPromise;
104
- exports.checkedTypeof = checkedTypeof;
105
- exports.formDataToObject = formDataToObject;
106
- exports.generateArray = generateArray;
107
- exports.isAndroid = isAndroid;
108
- exports.isBrowser = isBrowser;
109
- exports.isChrome = isChrome;
110
- exports.isEdge = isEdge;
111
- exports.isFF = isFF;
112
- exports.isFormData = isFormData;
113
- exports.isIE = isIE;
114
- exports.isIE11 = isIE11;
115
- exports.isIE9 = isIE9;
116
- exports.isIOS = isIOS;
117
- exports.isMobile = isMobile;
118
- exports.isPhantomJS = isPhantomJS;
119
- exports.isWeex = isWeex;
120
- exports.isWindow = isWindow;
121
- exports.objectFlat = objectFlat;
122
- exports.objectToFormData = objectToFormData;
123
- exports.pickByParams = pickByParams;
124
- exports.toSize = toSize;
125
- exports.toUnit = toUnit;
126
- exports.urlParamsAnaly = urlParamsAnaly;
127
- exports.weexPlatform = weexPlatform;
128
-
129
- Object.defineProperty(exports, '__esModule', { value: true });
130
-
131
- })(this.hairyUtils = this.hairyUtils || {}, _);
package/index.iife.min.js DELETED
@@ -1 +0,0 @@
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||{},_);