@hairy/utils 0.6.8 → 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 +88 -64
- package/dist/index.d.ts +35 -36
- package/dist/index.mjs +76 -49
- package/package.json +1 -6
- package/src/index.ts +0 -6
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
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
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,27 +15,19 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
20
|
// src/index.ts
|
|
31
21
|
var src_exports = {};
|
|
32
22
|
__export(src_exports, {
|
|
23
|
+
Deferred: () => Deferred,
|
|
33
24
|
UA: () => UA,
|
|
34
25
|
arange: () => arange,
|
|
35
|
-
atWillToSize: () => atWillToSize,
|
|
36
|
-
atWillToUnit: () => atWillToUnit,
|
|
37
26
|
compose: () => compose,
|
|
38
|
-
|
|
39
|
-
delay: () => import_delay.default,
|
|
27
|
+
delay: () => delay,
|
|
40
28
|
formDataToObject: () => formDataToObject,
|
|
29
|
+
formatSize: () => formatSize,
|
|
30
|
+
formatUnit: () => formatUnit,
|
|
41
31
|
getTypeof: () => getTypeof,
|
|
42
32
|
isAndroid: () => isAndroid,
|
|
43
33
|
isBrowser: () => isBrowser,
|
|
@@ -50,15 +40,22 @@ __export(src_exports, {
|
|
|
50
40
|
isIE9: () => isIE9,
|
|
51
41
|
isIOS: () => isIOS,
|
|
52
42
|
isMobile: () => isMobile,
|
|
43
|
+
isNumber: () => isNumber,
|
|
53
44
|
isObject: () => isObject,
|
|
54
45
|
isPhantomJS: () => isPhantomJS,
|
|
46
|
+
isPlainObject: () => isPlainObject,
|
|
47
|
+
isString: () => isString,
|
|
55
48
|
isTypeof: () => isTypeof,
|
|
56
49
|
isWeex: () => isWeex,
|
|
57
50
|
isWindow: () => isWindow,
|
|
51
|
+
loop: () => loop,
|
|
52
|
+
noop: () => noop,
|
|
58
53
|
objectToFormData: () => objectToFormData,
|
|
59
54
|
pPipe: () => pPipe,
|
|
60
55
|
pipe: () => pipe,
|
|
61
|
-
|
|
56
|
+
riposte: () => riposte,
|
|
57
|
+
weexPlatform: () => weexPlatform,
|
|
58
|
+
whenever: () => whenever
|
|
62
59
|
});
|
|
63
60
|
module.exports = __toCommonJS(src_exports);
|
|
64
61
|
|
|
@@ -77,9 +74,14 @@ var isChrome = () => UA() && /chrome\/\d+/.test(UA()) && !isEdge();
|
|
|
77
74
|
var isPhantomJS = () => UA() && /phantomjs/.test(UA());
|
|
78
75
|
var isFF = () => typeof UA() === "string" && UA().match(/firefox\/(\d+)/);
|
|
79
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]";
|
|
80
83
|
|
|
81
84
|
// src/lang/index.ts
|
|
82
|
-
var import_isObject = __toESM(require("lodash/isObject"));
|
|
83
85
|
function formDataToObject(formData) {
|
|
84
86
|
return Object.fromEntries(formData.entries());
|
|
85
87
|
}
|
|
@@ -89,32 +91,22 @@ function objectToFormData(object) {
|
|
|
89
91
|
formData.append(key, value);
|
|
90
92
|
return formData;
|
|
91
93
|
}
|
|
92
|
-
function isFormData(value) {
|
|
93
|
-
return isObject(value) && isBrowser() && value instanceof FormData;
|
|
94
|
-
}
|
|
95
|
-
function isWindow(value) {
|
|
96
|
-
return typeof window !== "undefined" && toString.call(value) === "[object Window]";
|
|
97
|
-
}
|
|
98
|
-
function isObject(value) {
|
|
99
|
-
return (0, import_isObject.default)(value) && !Array.isArray(value);
|
|
100
|
-
}
|
|
101
94
|
|
|
102
95
|
// src/size/index.ts
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
function atWillToUnit(value, unit = "px") {
|
|
106
|
-
if (!((0, import_isString.default)(value) || (0, import_isNumber.default)(value)))
|
|
96
|
+
function formatUnit(value, unit = "px") {
|
|
97
|
+
if (!(isString(value) || isNumber(value)))
|
|
107
98
|
return "";
|
|
108
|
-
|
|
99
|
+
value = String(value);
|
|
100
|
+
return /\D/g.test(value) ? value : value + unit;
|
|
109
101
|
}
|
|
110
|
-
function
|
|
111
|
-
const
|
|
112
|
-
if (typeof
|
|
113
|
-
return { width:
|
|
114
|
-
if (Array.isArray(
|
|
115
|
-
return { width:
|
|
116
|
-
if (typeof
|
|
117
|
-
return { width:
|
|
102
|
+
function formatSize(dimension, unit) {
|
|
103
|
+
const _formatUnit = (value) => formatUnit(value, unit);
|
|
104
|
+
if (typeof dimension === "string" || typeof dimension === "number")
|
|
105
|
+
return { width: _formatUnit(dimension), height: _formatUnit(dimension) };
|
|
106
|
+
if (Array.isArray(dimension))
|
|
107
|
+
return { width: _formatUnit(dimension[0]), height: _formatUnit(dimension[1]) };
|
|
108
|
+
if (typeof dimension === "object")
|
|
109
|
+
return { width: _formatUnit(dimension.width), height: _formatUnit(dimension.height) };
|
|
118
110
|
return { width: "", height: "" };
|
|
119
111
|
}
|
|
120
112
|
|
|
@@ -127,24 +119,45 @@ function isTypeof(target, type) {
|
|
|
127
119
|
return getTypeof(target) === type;
|
|
128
120
|
}
|
|
129
121
|
|
|
130
|
-
//
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
122
|
+
// src/util/deferred.ts
|
|
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
|
+
};
|
|
134
138
|
}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
// src/util/pipe.ts
|
|
142
|
+
var pPipe = (...functions) => {
|
|
143
|
+
if (functions.length === 0)
|
|
144
|
+
throw new Error("Expected at least one argument");
|
|
135
145
|
return async (input) => {
|
|
136
146
|
let currentValue = input;
|
|
137
|
-
for (const function_ of functions)
|
|
147
|
+
for (const function_ of functions)
|
|
138
148
|
currentValue = await function_(currentValue);
|
|
139
|
-
}
|
|
140
149
|
return currentValue;
|
|
141
150
|
};
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// src/util/index.ts
|
|
145
|
-
var import_delay = __toESM(require("delay"));
|
|
151
|
+
};
|
|
146
152
|
var pipe = (...fns) => fns.reduce((v, f) => f(v));
|
|
147
153
|
var compose = (...fns) => fns.reduceRight((v, f) => f(v));
|
|
154
|
+
|
|
155
|
+
// src/util/util.ts
|
|
156
|
+
function noop() {
|
|
157
|
+
}
|
|
158
|
+
function delay(ms) {
|
|
159
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
160
|
+
}
|
|
148
161
|
function arange(x1, x2, stp = 1, z = [], z0 = z.length) {
|
|
149
162
|
if (!x2)
|
|
150
163
|
x1 -= x2 = x1;
|
|
@@ -152,29 +165,33 @@ function arange(x1, x2, stp = 1, z = [], z0 = z.length) {
|
|
|
152
165
|
z[z0++] = x1;
|
|
153
166
|
return z;
|
|
154
167
|
}
|
|
155
|
-
function
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
168
|
+
function whenever(value, callback) {
|
|
169
|
+
return value ? callback(value) : void 0;
|
|
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;
|
|
167
184
|
}
|
|
168
185
|
// Annotate the CommonJS export names for ESM import in node:
|
|
169
186
|
0 && (module.exports = {
|
|
187
|
+
Deferred,
|
|
170
188
|
UA,
|
|
171
189
|
arange,
|
|
172
|
-
atWillToSize,
|
|
173
|
-
atWillToUnit,
|
|
174
190
|
compose,
|
|
175
|
-
createDeferred,
|
|
176
191
|
delay,
|
|
177
192
|
formDataToObject,
|
|
193
|
+
formatSize,
|
|
194
|
+
formatUnit,
|
|
178
195
|
getTypeof,
|
|
179
196
|
isAndroid,
|
|
180
197
|
isBrowser,
|
|
@@ -187,13 +204,20 @@ function createDeferred() {
|
|
|
187
204
|
isIE9,
|
|
188
205
|
isIOS,
|
|
189
206
|
isMobile,
|
|
207
|
+
isNumber,
|
|
190
208
|
isObject,
|
|
191
209
|
isPhantomJS,
|
|
210
|
+
isPlainObject,
|
|
211
|
+
isString,
|
|
192
212
|
isTypeof,
|
|
193
213
|
isWeex,
|
|
194
214
|
isWindow,
|
|
215
|
+
loop,
|
|
216
|
+
noop,
|
|
195
217
|
objectToFormData,
|
|
196
218
|
pPipe,
|
|
197
219
|
pipe,
|
|
198
|
-
|
|
220
|
+
riposte,
|
|
221
|
+
weexPlatform,
|
|
222
|
+
whenever
|
|
199
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,17 +30,14 @@ 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
|
-
type
|
|
34
|
-
type
|
|
35
|
+
type Numeric = string | number | bigint;
|
|
36
|
+
type DynamicObject = {
|
|
35
37
|
[key: string]: any;
|
|
36
38
|
};
|
|
37
|
-
type
|
|
38
|
-
[key: string]:
|
|
39
|
+
type NumericObject = {
|
|
40
|
+
[key: string]: Numeric;
|
|
39
41
|
};
|
|
40
42
|
type StringObject = {
|
|
41
43
|
[key: string]: string;
|
|
@@ -68,27 +70,20 @@ type Arrayable<T> = T | T[];
|
|
|
68
70
|
type Option<L extends Key = 'label', V extends Key = 'value', C extends Key = 'children'> = {
|
|
69
71
|
[P in L]?: string;
|
|
70
72
|
} & {
|
|
71
|
-
[P in V]?:
|
|
73
|
+
[P in V]?: Numeric;
|
|
72
74
|
} & {
|
|
73
75
|
[P in C]?: Option<L, V, C>[];
|
|
74
76
|
};
|
|
75
77
|
|
|
76
|
-
declare function
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
height: AtwillNumber;
|
|
78
|
+
declare function formatUnit(value: Numeric, unit?: string): string;
|
|
79
|
+
type Dimension = Numeric | [Numeric, Numeric] | {
|
|
80
|
+
width: Numeric;
|
|
81
|
+
height: Numeric;
|
|
81
82
|
};
|
|
82
|
-
|
|
83
|
+
declare function formatSize(dimension: Dimension, unit?: string): {
|
|
83
84
|
width: string;
|
|
84
85
|
height: string;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* 将 size 转换为宽高,用于元素宽高
|
|
88
|
-
* @param size AtWillSize
|
|
89
|
-
* @returns
|
|
90
|
-
*/
|
|
91
|
-
declare function atWillToSize(size: AtWillSize, unit?: string): Size;
|
|
86
|
+
};
|
|
92
87
|
|
|
93
88
|
type TypeofType = 'string' | 'number' | 'bigint' | 'boolean' | 'symbol' | 'undefined' | 'object' | 'function' | 'null' | 'regexp';
|
|
94
89
|
/**
|
|
@@ -105,17 +100,21 @@ declare function getTypeof(target: any): TypeofType;
|
|
|
105
100
|
*/
|
|
106
101
|
declare function isTypeof(target: any, type: TypeofType): boolean;
|
|
107
102
|
|
|
103
|
+
declare class Deferred<T> extends Promise<T> {
|
|
104
|
+
resolve: (value: T) => Deferred<T>;
|
|
105
|
+
reject: (reason?: any) => Deferred<T>;
|
|
106
|
+
constructor();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
declare const pPipe: typeof _pPipe;
|
|
108
110
|
declare const pipe: (...fns: any[]) => any;
|
|
109
|
-
declare const compose: (...fns: any[]) => any;
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
*/
|
|
111
|
+
declare const compose: (...fns: any[]) => any;
|
|
112
|
+
|
|
113
|
+
declare function noop(): any;
|
|
114
|
+
declare function delay(ms: number): Promise<unknown>;
|
|
114
115
|
declare function arange(x1: number, x2?: number, stp?: number, z?: number[], z0?: number): number[];
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
};
|
|
119
|
-
declare function createDeferred<T = void>(): Deferred<T>;
|
|
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;
|
|
120
119
|
|
|
121
|
-
export { Arrayable,
|
|
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
|
@@ -13,9 +13,14 @@ var isChrome = () => UA() && /chrome\/\d+/.test(UA()) && !isEdge();
|
|
|
13
13
|
var isPhantomJS = () => UA() && /phantomjs/.test(UA());
|
|
14
14
|
var isFF = () => typeof UA() === "string" && UA().match(/firefox\/(\d+)/);
|
|
15
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]";
|
|
16
22
|
|
|
17
23
|
// src/lang/index.ts
|
|
18
|
-
import _isObject from "lodash/isObject";
|
|
19
24
|
function formDataToObject(formData) {
|
|
20
25
|
return Object.fromEntries(formData.entries());
|
|
21
26
|
}
|
|
@@ -25,32 +30,22 @@ function objectToFormData(object) {
|
|
|
25
30
|
formData.append(key, value);
|
|
26
31
|
return formData;
|
|
27
32
|
}
|
|
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
33
|
|
|
38
34
|
// src/size/index.ts
|
|
39
|
-
|
|
40
|
-
import isString from "lodash/isString";
|
|
41
|
-
function atWillToUnit(value, unit = "px") {
|
|
35
|
+
function formatUnit(value, unit = "px") {
|
|
42
36
|
if (!(isString(value) || isNumber(value)))
|
|
43
37
|
return "";
|
|
44
|
-
|
|
38
|
+
value = String(value);
|
|
39
|
+
return /\D/g.test(value) ? value : value + unit;
|
|
45
40
|
}
|
|
46
|
-
function
|
|
47
|
-
const
|
|
48
|
-
if (typeof
|
|
49
|
-
return { width:
|
|
50
|
-
if (Array.isArray(
|
|
51
|
-
return { width:
|
|
52
|
-
if (typeof
|
|
53
|
-
return { width:
|
|
41
|
+
function formatSize(dimension, unit) {
|
|
42
|
+
const _formatUnit = (value) => formatUnit(value, unit);
|
|
43
|
+
if (typeof dimension === "string" || typeof dimension === "number")
|
|
44
|
+
return { width: _formatUnit(dimension), height: _formatUnit(dimension) };
|
|
45
|
+
if (Array.isArray(dimension))
|
|
46
|
+
return { width: _formatUnit(dimension[0]), height: _formatUnit(dimension[1]) };
|
|
47
|
+
if (typeof dimension === "object")
|
|
48
|
+
return { width: _formatUnit(dimension.width), height: _formatUnit(dimension.height) };
|
|
54
49
|
return { width: "", height: "" };
|
|
55
50
|
}
|
|
56
51
|
|
|
@@ -63,24 +58,45 @@ function isTypeof(target, type) {
|
|
|
63
58
|
return getTypeof(target) === type;
|
|
64
59
|
}
|
|
65
60
|
|
|
66
|
-
//
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
61
|
+
// src/util/deferred.ts
|
|
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
|
+
};
|
|
70
77
|
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// src/util/pipe.ts
|
|
81
|
+
var pPipe = (...functions) => {
|
|
82
|
+
if (functions.length === 0)
|
|
83
|
+
throw new Error("Expected at least one argument");
|
|
71
84
|
return async (input) => {
|
|
72
85
|
let currentValue = input;
|
|
73
|
-
for (const function_ of functions)
|
|
86
|
+
for (const function_ of functions)
|
|
74
87
|
currentValue = await function_(currentValue);
|
|
75
|
-
}
|
|
76
88
|
return currentValue;
|
|
77
89
|
};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// src/util/index.ts
|
|
81
|
-
import { default as default2 } from "delay";
|
|
90
|
+
};
|
|
82
91
|
var pipe = (...fns) => fns.reduce((v, f) => f(v));
|
|
83
92
|
var compose = (...fns) => fns.reduceRight((v, f) => f(v));
|
|
93
|
+
|
|
94
|
+
// src/util/util.ts
|
|
95
|
+
function noop() {
|
|
96
|
+
}
|
|
97
|
+
function delay(ms) {
|
|
98
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
99
|
+
}
|
|
84
100
|
function arange(x1, x2, stp = 1, z = [], z0 = z.length) {
|
|
85
101
|
if (!x2)
|
|
86
102
|
x1 -= x2 = x1;
|
|
@@ -88,28 +104,32 @@ function arange(x1, x2, stp = 1, z = [], z0 = z.length) {
|
|
|
88
104
|
z[z0++] = x1;
|
|
89
105
|
return z;
|
|
90
106
|
}
|
|
91
|
-
function
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
107
|
+
function whenever(value, callback) {
|
|
108
|
+
return value ? callback(value) : void 0;
|
|
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;
|
|
103
123
|
}
|
|
104
124
|
export {
|
|
125
|
+
Deferred,
|
|
105
126
|
UA,
|
|
106
127
|
arange,
|
|
107
|
-
atWillToSize,
|
|
108
|
-
atWillToUnit,
|
|
109
128
|
compose,
|
|
110
|
-
|
|
111
|
-
default2 as delay,
|
|
129
|
+
delay,
|
|
112
130
|
formDataToObject,
|
|
131
|
+
formatSize,
|
|
132
|
+
formatUnit,
|
|
113
133
|
getTypeof,
|
|
114
134
|
isAndroid,
|
|
115
135
|
isBrowser,
|
|
@@ -122,13 +142,20 @@ export {
|
|
|
122
142
|
isIE9,
|
|
123
143
|
isIOS,
|
|
124
144
|
isMobile,
|
|
145
|
+
isNumber,
|
|
125
146
|
isObject,
|
|
126
147
|
isPhantomJS,
|
|
148
|
+
isPlainObject,
|
|
149
|
+
isString,
|
|
127
150
|
isTypeof,
|
|
128
151
|
isWeex,
|
|
129
152
|
isWindow,
|
|
153
|
+
loop,
|
|
154
|
+
noop,
|
|
130
155
|
objectToFormData,
|
|
131
156
|
pPipe,
|
|
132
157
|
pipe,
|
|
133
|
-
|
|
158
|
+
riposte,
|
|
159
|
+
weexPlatform,
|
|
160
|
+
whenever
|
|
134
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
|
},
|