@hairy/utils 1.0.20 → 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/{LICENSE → LICENSE.md} +21 -23
- package/README.md +36 -0
- package/dist/index.cjs +405 -0
- package/dist/index.d.ts +254 -0
- package/dist/index.global.js +1599 -0
- package/dist/index.js +312 -0
- package/package.json +32 -26
- package/index.cjs.js +0 -220
- package/index.d.ts +0 -208
- package/index.esm.js +0 -174
- package/index.iife.js +0 -220
- package/index.iife.min.js +0 -1
package/{LICENSE → LICENSE.md}
RENAMED
|
@@ -1,23 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c)
|
|
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) 2025-PRESENT Hairyf <https://github.com/antfu>
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# @hairy/utils
|
|
2
|
+
|
|
3
|
+
[![npm version][npm-version-src]][npm-version-href]
|
|
4
|
+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
5
|
+
[![bundle][bundle-src]][bundle-href]
|
|
6
|
+
[![JSDocs][jsdocs-src]][jsdocs-href]
|
|
7
|
+
[![License][license-src]][license-href]
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
ni @hairy/utils
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## CDN
|
|
16
|
+
|
|
17
|
+
```html
|
|
18
|
+
<script src="https://unpkg.com/@hairy/utils"></script>
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## License
|
|
22
|
+
|
|
23
|
+
[MIT](./LICENSE) License © [Hairyf](https://github.com/hairyf)
|
|
24
|
+
|
|
25
|
+
<!-- Badges -->
|
|
26
|
+
|
|
27
|
+
[npm-version-src]: https://img.shields.io/npm/v/@hairy/utils?style=flat&colorA=080f12&colorB=1fa669
|
|
28
|
+
[npm-version-href]: https://npmjs.com/package/@hairy/utils
|
|
29
|
+
[npm-downloads-src]: https://img.shields.io/npm/dm/@hairy/utils?style=flat&colorA=080f12&colorB=1fa669
|
|
30
|
+
[npm-downloads-href]: https://npmjs.com/package/@hairy/utils
|
|
31
|
+
[bundle-src]: https://img.shields.io/bundlephobia/minzip/@hairy/utils?style=flat&colorA=080f12&colorB=1fa669&label=minzip
|
|
32
|
+
[bundle-href]: https://bundlephobia.com/result?p=@hairy/utils
|
|
33
|
+
[license-src]: https://img.shields.io/github/license/hairyf/hairylib.svg?style=flat&colorA=080f12&colorB=1fa669
|
|
34
|
+
[license-href]: https://github.com/hairyf/hairylib/blob/main/LICENSE
|
|
35
|
+
[jsdocs-src]: https://img.shields.io/badge/jsdocs-reference-080f12?style=flat&colorA=080f12&colorB=1fa669
|
|
36
|
+
[jsdocs-href]: https://www.jsdocs.io/package/@hairy/utils
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
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
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
BIG_INTS: () => BIG_INTS,
|
|
34
|
+
Bignumber: () => import_bignumber.default,
|
|
35
|
+
Deferred: () => Deferred,
|
|
36
|
+
UA: () => UA,
|
|
37
|
+
arange: () => arange,
|
|
38
|
+
average: () => average,
|
|
39
|
+
compose: () => compose,
|
|
40
|
+
cover: () => cover,
|
|
41
|
+
decimal: () => decimal,
|
|
42
|
+
delay: () => delay,
|
|
43
|
+
formToObject: () => formToObject,
|
|
44
|
+
formatNumeric: () => formatNumeric,
|
|
45
|
+
formatSize: () => formatSize,
|
|
46
|
+
formatUnit: () => formatUnit,
|
|
47
|
+
getTypeof: () => getTypeof,
|
|
48
|
+
gt: () => gt,
|
|
49
|
+
gte: () => gte,
|
|
50
|
+
integer: () => integer,
|
|
51
|
+
isAndroid: () => isAndroid,
|
|
52
|
+
isArray: () => isArray,
|
|
53
|
+
isBrowser: () => isBrowser,
|
|
54
|
+
isChrome: () => isChrome,
|
|
55
|
+
isEdge: () => isEdge,
|
|
56
|
+
isFF: () => isFF,
|
|
57
|
+
isFormData: () => isFormData,
|
|
58
|
+
isIE: () => isIE,
|
|
59
|
+
isIE11: () => isIE11,
|
|
60
|
+
isIE9: () => isIE9,
|
|
61
|
+
isIOS: () => isIOS,
|
|
62
|
+
isMobile: () => isMobile,
|
|
63
|
+
isNull: () => isNull,
|
|
64
|
+
isNumber: () => isNumber,
|
|
65
|
+
isObject: () => isObject,
|
|
66
|
+
isPhantomJS: () => isPhantomJS,
|
|
67
|
+
isPlainObject: () => isPlainObject,
|
|
68
|
+
isString: () => isString,
|
|
69
|
+
isTypeof: () => isTypeof,
|
|
70
|
+
isWeex: () => isWeex,
|
|
71
|
+
isWindow: () => isWindow,
|
|
72
|
+
loop: () => loop,
|
|
73
|
+
lt: () => lt,
|
|
74
|
+
lte: () => lte,
|
|
75
|
+
noop: () => noop,
|
|
76
|
+
numerfix: () => numerfix,
|
|
77
|
+
objectToForm: () => objectToForm,
|
|
78
|
+
pPipe: () => pPipe,
|
|
79
|
+
parseNumeric: () => parseNumeric,
|
|
80
|
+
percentage: () => percentage,
|
|
81
|
+
pipe: () => pipe,
|
|
82
|
+
plus: () => plus,
|
|
83
|
+
riposte: () => riposte,
|
|
84
|
+
unum: () => unum,
|
|
85
|
+
unwrap: () => unwrap,
|
|
86
|
+
weexPlatform: () => weexPlatform,
|
|
87
|
+
whenever: () => whenever,
|
|
88
|
+
zerofill: () => zerofill,
|
|
89
|
+
zeromove: () => zeromove
|
|
90
|
+
});
|
|
91
|
+
module.exports = __toCommonJS(index_exports);
|
|
92
|
+
|
|
93
|
+
// src/number/index.ts
|
|
94
|
+
var import_bignumber = __toESM(require("bignumber.js"), 1);
|
|
95
|
+
var BIG_INTS = {
|
|
96
|
+
t: { v: 10 ** 12, d: 13, n: "t" },
|
|
97
|
+
b: { v: 10 ** 9, d: 10, n: "b" },
|
|
98
|
+
m: { v: 10 ** 6, d: 7, n: "m" },
|
|
99
|
+
k: { v: 10 ** 3, d: 4, n: "k" }
|
|
100
|
+
};
|
|
101
|
+
function unum(num = "0") {
|
|
102
|
+
return new import_bignumber.default(numerfix(num));
|
|
103
|
+
}
|
|
104
|
+
function gte(num, n) {
|
|
105
|
+
return unum(num).gte(unum(n));
|
|
106
|
+
}
|
|
107
|
+
function gt(num, n) {
|
|
108
|
+
return unum(num).gt(unum(n));
|
|
109
|
+
}
|
|
110
|
+
function lte(num, n) {
|
|
111
|
+
return unum(num).lte(unum(n));
|
|
112
|
+
}
|
|
113
|
+
function lt(num, n) {
|
|
114
|
+
return unum(num).lt(unum(n));
|
|
115
|
+
}
|
|
116
|
+
function plus(array, options) {
|
|
117
|
+
const rounding = options?.r || import_bignumber.default.ROUND_DOWN;
|
|
118
|
+
const decimal2 = options?.d || 0;
|
|
119
|
+
return array.filter((v) => unum(v).gt(0)).reduce((t, v) => t.plus(unum(v)), unum(0)).toFixed(decimal2, rounding);
|
|
120
|
+
}
|
|
121
|
+
function average(array, options) {
|
|
122
|
+
const rounding = options?.r || import_bignumber.default.ROUND_DOWN;
|
|
123
|
+
const decimal2 = options?.d || 0;
|
|
124
|
+
if (array.length === 0)
|
|
125
|
+
return "0";
|
|
126
|
+
return unum(plus(array)).div(array.length).toFixed(decimal2, rounding);
|
|
127
|
+
}
|
|
128
|
+
function percentage(total, count, options) {
|
|
129
|
+
options ??= { d: 3, r: import_bignumber.default.ROUND_DOWN };
|
|
130
|
+
const rounding = options?.r || import_bignumber.default.ROUND_DOWN;
|
|
131
|
+
const decimal2 = options?.d || 3;
|
|
132
|
+
if (unum(total).lte(0) || unum(count).lte(0))
|
|
133
|
+
return "0";
|
|
134
|
+
return unum(count).div(unum(total)).times(100).toFixed(decimal2, rounding);
|
|
135
|
+
}
|
|
136
|
+
function zerofill(value, n = 2, type = "positive") {
|
|
137
|
+
const _value = integer(value);
|
|
138
|
+
if (_value.length >= n)
|
|
139
|
+
return value;
|
|
140
|
+
const zero = "0".repeat(n - _value.length);
|
|
141
|
+
if (type === "positive")
|
|
142
|
+
return zero + value;
|
|
143
|
+
if (type === "reverse")
|
|
144
|
+
return zero + value;
|
|
145
|
+
return "";
|
|
146
|
+
}
|
|
147
|
+
function zeromove(value) {
|
|
148
|
+
return value.toString().replace(/\.?0+$/, "");
|
|
149
|
+
}
|
|
150
|
+
function numerfix(value) {
|
|
151
|
+
const _isNaN = Number.isNaN(Number(value)) || value.toString() === "NaN";
|
|
152
|
+
if (_isNaN)
|
|
153
|
+
console.warn(`numerfix(${value}): value is not the correct value. To ensure the normal operation of the program, it will be converted to zero`);
|
|
154
|
+
return _isNaN ? "0" : String(value);
|
|
155
|
+
}
|
|
156
|
+
function integer(value) {
|
|
157
|
+
return new import_bignumber.default(numerfix(value)).toFixed(0);
|
|
158
|
+
}
|
|
159
|
+
function decimal(value, n = 2) {
|
|
160
|
+
let [integer2, decimal2] = numerfix(value).split(".");
|
|
161
|
+
if (n <= 0)
|
|
162
|
+
return integer2;
|
|
163
|
+
if (!decimal2)
|
|
164
|
+
decimal2 = "0";
|
|
165
|
+
decimal2 = decimal2.slice(0, n);
|
|
166
|
+
decimal2 = decimal2 + "0".repeat(n - decimal2.length);
|
|
167
|
+
return `${integer2}.${decimal2}`;
|
|
168
|
+
}
|
|
169
|
+
function parseNumeric(num, delimiters = ["t", "b", "m"]) {
|
|
170
|
+
const mappings = [
|
|
171
|
+
delimiters.includes("t") && ((n) => gte(n, BIG_INTS.t.v) && BIG_INTS.t),
|
|
172
|
+
delimiters.includes("b") && ((n) => gte(n, BIG_INTS.b.v) && lt(n, BIG_INTS.t.v) && BIG_INTS.b),
|
|
173
|
+
delimiters.includes("m") && ((n) => gte(n, BIG_INTS.m.v) && lt(n, BIG_INTS.b.v) && BIG_INTS.m),
|
|
174
|
+
delimiters.includes("k") && ((n) => gte(n, BIG_INTS.k.v) && lt(n, BIG_INTS.m.v) && BIG_INTS.k)
|
|
175
|
+
];
|
|
176
|
+
let options;
|
|
177
|
+
for (const analy of mappings) {
|
|
178
|
+
const opts = analy && analy(unum(num).toFixed(0));
|
|
179
|
+
opts && (options = opts);
|
|
180
|
+
}
|
|
181
|
+
return options || { v: 1, d: 0, n: "" };
|
|
182
|
+
}
|
|
183
|
+
function formatNumeric(value = "0", options) {
|
|
184
|
+
const {
|
|
185
|
+
rounding = import_bignumber.default.ROUND_DOWN,
|
|
186
|
+
delimiters,
|
|
187
|
+
format,
|
|
188
|
+
decimals = 2
|
|
189
|
+
} = options || {};
|
|
190
|
+
const config = parseNumeric(value, delimiters || []);
|
|
191
|
+
let number = unum(value).div(config.v).toFormat(decimals, rounding, {
|
|
192
|
+
decimalSeparator: ".",
|
|
193
|
+
groupSeparator: ",",
|
|
194
|
+
groupSize: 3,
|
|
195
|
+
secondaryGroupSize: 0,
|
|
196
|
+
fractionGroupSeparator: " ",
|
|
197
|
+
fractionGroupSize: 0,
|
|
198
|
+
...format
|
|
199
|
+
});
|
|
200
|
+
number = options?.zeromove ? zeromove(number) : number;
|
|
201
|
+
return `${number}${config.n}`;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// src/util/compose.ts
|
|
205
|
+
var compose = (...fns) => fns.reduceRight((v, f) => f(v));
|
|
206
|
+
|
|
207
|
+
// src/util/converts.ts
|
|
208
|
+
function formToObject(formData) {
|
|
209
|
+
return Object.fromEntries(formData.entries());
|
|
210
|
+
}
|
|
211
|
+
function objectToForm(object) {
|
|
212
|
+
const formData = new FormData();
|
|
213
|
+
for (const [key, value] of Object.entries(object)) formData.append(key, value);
|
|
214
|
+
return formData;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// src/util/deferred.ts
|
|
218
|
+
var Deferred = class extends Promise {
|
|
219
|
+
resolve;
|
|
220
|
+
reject;
|
|
221
|
+
constructor() {
|
|
222
|
+
let _resolve, _reject;
|
|
223
|
+
super((resolve_, reject_) => {
|
|
224
|
+
_resolve = resolve_;
|
|
225
|
+
_reject = reject_;
|
|
226
|
+
});
|
|
227
|
+
this.resolve = (value) => {
|
|
228
|
+
_resolve(value);
|
|
229
|
+
return this;
|
|
230
|
+
};
|
|
231
|
+
this.reject = (reason) => {
|
|
232
|
+
_reject(reason);
|
|
233
|
+
return this;
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
// src/util/delay.ts
|
|
239
|
+
function delay(ms) {
|
|
240
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// src/util/is.ts
|
|
244
|
+
var isBrowser = () => typeof window !== "undefined";
|
|
245
|
+
var isWeex = () => typeof WXEnvironment !== "undefined" && !!WXEnvironment.platform;
|
|
246
|
+
var weexPlatform = () => isWeex() && WXEnvironment.platform.toLowerCase();
|
|
247
|
+
var UA = () => isBrowser() && window.navigator.userAgent.toLowerCase() || "";
|
|
248
|
+
var isIE = () => UA() && /msie|trident/.test(UA());
|
|
249
|
+
var isIE9 = () => UA() && UA().indexOf("msie 9.0") > 0;
|
|
250
|
+
var isIE11 = () => isBrowser() && navigator.userAgent.includes("Trident") && navigator.userAgent.includes("rv:11.0");
|
|
251
|
+
var isEdge = () => UA() && UA().indexOf("edge/") > 0;
|
|
252
|
+
var isAndroid = () => UA() && UA().indexOf("android") > 0 || weexPlatform() === "android";
|
|
253
|
+
var isIOS = () => UA() && /iphone|ipad|ipod|ios/.test(UA()) || weexPlatform() === "ios";
|
|
254
|
+
var isChrome = () => UA() && /chrome\/\d+/.test(UA()) && !isEdge();
|
|
255
|
+
var isPhantomJS = () => UA() && /phantomjs/.test(UA());
|
|
256
|
+
var isFF = () => typeof UA() === "string" && UA().match(/firefox\/(\d+)/);
|
|
257
|
+
var isMobile = () => isBrowser() && navigator.userAgent.toLowerCase().includes("mobile");
|
|
258
|
+
var isObject = (value) => typeof value === "object" && !Array.isArray(value);
|
|
259
|
+
var isNumber = (value) => typeof value === "number";
|
|
260
|
+
var isString = (value) => typeof value === "string";
|
|
261
|
+
var isArray = (value) => Array.isArray(value);
|
|
262
|
+
var isNull = (value) => value === null;
|
|
263
|
+
var isPlainObject = (value) => typeof value === "object" && value !== null && value.constructor === Object;
|
|
264
|
+
var isFormData = (value) => isObject(value) && isBrowser() && value instanceof FormData;
|
|
265
|
+
var isWindow = (value) => typeof window !== "undefined" && toString.call(value) === "[object Window]";
|
|
266
|
+
|
|
267
|
+
// src/util/noop.ts
|
|
268
|
+
var noop = () => {
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
// src/util/p-pipe.ts
|
|
272
|
+
function pPipe(...functions) {
|
|
273
|
+
if (functions.length === 0)
|
|
274
|
+
throw new Error("Expected at least one argument");
|
|
275
|
+
return async (input) => {
|
|
276
|
+
let currentValue = input;
|
|
277
|
+
for (const function_ of functions)
|
|
278
|
+
currentValue = await function_(currentValue);
|
|
279
|
+
return currentValue;
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// src/util/pipe.ts
|
|
284
|
+
var pipe = (...fns) => fns.reduce((v, f) => f(v));
|
|
285
|
+
|
|
286
|
+
// src/util/util.ts
|
|
287
|
+
function arange(x1, x2, stp = 1, z = [], z0 = z.length) {
|
|
288
|
+
if (!x2)
|
|
289
|
+
x1 -= x2 = x1;
|
|
290
|
+
for (let z1 = z0 + Math.max(Math.ceil((++x2 - x1) / stp), 0); z0 < z1; x1 += stp)
|
|
291
|
+
z[z0++] = x1;
|
|
292
|
+
return z;
|
|
293
|
+
}
|
|
294
|
+
function loop(fn) {
|
|
295
|
+
async function next(ms) {
|
|
296
|
+
await delay(ms);
|
|
297
|
+
return fn(next);
|
|
298
|
+
}
|
|
299
|
+
return fn(next);
|
|
300
|
+
}
|
|
301
|
+
function riposte(...args) {
|
|
302
|
+
for (const [cond, value] of args) {
|
|
303
|
+
if (cond)
|
|
304
|
+
return value;
|
|
305
|
+
}
|
|
306
|
+
return void 0;
|
|
307
|
+
}
|
|
308
|
+
function unwrap(value) {
|
|
309
|
+
return typeof value === "function" ? value() : value;
|
|
310
|
+
}
|
|
311
|
+
function whenever(value, callback) {
|
|
312
|
+
return value ? callback(value) : void 0;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// src/size/index.ts
|
|
316
|
+
function formatUnit(value, unit = "px") {
|
|
317
|
+
if (!(isString(value) || isNumber(value)))
|
|
318
|
+
return "";
|
|
319
|
+
value = String(value);
|
|
320
|
+
return /\D/.test(value) ? value : value + unit;
|
|
321
|
+
}
|
|
322
|
+
function formatSize(dimension, unit) {
|
|
323
|
+
const _formatUnit = (value) => formatUnit(value, unit);
|
|
324
|
+
if (typeof dimension === "string" || typeof dimension === "number")
|
|
325
|
+
return { width: _formatUnit(dimension), height: _formatUnit(dimension) };
|
|
326
|
+
if (Array.isArray(dimension))
|
|
327
|
+
return { width: _formatUnit(dimension[0]), height: _formatUnit(dimension[1]) };
|
|
328
|
+
if (typeof dimension === "object")
|
|
329
|
+
return { width: _formatUnit(dimension.width), height: _formatUnit(dimension.height) };
|
|
330
|
+
return { width: "", height: "" };
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// src/string/index.ts
|
|
334
|
+
function cover(value, mode, symbol = "*") {
|
|
335
|
+
return value.slice(0, mode[0]) + symbol.repeat(mode[1]) + value.slice(-mode[2]);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// src/typeof/index.ts
|
|
339
|
+
function getTypeof(target) {
|
|
340
|
+
const value = Object.prototype.toString.call(target).slice(8, -1).toLocaleLowerCase();
|
|
341
|
+
return value;
|
|
342
|
+
}
|
|
343
|
+
function isTypeof(target, type) {
|
|
344
|
+
return getTypeof(target) === type;
|
|
345
|
+
}
|
|
346
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
347
|
+
0 && (module.exports = {
|
|
348
|
+
BIG_INTS,
|
|
349
|
+
Bignumber,
|
|
350
|
+
Deferred,
|
|
351
|
+
UA,
|
|
352
|
+
arange,
|
|
353
|
+
average,
|
|
354
|
+
compose,
|
|
355
|
+
cover,
|
|
356
|
+
decimal,
|
|
357
|
+
delay,
|
|
358
|
+
formToObject,
|
|
359
|
+
formatNumeric,
|
|
360
|
+
formatSize,
|
|
361
|
+
formatUnit,
|
|
362
|
+
getTypeof,
|
|
363
|
+
gt,
|
|
364
|
+
gte,
|
|
365
|
+
integer,
|
|
366
|
+
isAndroid,
|
|
367
|
+
isArray,
|
|
368
|
+
isBrowser,
|
|
369
|
+
isChrome,
|
|
370
|
+
isEdge,
|
|
371
|
+
isFF,
|
|
372
|
+
isFormData,
|
|
373
|
+
isIE,
|
|
374
|
+
isIE11,
|
|
375
|
+
isIE9,
|
|
376
|
+
isIOS,
|
|
377
|
+
isMobile,
|
|
378
|
+
isNull,
|
|
379
|
+
isNumber,
|
|
380
|
+
isObject,
|
|
381
|
+
isPhantomJS,
|
|
382
|
+
isPlainObject,
|
|
383
|
+
isString,
|
|
384
|
+
isTypeof,
|
|
385
|
+
isWeex,
|
|
386
|
+
isWindow,
|
|
387
|
+
loop,
|
|
388
|
+
lt,
|
|
389
|
+
lte,
|
|
390
|
+
noop,
|
|
391
|
+
numerfix,
|
|
392
|
+
objectToForm,
|
|
393
|
+
pPipe,
|
|
394
|
+
parseNumeric,
|
|
395
|
+
percentage,
|
|
396
|
+
pipe,
|
|
397
|
+
plus,
|
|
398
|
+
riposte,
|
|
399
|
+
unum,
|
|
400
|
+
unwrap,
|
|
401
|
+
weexPlatform,
|
|
402
|
+
whenever,
|
|
403
|
+
zerofill,
|
|
404
|
+
zeromove
|
|
405
|
+
});
|