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