@hairy/utils 0.6.6 → 0.6.9
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/dist/{index.cjs.js → index.cjs} +92 -34
- package/dist/index.d.ts +37 -28
- package/dist/index.mjs +214 -0
- package/package.json +6 -6
- package/dist/index.esm.js +0 -134
|
@@ -5,6 +5,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
+
};
|
|
8
11
|
var __export = (target, all) => {
|
|
9
12
|
for (var name in all)
|
|
10
13
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -27,17 +30,64 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
30
|
));
|
|
28
31
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
32
|
|
|
33
|
+
// ../../node_modules/.pnpm/lodash@4.0.0/node_modules/lodash/isObjectLike.js
|
|
34
|
+
var require_isObjectLike = __commonJS({
|
|
35
|
+
"../../node_modules/.pnpm/lodash@4.0.0/node_modules/lodash/isObjectLike.js"(exports, module2) {
|
|
36
|
+
function isObjectLike(value) {
|
|
37
|
+
return !!value && typeof value == "object";
|
|
38
|
+
}
|
|
39
|
+
module2.exports = isObjectLike;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// ../../node_modules/.pnpm/lodash@4.0.0/node_modules/lodash/isNumber.js
|
|
44
|
+
var require_isNumber = __commonJS({
|
|
45
|
+
"../../node_modules/.pnpm/lodash@4.0.0/node_modules/lodash/isNumber.js"(exports, module2) {
|
|
46
|
+
var isObjectLike = require_isObjectLike();
|
|
47
|
+
var numberTag = "[object Number]";
|
|
48
|
+
var objectProto = global.Object.prototype;
|
|
49
|
+
var objectToString = objectProto.toString;
|
|
50
|
+
function isNumber2(value) {
|
|
51
|
+
return typeof value == "number" || isObjectLike(value) && objectToString.call(value) == numberTag;
|
|
52
|
+
}
|
|
53
|
+
module2.exports = isNumber2;
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// ../../node_modules/.pnpm/lodash@4.0.0/node_modules/lodash/isArray.js
|
|
58
|
+
var require_isArray = __commonJS({
|
|
59
|
+
"../../node_modules/.pnpm/lodash@4.0.0/node_modules/lodash/isArray.js"(exports, module2) {
|
|
60
|
+
var isArray = Array.isArray;
|
|
61
|
+
module2.exports = isArray;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// ../../node_modules/.pnpm/lodash@4.0.0/node_modules/lodash/isString.js
|
|
66
|
+
var require_isString = __commonJS({
|
|
67
|
+
"../../node_modules/.pnpm/lodash@4.0.0/node_modules/lodash/isString.js"(exports, module2) {
|
|
68
|
+
var isArray = require_isArray();
|
|
69
|
+
var isObjectLike = require_isObjectLike();
|
|
70
|
+
var stringTag = "[object String]";
|
|
71
|
+
var objectProto = global.Object.prototype;
|
|
72
|
+
var objectToString = objectProto.toString;
|
|
73
|
+
function isString2(value) {
|
|
74
|
+
return typeof value == "string" || !isArray(value) && isObjectLike(value) && objectToString.call(value) == stringTag;
|
|
75
|
+
}
|
|
76
|
+
module2.exports = isString2;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
30
80
|
// src/index.ts
|
|
31
81
|
var src_exports = {};
|
|
32
82
|
__export(src_exports, {
|
|
33
83
|
UA: () => UA,
|
|
34
84
|
arange: () => arange,
|
|
35
|
-
atWillToSize: () => atWillToSize,
|
|
36
|
-
atWillToUnit: () => atWillToUnit,
|
|
37
85
|
compose: () => compose,
|
|
38
86
|
createDeferred: () => createDeferred,
|
|
39
87
|
delay: () => import_delay.default,
|
|
40
88
|
formDataToObject: () => formDataToObject,
|
|
89
|
+
formatSize: () => formatSize,
|
|
90
|
+
formatUnit: () => formatUnit,
|
|
41
91
|
getTypeof: () => getTypeof,
|
|
42
92
|
isAndroid: () => isAndroid,
|
|
43
93
|
isBrowser: () => isBrowser,
|
|
@@ -58,7 +108,8 @@ __export(src_exports, {
|
|
|
58
108
|
objectToFormData: () => objectToFormData,
|
|
59
109
|
pPipe: () => pPipe,
|
|
60
110
|
pipe: () => pipe,
|
|
61
|
-
weexPlatform: () => weexPlatform
|
|
111
|
+
weexPlatform: () => weexPlatform,
|
|
112
|
+
whenever: () => whenever
|
|
62
113
|
});
|
|
63
114
|
module.exports = __toCommonJS(src_exports);
|
|
64
115
|
|
|
@@ -79,7 +130,6 @@ var isFF = () => typeof UA() === "string" && UA().match(/firefox\/(\d+)/);
|
|
|
79
130
|
var isMobile = () => isBrowser() && navigator.userAgent.toLowerCase().includes("mobile");
|
|
80
131
|
|
|
81
132
|
// src/lang/index.ts
|
|
82
|
-
var import_isObject = __toESM(require("lodash/isObject"));
|
|
83
133
|
function formDataToObject(formData) {
|
|
84
134
|
return Object.fromEntries(formData.entries());
|
|
85
135
|
}
|
|
@@ -96,25 +146,25 @@ function isWindow(value) {
|
|
|
96
146
|
return typeof window !== "undefined" && toString.call(value) === "[object Window]";
|
|
97
147
|
}
|
|
98
148
|
function isObject(value) {
|
|
99
|
-
return
|
|
149
|
+
return typeof value === "object" && !Array.isArray(value);
|
|
100
150
|
}
|
|
101
151
|
|
|
102
152
|
// src/size/index.ts
|
|
103
|
-
var import_isNumber = __toESM(
|
|
104
|
-
var import_isString = __toESM(
|
|
105
|
-
function
|
|
153
|
+
var import_isNumber = __toESM(require_isNumber());
|
|
154
|
+
var import_isString = __toESM(require_isString());
|
|
155
|
+
function formatUnit(value, unit = "px") {
|
|
106
156
|
if (!((0, import_isString.default)(value) || (0, import_isNumber.default)(value)))
|
|
107
157
|
return "";
|
|
108
158
|
return (0, import_isString.default)(value) && /\D/g.test(value) ? value : value + unit;
|
|
109
159
|
}
|
|
110
|
-
function
|
|
111
|
-
const
|
|
112
|
-
if (typeof
|
|
113
|
-
return { width:
|
|
114
|
-
if (Array.isArray(
|
|
115
|
-
return { width:
|
|
116
|
-
if (typeof
|
|
117
|
-
return { width:
|
|
160
|
+
function formatSize(dimension, unit) {
|
|
161
|
+
const _formatUnit = (value) => formatUnit(value, unit);
|
|
162
|
+
if (typeof dimension === "string" || typeof dimension === "number")
|
|
163
|
+
return { width: _formatUnit(dimension), height: _formatUnit(dimension) };
|
|
164
|
+
if (Array.isArray(dimension))
|
|
165
|
+
return { width: _formatUnit(dimension[0]), height: _formatUnit(dimension[1]) };
|
|
166
|
+
if (typeof dimension === "object")
|
|
167
|
+
return { width: _formatUnit(dimension.width), height: _formatUnit(dimension.height) };
|
|
118
168
|
return { width: "", height: "" };
|
|
119
169
|
}
|
|
120
170
|
|
|
@@ -127,6 +177,21 @@ function isTypeof(target, type) {
|
|
|
127
177
|
return getTypeof(target) === type;
|
|
128
178
|
}
|
|
129
179
|
|
|
180
|
+
// src/util/deferred.ts
|
|
181
|
+
function createDeferred() {
|
|
182
|
+
let resolve, reject;
|
|
183
|
+
const promise = new Promise((_resolve, _reject) => {
|
|
184
|
+
resolve = _resolve;
|
|
185
|
+
reject = _reject;
|
|
186
|
+
});
|
|
187
|
+
promise.resolve = (v) => {
|
|
188
|
+
resolve(v);
|
|
189
|
+
return promise;
|
|
190
|
+
};
|
|
191
|
+
promise.reject = reject;
|
|
192
|
+
return promise;
|
|
193
|
+
}
|
|
194
|
+
|
|
130
195
|
// ../../node_modules/.pnpm/p-pipe@4.0.0/node_modules/p-pipe/index.js
|
|
131
196
|
function pPipe(...functions) {
|
|
132
197
|
if (functions.length === 0) {
|
|
@@ -141,10 +206,10 @@ function pPipe(...functions) {
|
|
|
141
206
|
};
|
|
142
207
|
}
|
|
143
208
|
|
|
144
|
-
// src/util/
|
|
209
|
+
// src/util/third.ts
|
|
145
210
|
var import_delay = __toESM(require("delay"));
|
|
146
|
-
|
|
147
|
-
|
|
211
|
+
|
|
212
|
+
// src/util/index.ts
|
|
148
213
|
function arange(x1, x2, stp = 1, z = [], z0 = z.length) {
|
|
149
214
|
if (!x2)
|
|
150
215
|
x1 -= x2 = x1;
|
|
@@ -152,29 +217,21 @@ function arange(x1, x2, stp = 1, z = [], z0 = z.length) {
|
|
|
152
217
|
z[z0++] = x1;
|
|
153
218
|
return z;
|
|
154
219
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
reject = _reject;
|
|
160
|
-
});
|
|
161
|
-
promise.resolve = (v) => {
|
|
162
|
-
resolve(v);
|
|
163
|
-
return promise;
|
|
164
|
-
};
|
|
165
|
-
promise.reject = reject;
|
|
166
|
-
return promise;
|
|
220
|
+
var pipe = (...fns) => fns.reduce((v, f) => f(v));
|
|
221
|
+
var compose = (...fns) => fns.reduceRight((v, f) => f(v));
|
|
222
|
+
function whenever(value, callback) {
|
|
223
|
+
return value ? callback(value) : void 0;
|
|
167
224
|
}
|
|
168
225
|
// Annotate the CommonJS export names for ESM import in node:
|
|
169
226
|
0 && (module.exports = {
|
|
170
227
|
UA,
|
|
171
228
|
arange,
|
|
172
|
-
atWillToSize,
|
|
173
|
-
atWillToUnit,
|
|
174
229
|
compose,
|
|
175
230
|
createDeferred,
|
|
176
231
|
delay,
|
|
177
232
|
formDataToObject,
|
|
233
|
+
formatSize,
|
|
234
|
+
formatUnit,
|
|
178
235
|
getTypeof,
|
|
179
236
|
isAndroid,
|
|
180
237
|
isBrowser,
|
|
@@ -195,5 +252,6 @@ function createDeferred() {
|
|
|
195
252
|
objectToFormData,
|
|
196
253
|
pPipe,
|
|
197
254
|
pipe,
|
|
198
|
-
weexPlatform
|
|
255
|
+
weexPlatform,
|
|
256
|
+
whenever
|
|
199
257
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -30,14 +30,25 @@ declare function isFormData(value: any): value is FormData;
|
|
|
30
30
|
declare function isWindow(value: any): value is Window;
|
|
31
31
|
declare function isObject(value: any): value is object;
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
type Numeric = string | number | bigint;
|
|
34
|
+
type DynamicObject = {
|
|
34
35
|
[key: string]: any;
|
|
35
|
-
}
|
|
36
|
-
type
|
|
37
|
-
|
|
36
|
+
};
|
|
37
|
+
type NumericObject = {
|
|
38
|
+
[key: string]: Numeric;
|
|
39
|
+
};
|
|
40
|
+
type StringObject = {
|
|
41
|
+
[key: string]: string;
|
|
42
|
+
};
|
|
43
|
+
type NumberObject = {
|
|
38
44
|
[key: string]: string;
|
|
39
|
-
}
|
|
45
|
+
};
|
|
46
|
+
type SymbolObject = {
|
|
47
|
+
[key: string]: symbol;
|
|
48
|
+
};
|
|
40
49
|
type Key = string | number | symbol;
|
|
50
|
+
type BooleanLike = any;
|
|
51
|
+
|
|
41
52
|
type DeepReadonly<T> = {
|
|
42
53
|
readonly [P in keyof T]: T[P] extends object ? DeepReadonly<T[P]> : T[P];
|
|
43
54
|
};
|
|
@@ -47,34 +58,30 @@ type DeepRequired<T> = {
|
|
|
47
58
|
type DeepPartial<T> = {
|
|
48
59
|
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
49
60
|
};
|
|
50
|
-
type DeepKeyof<T> = T extends object ? keyof T | DeepKeyof<T[keyof T]> : never;
|
|
51
61
|
type DeepReplace<T, K = unknown, V = unknown> = {
|
|
52
62
|
[P in keyof T]: K extends P ? V : DeepReplace<T[P], K, V>;
|
|
53
63
|
};
|
|
64
|
+
type DeepKeyof<T> = T extends object ? keyof T | DeepKeyof<T[keyof T]> : never;
|
|
65
|
+
|
|
66
|
+
type Awaitable<T> = T | Promise<T>;
|
|
67
|
+
type Arrayable<T> = T | T[];
|
|
54
68
|
type Option<L extends Key = 'label', V extends Key = 'value', C extends Key = 'children'> = {
|
|
55
69
|
[P in L]?: string;
|
|
56
70
|
} & {
|
|
57
|
-
[P in V]?:
|
|
71
|
+
[P in V]?: Numeric;
|
|
58
72
|
} & {
|
|
59
73
|
[P in C]?: Option<L, V, C>[];
|
|
60
74
|
};
|
|
61
75
|
|
|
62
|
-
declare function
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
height: AtWillNumber;
|
|
76
|
+
declare function formatUnit(value: Numeric, unit?: string): string;
|
|
77
|
+
type Dimension = Numeric | [Numeric, Numeric] | {
|
|
78
|
+
width: Numeric;
|
|
79
|
+
height: Numeric;
|
|
67
80
|
};
|
|
68
|
-
|
|
81
|
+
declare function formatSize(dimension: Dimension, unit?: string): {
|
|
69
82
|
width: string;
|
|
70
83
|
height: string;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* 将 size 转换为宽高,用于元素宽高
|
|
74
|
-
* @param size AtWillSize
|
|
75
|
-
* @returns
|
|
76
|
-
*/
|
|
77
|
-
declare function atWillToSize(size: AtWillSize, unit?: string): Size;
|
|
84
|
+
};
|
|
78
85
|
|
|
79
86
|
type TypeofType = 'string' | 'number' | 'bigint' | 'boolean' | 'symbol' | 'undefined' | 'object' | 'function' | 'null' | 'regexp';
|
|
80
87
|
/**
|
|
@@ -91,17 +98,19 @@ declare function getTypeof(target: any): TypeofType;
|
|
|
91
98
|
*/
|
|
92
99
|
declare function isTypeof(target: any, type: TypeofType): boolean;
|
|
93
100
|
|
|
94
|
-
|
|
95
|
-
|
|
101
|
+
type Deferred<T = void> = Promise<T> & {
|
|
102
|
+
resolve: (value: T) => void;
|
|
103
|
+
reject: (value?: any) => void;
|
|
104
|
+
};
|
|
105
|
+
declare function createDeferred<T = void>(): Deferred<T>;
|
|
106
|
+
|
|
96
107
|
/**
|
|
97
108
|
* 生成区间数组
|
|
98
109
|
* arange(<start>, <stop>, [step=1], [target=[]], [at])
|
|
99
110
|
*/
|
|
100
111
|
declare function arange(x1: number, x2?: number, stp?: number, z?: number[], z0?: number): number[];
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
};
|
|
105
|
-
declare function createDeferred<T = void>(): Deferred<T>;
|
|
112
|
+
declare const pipe: (...fns: any[]) => any;
|
|
113
|
+
declare const compose: (...fns: any[]) => any;
|
|
114
|
+
declare function whenever<T, C extends (value: Exclude<T, null | undefined>) => any>(value: T, callback: C): ReturnType<C> | undefined;
|
|
106
115
|
|
|
107
|
-
export {
|
|
116
|
+
export { Arrayable, Awaitable, BooleanLike, DeepKeyof, DeepPartial, DeepReadonly, DeepReplace, DeepRequired, Deferred, Dimension, DynamicObject, Key, NumberObject, Numeric, NumericObject, Option, StringObject, SymbolObject, TypeofType, UA, arange, compose, createDeferred, formDataToObject, formatSize, formatUnit, getTypeof, isAndroid, isBrowser, isChrome, isEdge, isFF, isFormData, isIE, isIE11, isIE9, isIOS, isMobile, isObject, isPhantomJS, isTypeof, isWeex, isWindow, objectToFormData, pipe, weexPlatform, whenever };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
+
mod
|
|
25
|
+
));
|
|
26
|
+
|
|
27
|
+
// ../../node_modules/.pnpm/lodash@4.0.0/node_modules/lodash/isObjectLike.js
|
|
28
|
+
var require_isObjectLike = __commonJS({
|
|
29
|
+
"../../node_modules/.pnpm/lodash@4.0.0/node_modules/lodash/isObjectLike.js"(exports, module) {
|
|
30
|
+
function isObjectLike(value) {
|
|
31
|
+
return !!value && typeof value == "object";
|
|
32
|
+
}
|
|
33
|
+
module.exports = isObjectLike;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// ../../node_modules/.pnpm/lodash@4.0.0/node_modules/lodash/isNumber.js
|
|
38
|
+
var require_isNumber = __commonJS({
|
|
39
|
+
"../../node_modules/.pnpm/lodash@4.0.0/node_modules/lodash/isNumber.js"(exports, module) {
|
|
40
|
+
var isObjectLike = require_isObjectLike();
|
|
41
|
+
var numberTag = "[object Number]";
|
|
42
|
+
var objectProto = global.Object.prototype;
|
|
43
|
+
var objectToString = objectProto.toString;
|
|
44
|
+
function isNumber2(value) {
|
|
45
|
+
return typeof value == "number" || isObjectLike(value) && objectToString.call(value) == numberTag;
|
|
46
|
+
}
|
|
47
|
+
module.exports = isNumber2;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// ../../node_modules/.pnpm/lodash@4.0.0/node_modules/lodash/isArray.js
|
|
52
|
+
var require_isArray = __commonJS({
|
|
53
|
+
"../../node_modules/.pnpm/lodash@4.0.0/node_modules/lodash/isArray.js"(exports, module) {
|
|
54
|
+
var isArray = Array.isArray;
|
|
55
|
+
module.exports = isArray;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// ../../node_modules/.pnpm/lodash@4.0.0/node_modules/lodash/isString.js
|
|
60
|
+
var require_isString = __commonJS({
|
|
61
|
+
"../../node_modules/.pnpm/lodash@4.0.0/node_modules/lodash/isString.js"(exports, module) {
|
|
62
|
+
var isArray = require_isArray();
|
|
63
|
+
var isObjectLike = require_isObjectLike();
|
|
64
|
+
var stringTag = "[object String]";
|
|
65
|
+
var objectProto = global.Object.prototype;
|
|
66
|
+
var objectToString = objectProto.toString;
|
|
67
|
+
function isString2(value) {
|
|
68
|
+
return typeof value == "string" || !isArray(value) && isObjectLike(value) && objectToString.call(value) == stringTag;
|
|
69
|
+
}
|
|
70
|
+
module.exports = isString2;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// src/is/index.ts
|
|
75
|
+
var isBrowser = () => typeof window !== "undefined";
|
|
76
|
+
var isWeex = () => typeof WXEnvironment !== "undefined" && !!WXEnvironment.platform;
|
|
77
|
+
var weexPlatform = () => isWeex() && WXEnvironment.platform.toLowerCase();
|
|
78
|
+
var UA = () => isBrowser() && window.navigator.userAgent.toLowerCase() || "";
|
|
79
|
+
var isIE = () => UA() && /msie|trident/.test(UA());
|
|
80
|
+
var isIE9 = () => UA() && UA().indexOf("msie 9.0") > 0;
|
|
81
|
+
var isIE11 = () => isBrowser() && navigator.userAgent.includes("Trident") && navigator.userAgent.includes("rv:11.0");
|
|
82
|
+
var isEdge = () => UA() && UA().indexOf("edge/") > 0;
|
|
83
|
+
var isAndroid = () => UA() && UA().indexOf("android") > 0 || weexPlatform() === "android";
|
|
84
|
+
var isIOS = () => UA() && /iphone|ipad|ipod|ios/.test(UA()) || weexPlatform() === "ios";
|
|
85
|
+
var isChrome = () => UA() && /chrome\/\d+/.test(UA()) && !isEdge();
|
|
86
|
+
var isPhantomJS = () => UA() && /phantomjs/.test(UA());
|
|
87
|
+
var isFF = () => typeof UA() === "string" && UA().match(/firefox\/(\d+)/);
|
|
88
|
+
var isMobile = () => isBrowser() && navigator.userAgent.toLowerCase().includes("mobile");
|
|
89
|
+
|
|
90
|
+
// src/lang/index.ts
|
|
91
|
+
function formDataToObject(formData) {
|
|
92
|
+
return Object.fromEntries(formData.entries());
|
|
93
|
+
}
|
|
94
|
+
function objectToFormData(object) {
|
|
95
|
+
const formData = new FormData();
|
|
96
|
+
for (const [key, value] of Object.entries(object))
|
|
97
|
+
formData.append(key, value);
|
|
98
|
+
return formData;
|
|
99
|
+
}
|
|
100
|
+
function isFormData(value) {
|
|
101
|
+
return isObject(value) && isBrowser() && value instanceof FormData;
|
|
102
|
+
}
|
|
103
|
+
function isWindow(value) {
|
|
104
|
+
return typeof window !== "undefined" && toString.call(value) === "[object Window]";
|
|
105
|
+
}
|
|
106
|
+
function isObject(value) {
|
|
107
|
+
return typeof value === "object" && !Array.isArray(value);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// src/size/index.ts
|
|
111
|
+
var import_isNumber = __toESM(require_isNumber());
|
|
112
|
+
var import_isString = __toESM(require_isString());
|
|
113
|
+
function formatUnit(value, unit = "px") {
|
|
114
|
+
if (!((0, import_isString.default)(value) || (0, import_isNumber.default)(value)))
|
|
115
|
+
return "";
|
|
116
|
+
return (0, import_isString.default)(value) && /\D/g.test(value) ? value : value + unit;
|
|
117
|
+
}
|
|
118
|
+
function formatSize(dimension, unit) {
|
|
119
|
+
const _formatUnit = (value) => formatUnit(value, unit);
|
|
120
|
+
if (typeof dimension === "string" || typeof dimension === "number")
|
|
121
|
+
return { width: _formatUnit(dimension), height: _formatUnit(dimension) };
|
|
122
|
+
if (Array.isArray(dimension))
|
|
123
|
+
return { width: _formatUnit(dimension[0]), height: _formatUnit(dimension[1]) };
|
|
124
|
+
if (typeof dimension === "object")
|
|
125
|
+
return { width: _formatUnit(dimension.width), height: _formatUnit(dimension.height) };
|
|
126
|
+
return { width: "", height: "" };
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// src/typeof/index.ts
|
|
130
|
+
function getTypeof(target) {
|
|
131
|
+
const value = Object.prototype.toString.call(target).slice(8, -1).toLocaleLowerCase();
|
|
132
|
+
return value;
|
|
133
|
+
}
|
|
134
|
+
function isTypeof(target, type) {
|
|
135
|
+
return getTypeof(target) === type;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// src/util/deferred.ts
|
|
139
|
+
function createDeferred() {
|
|
140
|
+
let resolve, reject;
|
|
141
|
+
const promise = new Promise((_resolve, _reject) => {
|
|
142
|
+
resolve = _resolve;
|
|
143
|
+
reject = _reject;
|
|
144
|
+
});
|
|
145
|
+
promise.resolve = (v) => {
|
|
146
|
+
resolve(v);
|
|
147
|
+
return promise;
|
|
148
|
+
};
|
|
149
|
+
promise.reject = reject;
|
|
150
|
+
return promise;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// ../../node_modules/.pnpm/p-pipe@4.0.0/node_modules/p-pipe/index.js
|
|
154
|
+
function pPipe(...functions) {
|
|
155
|
+
if (functions.length === 0) {
|
|
156
|
+
throw new Error("Expected at least one argument");
|
|
157
|
+
}
|
|
158
|
+
return async (input) => {
|
|
159
|
+
let currentValue = input;
|
|
160
|
+
for (const function_ of functions) {
|
|
161
|
+
currentValue = await function_(currentValue);
|
|
162
|
+
}
|
|
163
|
+
return currentValue;
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// src/util/third.ts
|
|
168
|
+
import { default as default2 } from "delay";
|
|
169
|
+
|
|
170
|
+
// src/util/index.ts
|
|
171
|
+
function arange(x1, x2, stp = 1, z = [], z0 = z.length) {
|
|
172
|
+
if (!x2)
|
|
173
|
+
x1 -= x2 = x1;
|
|
174
|
+
for (let z1 = z0 + Math.max(Math.ceil((++x2 - x1) / stp), 0); z0 < z1; x1 += stp)
|
|
175
|
+
z[z0++] = x1;
|
|
176
|
+
return z;
|
|
177
|
+
}
|
|
178
|
+
var pipe = (...fns) => fns.reduce((v, f) => f(v));
|
|
179
|
+
var compose = (...fns) => fns.reduceRight((v, f) => f(v));
|
|
180
|
+
function whenever(value, callback) {
|
|
181
|
+
return value ? callback(value) : void 0;
|
|
182
|
+
}
|
|
183
|
+
export {
|
|
184
|
+
UA,
|
|
185
|
+
arange,
|
|
186
|
+
compose,
|
|
187
|
+
createDeferred,
|
|
188
|
+
default2 as delay,
|
|
189
|
+
formDataToObject,
|
|
190
|
+
formatSize,
|
|
191
|
+
formatUnit,
|
|
192
|
+
getTypeof,
|
|
193
|
+
isAndroid,
|
|
194
|
+
isBrowser,
|
|
195
|
+
isChrome,
|
|
196
|
+
isEdge,
|
|
197
|
+
isFF,
|
|
198
|
+
isFormData,
|
|
199
|
+
isIE,
|
|
200
|
+
isIE11,
|
|
201
|
+
isIE9,
|
|
202
|
+
isIOS,
|
|
203
|
+
isMobile,
|
|
204
|
+
isObject,
|
|
205
|
+
isPhantomJS,
|
|
206
|
+
isTypeof,
|
|
207
|
+
isWeex,
|
|
208
|
+
isWindow,
|
|
209
|
+
objectToFormData,
|
|
210
|
+
pPipe,
|
|
211
|
+
pipe,
|
|
212
|
+
weexPlatform,
|
|
213
|
+
whenever
|
|
214
|
+
};
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hairy/utils",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.9",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"main": "./dist/index.cjs
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"jsdelivr": "./dist/index.iife.min.js"
|
|
8
8
|
},
|
|
@@ -21,14 +21,14 @@
|
|
|
21
21
|
"scripts": {
|
|
22
22
|
"build": "ptsup src/index.ts --dts"
|
|
23
23
|
},
|
|
24
|
+
"module": "./dist/index.mjs",
|
|
24
25
|
"types": "./dist/index.d.ts",
|
|
25
|
-
"module": "./dist/index.esm.js",
|
|
26
26
|
"unpkg": "./dist/index.iife.min.js",
|
|
27
27
|
"exports": {
|
|
28
28
|
".": {
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
29
|
+
"import": "./dist/index.mjs",
|
|
30
|
+
"require": "./dist/index.cjs",
|
|
31
|
+
"types": "./dist/index.d.ts"
|
|
32
32
|
},
|
|
33
33
|
"./*": "./*"
|
|
34
34
|
}
|
package/dist/index.esm.js
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
// src/is/index.ts
|
|
2
|
-
var isBrowser = () => typeof window !== "undefined";
|
|
3
|
-
var isWeex = () => typeof WXEnvironment !== "undefined" && !!WXEnvironment.platform;
|
|
4
|
-
var weexPlatform = () => isWeex() && WXEnvironment.platform.toLowerCase();
|
|
5
|
-
var UA = () => isBrowser() && window.navigator.userAgent.toLowerCase() || "";
|
|
6
|
-
var isIE = () => UA() && /msie|trident/.test(UA());
|
|
7
|
-
var isIE9 = () => UA() && UA().indexOf("msie 9.0") > 0;
|
|
8
|
-
var isIE11 = () => isBrowser() && navigator.userAgent.includes("Trident") && navigator.userAgent.includes("rv:11.0");
|
|
9
|
-
var isEdge = () => UA() && UA().indexOf("edge/") > 0;
|
|
10
|
-
var isAndroid = () => UA() && UA().indexOf("android") > 0 || weexPlatform() === "android";
|
|
11
|
-
var isIOS = () => UA() && /iphone|ipad|ipod|ios/.test(UA()) || weexPlatform() === "ios";
|
|
12
|
-
var isChrome = () => UA() && /chrome\/\d+/.test(UA()) && !isEdge();
|
|
13
|
-
var isPhantomJS = () => UA() && /phantomjs/.test(UA());
|
|
14
|
-
var isFF = () => typeof UA() === "string" && UA().match(/firefox\/(\d+)/);
|
|
15
|
-
var isMobile = () => isBrowser() && navigator.userAgent.toLowerCase().includes("mobile");
|
|
16
|
-
|
|
17
|
-
// src/lang/index.ts
|
|
18
|
-
import _isObject from "lodash/isObject";
|
|
19
|
-
function formDataToObject(formData) {
|
|
20
|
-
return Object.fromEntries(formData.entries());
|
|
21
|
-
}
|
|
22
|
-
function objectToFormData(object) {
|
|
23
|
-
const formData = new FormData();
|
|
24
|
-
for (const [key, value] of Object.entries(object))
|
|
25
|
-
formData.append(key, value);
|
|
26
|
-
return formData;
|
|
27
|
-
}
|
|
28
|
-
function isFormData(value) {
|
|
29
|
-
return isObject(value) && isBrowser() && value instanceof FormData;
|
|
30
|
-
}
|
|
31
|
-
function isWindow(value) {
|
|
32
|
-
return typeof window !== "undefined" && toString.call(value) === "[object Window]";
|
|
33
|
-
}
|
|
34
|
-
function isObject(value) {
|
|
35
|
-
return _isObject(value) && !Array.isArray(value);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// src/size/index.ts
|
|
39
|
-
import isNumber from "lodash/isNumber";
|
|
40
|
-
import isString from "lodash/isString";
|
|
41
|
-
function atWillToUnit(value, unit = "px") {
|
|
42
|
-
if (!(isString(value) || isNumber(value)))
|
|
43
|
-
return "";
|
|
44
|
-
return isString(value) && /\D/g.test(value) ? value : value + unit;
|
|
45
|
-
}
|
|
46
|
-
function atWillToSize(size, unit) {
|
|
47
|
-
const _atWillToUnit = (value) => atWillToUnit(value, unit);
|
|
48
|
-
if (typeof size === "string" || typeof size === "number")
|
|
49
|
-
return { width: _atWillToUnit(size), height: _atWillToUnit(size) };
|
|
50
|
-
if (Array.isArray(size))
|
|
51
|
-
return { width: _atWillToUnit(size[0]), height: _atWillToUnit(size[1]) };
|
|
52
|
-
if (typeof size === "object")
|
|
53
|
-
return { width: _atWillToUnit(size.width), height: _atWillToUnit(size.height) };
|
|
54
|
-
return { width: "", height: "" };
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// src/typeof/index.ts
|
|
58
|
-
function getTypeof(target) {
|
|
59
|
-
const value = Object.prototype.toString.call(target).slice(8, -1).toLocaleLowerCase();
|
|
60
|
-
return value;
|
|
61
|
-
}
|
|
62
|
-
function isTypeof(target, type) {
|
|
63
|
-
return getTypeof(target) === type;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// ../../node_modules/.pnpm/p-pipe@4.0.0/node_modules/p-pipe/index.js
|
|
67
|
-
function pPipe(...functions) {
|
|
68
|
-
if (functions.length === 0) {
|
|
69
|
-
throw new Error("Expected at least one argument");
|
|
70
|
-
}
|
|
71
|
-
return async (input) => {
|
|
72
|
-
let currentValue = input;
|
|
73
|
-
for (const function_ of functions) {
|
|
74
|
-
currentValue = await function_(currentValue);
|
|
75
|
-
}
|
|
76
|
-
return currentValue;
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// src/util/index.ts
|
|
81
|
-
import { default as default2 } from "delay";
|
|
82
|
-
var pipe = (...fns) => fns.reduce((v, f) => f(v));
|
|
83
|
-
var compose = (...fns) => fns.reduceRight((v, f) => f(v));
|
|
84
|
-
function arange(x1, x2, stp = 1, z = [], z0 = z.length) {
|
|
85
|
-
if (!x2)
|
|
86
|
-
x1 -= x2 = x1;
|
|
87
|
-
for (let z1 = z0 + Math.max(Math.ceil((++x2 - x1) / stp), 0); z0 < z1; x1 += stp)
|
|
88
|
-
z[z0++] = x1;
|
|
89
|
-
return z;
|
|
90
|
-
}
|
|
91
|
-
function createDeferred() {
|
|
92
|
-
let resolve, reject;
|
|
93
|
-
const promise = new Promise((_resolve, _reject) => {
|
|
94
|
-
resolve = _resolve;
|
|
95
|
-
reject = _reject;
|
|
96
|
-
});
|
|
97
|
-
promise.resolve = (v) => {
|
|
98
|
-
resolve(v);
|
|
99
|
-
return promise;
|
|
100
|
-
};
|
|
101
|
-
promise.reject = reject;
|
|
102
|
-
return promise;
|
|
103
|
-
}
|
|
104
|
-
export {
|
|
105
|
-
UA,
|
|
106
|
-
arange,
|
|
107
|
-
atWillToSize,
|
|
108
|
-
atWillToUnit,
|
|
109
|
-
compose,
|
|
110
|
-
createDeferred,
|
|
111
|
-
default2 as delay,
|
|
112
|
-
formDataToObject,
|
|
113
|
-
getTypeof,
|
|
114
|
-
isAndroid,
|
|
115
|
-
isBrowser,
|
|
116
|
-
isChrome,
|
|
117
|
-
isEdge,
|
|
118
|
-
isFF,
|
|
119
|
-
isFormData,
|
|
120
|
-
isIE,
|
|
121
|
-
isIE11,
|
|
122
|
-
isIE9,
|
|
123
|
-
isIOS,
|
|
124
|
-
isMobile,
|
|
125
|
-
isObject,
|
|
126
|
-
isPhantomJS,
|
|
127
|
-
isTypeof,
|
|
128
|
-
isWeex,
|
|
129
|
-
isWindow,
|
|
130
|
-
objectToFormData,
|
|
131
|
-
pPipe,
|
|
132
|
-
pipe,
|
|
133
|
-
weexPlatform
|
|
134
|
-
};
|