@hairy/utils 1.30.0 → 1.32.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/dist/index.cjs CHANGED
@@ -31,11 +31,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
33
  BIG_INTS: () => BIG_INTS,
34
- BigNum: () => BigNum,
35
34
  Bignumber: () => import_bignumber.default,
36
35
  Deferred: () => Deferred,
37
36
  arange: () => arange,
38
37
  average: () => average,
38
+ bignum: () => bignum,
39
+ call: () => call,
39
40
  camelCase: () => camelCase,
40
41
  capitalCase: () => capitalCase,
41
42
  clone: () => clone_default,
@@ -49,13 +50,17 @@ __export(index_exports, {
49
50
  debounce: () => debounce_default,
50
51
  decimal: () => decimal,
51
52
  delay: () => delay,
53
+ dialsPhone: () => dialsPhone,
52
54
  dotCase: () => dotCase,
55
+ downloadBlobFile: () => downloadBlobFile,
56
+ downloadNetworkFile: () => downloadNetworkFile,
53
57
  find: () => find_default,
54
58
  formToObject: () => formToObject,
55
59
  formatNumeric: () => formatNumeric,
56
60
  formatSize: () => formatSize,
57
61
  formatUnit: () => formatUnit,
58
62
  getTypeof: () => getTypeof,
63
+ groupBy: () => groupBy_default,
59
64
  gt: () => gt,
60
65
  gte: () => gte,
61
66
  integer: () => integer,
@@ -102,8 +107,10 @@ __export(index_exports, {
102
107
  mergeWith: () => mergeWith_default,
103
108
  noCase: () => noCase,
104
109
  noop: () => noop2,
105
- numerfix: () => numerfix,
110
+ numfix: () => numfix,
106
111
  objectToForm: () => objectToForm,
112
+ off: () => off,
113
+ on: () => on,
107
114
  parseNumeric: () => parseNumeric,
108
115
  pascalCase: () => pascalCase,
109
116
  pascalSnakeCase: () => pascalSnakeCase,
@@ -114,8 +121,13 @@ __export(index_exports, {
114
121
  proxy: () => proxy,
115
122
  randomArray: () => randomArray,
116
123
  randomNumer: () => randomNumer,
124
+ readFileReader: () => readFileReader,
125
+ redirectTo: () => redirectTo,
117
126
  riposte: () => riposte,
127
+ selectImages: () => selectImages,
118
128
  sentenceCase: () => sentenceCase,
129
+ showOpenFilePicker: () => showOpenFilePicker,
130
+ showOpenImagePicker: () => showOpenImagePicker,
119
131
  snakeCase: () => snakeCase,
120
132
  to: () => to,
121
133
  trainCase: () => trainCase,
@@ -131,6 +143,81 @@ __export(index_exports, {
131
143
  });
132
144
  module.exports = __toCommonJS(index_exports);
133
145
 
146
+ // src/browser/file.ts
147
+ function showOpenFilePicker(option = {}) {
148
+ const { multiple = true, accept } = option;
149
+ return new Promise((resolve, reject) => {
150
+ const inputElement = document.createElement("input");
151
+ inputElement.type = "file";
152
+ inputElement.multiple = multiple;
153
+ accept && (inputElement.accept = accept);
154
+ inputElement.click();
155
+ const timer = setTimeout(reject, 20 * 1e3);
156
+ inputElement.addEventListener("change", (event) => {
157
+ const files = event.target.files;
158
+ if (files) {
159
+ resolve(Object.values(files));
160
+ clearTimeout(timer);
161
+ }
162
+ });
163
+ });
164
+ }
165
+ function showOpenImagePicker(options = {}) {
166
+ const { multiple = true } = options;
167
+ return showOpenFilePicker({ multiple, accept: "image/jpeg,image/x-png,image/gif" });
168
+ }
169
+ var selectImages = showOpenImagePicker;
170
+ function downloadBlobFile(data, name) {
171
+ const blob = new Blob([data]);
172
+ const link = document.createElement("a");
173
+ const url = window.URL.createObjectURL(blob);
174
+ link.href = url;
175
+ link.download = name;
176
+ link.click();
177
+ }
178
+ function downloadNetworkFile(url, name) {
179
+ const a = document.createElement("a");
180
+ name && (a.download = name);
181
+ a.href = url;
182
+ a.click();
183
+ }
184
+ function readFileReader(formType, file) {
185
+ return new Promise((resolve, reject) => {
186
+ if (typeof FileReader === "undefined") {
187
+ console.warn("\u5F53\u524D\u73AF\u5883\u4E0D\u652F\u6301\u4F7F\u7528 FileReader Api");
188
+ reject();
189
+ }
190
+ const reader = new FileReader();
191
+ reader[formType](file);
192
+ reader.onloadend = function() {
193
+ isNull(this.result) ? reject() : resolve(this.result);
194
+ };
195
+ });
196
+ }
197
+
198
+ // src/browser/util.ts
199
+ function redirectTo(url, target = "_blank") {
200
+ const link = document.createElement("a");
201
+ link.href = url;
202
+ link.target = target;
203
+ link.click();
204
+ link.remove();
205
+ }
206
+ function dialsPhone(phoneNumber) {
207
+ const aTag = document.createElement("a");
208
+ aTag.setAttribute("href", `tel:${phoneNumber}`);
209
+ aTag.setAttribute("target", "_blank");
210
+ aTag.click();
211
+ }
212
+ function on(obj, ...args) {
213
+ if (obj && obj.addEventListener)
214
+ obj.addEventListener(...args);
215
+ }
216
+ function off(obj, ...args) {
217
+ if (obj && obj.removeEventListener)
218
+ obj.removeEventListener(...args);
219
+ }
220
+
134
221
  // ../../node_modules/.pnpm/change-case@5.4.4/node_modules/change-case/dist/index.js
135
222
  var SPLIT_LOWER_UPPER_RE = /([\p{Ll}\d])(\p{Lu})/gu;
136
223
  var SPLIT_UPPER_UPPER_RE = /(\p{Lu})([\p{Lu}][\p{Ll}])/gu;
@@ -2442,6 +2529,17 @@ function baseIteratee(value) {
2442
2529
  }
2443
2530
  var baseIteratee_default = baseIteratee;
2444
2531
 
2532
+ // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_arrayAggregator.js
2533
+ function arrayAggregator(array, setter, iteratee, accumulator) {
2534
+ var index = -1, length = array == null ? 0 : array.length;
2535
+ while (++index < length) {
2536
+ var value = array[index];
2537
+ setter(accumulator, value, iteratee(value), array);
2538
+ }
2539
+ return accumulator;
2540
+ }
2541
+ var arrayAggregator_default = arrayAggregator;
2542
+
2445
2543
  // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_createBaseFor.js
2446
2544
  function createBaseFor(fromRight) {
2447
2545
  return function(object, iteratee, keysFunc) {
@@ -2461,6 +2559,54 @@ var createBaseFor_default = createBaseFor;
2461
2559
  var baseFor = createBaseFor_default();
2462
2560
  var baseFor_default = baseFor;
2463
2561
 
2562
+ // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseForOwn.js
2563
+ function baseForOwn(object, iteratee) {
2564
+ return object && baseFor_default(object, iteratee, keys_default);
2565
+ }
2566
+ var baseForOwn_default = baseForOwn;
2567
+
2568
+ // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_createBaseEach.js
2569
+ function createBaseEach(eachFunc, fromRight) {
2570
+ return function(collection, iteratee) {
2571
+ if (collection == null) {
2572
+ return collection;
2573
+ }
2574
+ if (!isArrayLike_default(collection)) {
2575
+ return eachFunc(collection, iteratee);
2576
+ }
2577
+ var length = collection.length, index = fromRight ? length : -1, iterable = Object(collection);
2578
+ while (fromRight ? index-- : ++index < length) {
2579
+ if (iteratee(iterable[index], index, iterable) === false) {
2580
+ break;
2581
+ }
2582
+ }
2583
+ return collection;
2584
+ };
2585
+ }
2586
+ var createBaseEach_default = createBaseEach;
2587
+
2588
+ // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseEach.js
2589
+ var baseEach = createBaseEach_default(baseForOwn_default);
2590
+ var baseEach_default = baseEach;
2591
+
2592
+ // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseAggregator.js
2593
+ function baseAggregator(collection, setter, iteratee, accumulator) {
2594
+ baseEach_default(collection, function(value, key, collection2) {
2595
+ setter(accumulator, value, iteratee(value), collection2);
2596
+ });
2597
+ return accumulator;
2598
+ }
2599
+ var baseAggregator_default = baseAggregator;
2600
+
2601
+ // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_createAggregator.js
2602
+ function createAggregator(setter, initializer) {
2603
+ return function(collection, iteratee) {
2604
+ var func = isArray_default(collection) ? arrayAggregator_default : baseAggregator_default, accumulator = initializer ? initializer() : {};
2605
+ return func(collection, setter, baseIteratee_default(iteratee, 2), accumulator);
2606
+ };
2607
+ }
2608
+ var createAggregator_default = createAggregator;
2609
+
2464
2610
  // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/now.js
2465
2611
  var now = function() {
2466
2612
  return root_default.Date.now();
@@ -2706,6 +2852,18 @@ var findIndex_default = findIndex;
2706
2852
  var find = createFind_default(findIndex_default);
2707
2853
  var find_default = find;
2708
2854
 
2855
+ // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/groupBy.js
2856
+ var objectProto17 = Object.prototype;
2857
+ var hasOwnProperty14 = objectProto17.hasOwnProperty;
2858
+ var groupBy = createAggregator_default(function(result, value, key) {
2859
+ if (hasOwnProperty14.call(result, key)) {
2860
+ result[key].push(value);
2861
+ } else {
2862
+ baseAssignValue_default(result, key, [value]);
2863
+ }
2864
+ });
2865
+ var groupBy_default = groupBy;
2866
+
2709
2867
  // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isString.js
2710
2868
  var stringTag5 = "[object String]";
2711
2869
  function isString(value) {
@@ -2749,8 +2907,8 @@ var isDate_default = isDate;
2749
2907
  // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isEmpty.js
2750
2908
  var mapTag7 = "[object Map]";
2751
2909
  var setTag7 = "[object Set]";
2752
- var objectProto17 = Object.prototype;
2753
- var hasOwnProperty14 = objectProto17.hasOwnProperty;
2910
+ var objectProto18 = Object.prototype;
2911
+ var hasOwnProperty15 = objectProto18.hasOwnProperty;
2754
2912
  function isEmpty(value) {
2755
2913
  if (value == null) {
2756
2914
  return true;
@@ -2766,7 +2924,7 @@ function isEmpty(value) {
2766
2924
  return !baseKeys_default(value).length;
2767
2925
  }
2768
2926
  for (var key in value) {
2769
- if (hasOwnProperty14.call(value, key)) {
2927
+ if (hasOwnProperty15.call(value, key)) {
2770
2928
  return false;
2771
2929
  }
2772
2930
  }
@@ -2808,10 +2966,10 @@ function isNative(value) {
2808
2966
  var isNative_default = isNative;
2809
2967
 
2810
2968
  // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isNull.js
2811
- function isNull(value) {
2969
+ function isNull2(value) {
2812
2970
  return value === null;
2813
2971
  }
2814
- var isNull_default = isNull;
2972
+ var isNull_default = isNull2;
2815
2973
 
2816
2974
  // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseIsRegExp.js
2817
2975
  var regexpTag5 = "[object RegExp]";
@@ -3016,40 +3174,43 @@ var BIG_INTS = {
3016
3174
  m: { v: 10 ** 6, d: 7, n: "m" },
3017
3175
  k: { v: 10 ** 3, d: 4, n: "k" }
3018
3176
  };
3019
- function BigNum(num = "0") {
3020
- return new import_bignumber.default(numerfix(num));
3177
+ function bignum(n = "0") {
3178
+ return new import_bignumber.default(numfix(n));
3021
3179
  }
3022
- function gte(num, n) {
3023
- return BigNum(num).gte(BigNum(n));
3180
+ function numfix(value) {
3181
+ return Number.isNaN(Number(value)) || value.toString() === "NaN" ? "0" : String(value);
3024
3182
  }
3025
- function gt(num, n) {
3026
- return BigNum(num).gt(BigNum(n));
3183
+ function gte(a, b) {
3184
+ return bignum(a).gte(bignum(b));
3027
3185
  }
3028
- function lte(num, n) {
3029
- return BigNum(num).lte(BigNum(n));
3186
+ function gt(a, b) {
3187
+ return bignum(a).gt(bignum(b));
3030
3188
  }
3031
- function lt(num, n) {
3032
- return BigNum(num).lt(BigNum(n));
3189
+ function lte(a, b) {
3190
+ return bignum(a).lte(bignum(b));
3191
+ }
3192
+ function lt(a, b) {
3193
+ return bignum(a).lt(bignum(b));
3033
3194
  }
3034
3195
  function plus(array, options) {
3035
3196
  const rounding = options?.r || import_bignumber.default.ROUND_DOWN;
3036
3197
  const decimal2 = options?.d || 0;
3037
- return array.filter((v) => BigNum(v).gt(0)).reduce((t, v) => t.plus(BigNum(v)), BigNum(0)).toFixed(decimal2, rounding);
3198
+ return array.filter((v) => bignum(v).gt(0)).reduce((t, v) => t.plus(bignum(v)), bignum(0)).toFixed(decimal2, rounding);
3038
3199
  }
3039
3200
  function average(array, options) {
3040
3201
  const rounding = options?.r || import_bignumber.default.ROUND_DOWN;
3041
3202
  const decimal2 = options?.d || 0;
3042
3203
  if (array.length === 0)
3043
3204
  return "0";
3044
- return BigNum(plus(array)).div(array.length).toFixed(decimal2, rounding);
3205
+ return bignum(plus(array)).div(array.length).toFixed(decimal2, rounding);
3045
3206
  }
3046
3207
  function percentage(total, count, options) {
3047
3208
  options ??= { d: 3, r: import_bignumber.default.ROUND_DOWN };
3048
3209
  const rounding = options?.r || import_bignumber.default.ROUND_DOWN;
3049
3210
  const decimal2 = options?.d || 3;
3050
- if (BigNum(total).lte(0) || BigNum(count).lte(0))
3211
+ if (bignum(total).lte(0) || bignum(count).lte(0))
3051
3212
  return "0";
3052
- return BigNum(count).div(BigNum(total)).times(100).toFixed(decimal2, rounding);
3213
+ return bignum(count).div(bignum(total)).times(100).toFixed(decimal2, rounding);
3053
3214
  }
3054
3215
  function zerofill(value, n = 2, type = "positive") {
3055
3216
  const _value = integer(value);
@@ -3065,15 +3226,11 @@ function zerofill(value, n = 2, type = "positive") {
3065
3226
  function zeromove(value) {
3066
3227
  return value.toString().replace(/\.?0+$/, "");
3067
3228
  }
3068
- function numerfix(value) {
3069
- const _isNaN = Number.isNaN(Number(value)) || value.toString() === "NaN";
3070
- return _isNaN ? "0" : String(value);
3071
- }
3072
3229
  function integer(value) {
3073
- return new import_bignumber.default(numerfix(value)).toFixed(0);
3230
+ return new import_bignumber.default(numfix(value)).toFixed(0);
3074
3231
  }
3075
3232
  function decimal(value, n = 2) {
3076
- let [integer2, decimal2] = numerfix(value).split(".");
3233
+ let [integer2, decimal2] = numfix(value).split(".");
3077
3234
  if (n <= 0)
3078
3235
  return integer2;
3079
3236
  if (!decimal2)
@@ -3091,7 +3248,7 @@ function parseNumeric(num, delimiters = ["t", "b", "m"]) {
3091
3248
  ];
3092
3249
  let options;
3093
3250
  for (const analy of mappings) {
3094
- const opts = analy && analy(BigNum(num).toFixed(0));
3251
+ const opts = analy && analy(bignum(num).toFixed(0));
3095
3252
  opts && (options = opts);
3096
3253
  }
3097
3254
  return options || { v: 1, d: 0, n: "" };
@@ -3104,7 +3261,7 @@ function formatNumeric(value = "0", options) {
3104
3261
  decimals = 2
3105
3262
  } = options || {};
3106
3263
  const config = parseNumeric(value, delimiters || []);
3107
- let number = BigNum(value).div(config.v).toFormat(decimals, rounding, {
3264
+ let number = bignum(value).div(config.v).toFormat(decimals, rounding, {
3108
3265
  decimalSeparator: ".",
3109
3266
  groupSeparator: ",",
3110
3267
  groupSize: 3,
@@ -3349,14 +3506,18 @@ function unwrap(value) {
3349
3506
  function whenever(value, callback) {
3350
3507
  return value ? callback(value) : void 0;
3351
3508
  }
3509
+ function call(fn, ...args) {
3510
+ return fn(...args);
3511
+ }
3352
3512
  // Annotate the CommonJS export names for ESM import in node:
3353
3513
  0 && (module.exports = {
3354
3514
  BIG_INTS,
3355
- BigNum,
3356
3515
  Bignumber,
3357
3516
  Deferred,
3358
3517
  arange,
3359
3518
  average,
3519
+ bignum,
3520
+ call,
3360
3521
  camelCase,
3361
3522
  capitalCase,
3362
3523
  clone,
@@ -3370,13 +3531,17 @@ function whenever(value, callback) {
3370
3531
  debounce,
3371
3532
  decimal,
3372
3533
  delay,
3534
+ dialsPhone,
3373
3535
  dotCase,
3536
+ downloadBlobFile,
3537
+ downloadNetworkFile,
3374
3538
  find,
3375
3539
  formToObject,
3376
3540
  formatNumeric,
3377
3541
  formatSize,
3378
3542
  formatUnit,
3379
3543
  getTypeof,
3544
+ groupBy,
3380
3545
  gt,
3381
3546
  gte,
3382
3547
  integer,
@@ -3423,8 +3588,10 @@ function whenever(value, callback) {
3423
3588
  mergeWith,
3424
3589
  noCase,
3425
3590
  noop,
3426
- numerfix,
3591
+ numfix,
3427
3592
  objectToForm,
3593
+ off,
3594
+ on,
3428
3595
  parseNumeric,
3429
3596
  pascalCase,
3430
3597
  pascalSnakeCase,
@@ -3435,8 +3602,13 @@ function whenever(value, callback) {
3435
3602
  proxy,
3436
3603
  randomArray,
3437
3604
  randomNumer,
3605
+ readFileReader,
3606
+ redirectTo,
3438
3607
  riposte,
3608
+ selectImages,
3439
3609
  sentenceCase,
3610
+ showOpenFilePicker,
3611
+ showOpenImagePicker,
3440
3612
  snakeCase,
3441
3613
  to,
3442
3614
  trainCase,
package/dist/index.d.ts CHANGED
@@ -1,78 +1,52 @@
1
- export { clone, cloneDeep, cloneDeepWith, cloneWith, concat, debounce, find, isArray, isArrayLike, isBoolean, isDate, isEmpty, isEqual, isError, isFunction, isNaN, isNative, isNull, isNumber, isObject, isPlainObject, isString, isUndefined, join, keys, merge, mergeWith, truncate, uniq, uniqBy, uniqWith, values } from 'lodash-es';
1
+ export { clone, cloneDeep, cloneDeepWith, cloneWith, concat, debounce, find, groupBy, isArray, isArrayLike, isBoolean, isDate, isEmpty, isEqual, isError, isFunction, isNaN, isNative, isNull, isNumber, isObject, isPlainObject, isString, isUndefined, join, keys, merge, mergeWith, truncate, uniq, uniqBy, uniqWith, values } from 'lodash-es';
2
2
  import Bignumber from 'bignumber.js';
3
3
  export { default as Bignumber } from 'bignumber.js';
4
4
 
5
- /**
6
- * Supported locale values. Use `false` to ignore locale.
7
- * Defaults to `undefined`, which uses the host environment.
8
- */
9
- type Locale = string[] | string | false | undefined;
10
- /**
11
- * Options used for converting strings to pascal/camel case.
12
- */
13
- interface PascalCaseOptions extends Options {
14
- mergeAmbiguousCharacters?: boolean;
5
+ interface OpenFilePickerOptions {
6
+ /**
7
+ * select multiple files
8
+ */
9
+ multiple?: boolean;
10
+ /**
11
+ * Choose the default format for the file
12
+ */
13
+ accept?: string;
15
14
  }
16
15
  /**
17
- * Options used for converting strings to any case.
16
+ * Select multiple files
18
17
  */
19
- interface Options {
20
- locale?: Locale;
21
- split?: (value: string) => string[];
22
- /** @deprecated Pass `split: splitSeparateNumbers` instead. */
23
- separateNumbers?: boolean;
24
- delimiter?: string;
25
- prefixCharacters?: string;
26
- suffixCharacters?: string;
18
+ declare function showOpenFilePicker(option?: OpenFilePickerOptions): Promise<File[]>;
19
+ interface OpenImagePickerOptions {
20
+ /**
21
+ * select multiple images
22
+ */
23
+ multiple?: boolean;
27
24
  }
28
25
  /**
29
- * Convert a string to space separated lower case (`foo bar`).
30
- */
31
- declare function noCase(input: string, options?: Options): string;
32
- /**
33
- * Convert a string to camel case (`fooBar`).
34
- */
35
- declare function camelCase(input: string, options?: PascalCaseOptions): string;
36
- /**
37
- * Convert a string to pascal case (`FooBar`).
38
- */
39
- declare function pascalCase(input: string, options?: PascalCaseOptions): string;
40
- /**
41
- * Convert a string to pascal snake case (`Foo_Bar`).
42
- */
43
- declare function pascalSnakeCase(input: string, options?: Options): string;
44
- /**
45
- * Convert a string to capital case (`Foo Bar`).
26
+ * Select multiple images
46
27
  */
47
- declare function capitalCase(input: string, options?: Options): string;
28
+ declare function showOpenImagePicker(options?: OpenImagePickerOptions): Promise<File[]>;
29
+ /** @deprecated use chooseFile */
30
+ declare const selectImages: typeof showOpenImagePicker;
48
31
  /**
49
- * Convert a string to constant case (`FOO_BAR`).
32
+ * Generate Blob | string file and download it
33
+ * @param data Blob data, or string
34
+ * @param name file name
50
35
  */
51
- declare function constantCase(input: string, options?: Options): string;
36
+ declare function downloadBlobFile(data: Blob | string, name: string): void;
52
37
  /**
53
- * Convert a string to dot case (`foo.bar`).
38
+ * Download network files
39
+ * @param url Download link
40
+ * @param name file name
54
41
  */
55
- declare function dotCase(input: string, options?: Options): string;
42
+ declare function downloadNetworkFile(url: string, name?: string): void;
43
+ type ReaderType = 'readAsArrayBuffer' | 'readAsBinaryString' | 'readAsDataURL' | 'readAsText';
56
44
  /**
57
- * Convert a string to kebab case (`foo-bar`).
58
- */
59
- declare function kebabCase(input: string, options?: Options): string;
60
- /**
61
- * Convert a string to path case (`foo/bar`).
62
- */
63
- declare function pathCase(input: string, options?: Options): string;
64
- /**
65
- * Convert a string to path case (`Foo bar`).
45
+ * Read File file
46
+ * @param formType Transform type
47
+ * @param file file object
66
48
  */
67
- declare function sentenceCase(input: string, options?: Options): string;
68
- /**
69
- * Convert a string to snake case (`foo_bar`).
70
- */
71
- declare function snakeCase(input: string, options?: Options): string;
72
- /**
73
- * Convert a string to header case (`Foo-Bar`).
74
- */
75
- declare function trainCase(input: string, options?: Options): string;
49
+ declare function readFileReader<T extends ReaderType>(formType: T, file: File): Promise<T extends "readAsArrayBuffer" ? ArrayBuffer : string>;
76
50
 
77
51
  type Numeric = string | number | bigint;
78
52
  interface DynamicObject {
@@ -135,6 +109,83 @@ type Option<L extends Key = 'label', V extends Key = 'value', C extends Key = 'c
135
109
  [P in C]?: Option<L, V, C>[];
136
110
  };
137
111
 
112
+ declare function redirectTo(url: string, target?: string): void;
113
+ declare function dialsPhone(phoneNumber: string): void;
114
+ declare function on<T extends Window | Document | HTMLElement | EventTarget>(obj: T | null, ...args: Parameters<T['addEventListener']> | [string, Fn$1 | null, ...any]): void;
115
+ declare function off<T extends Window | Document | HTMLElement | EventTarget>(obj: T | null, ...args: Parameters<T['removeEventListener']> | [string, Fn$1 | null, ...any]): void;
116
+
117
+ /**
118
+ * Supported locale values. Use `false` to ignore locale.
119
+ * Defaults to `undefined`, which uses the host environment.
120
+ */
121
+ type Locale = string[] | string | false | undefined;
122
+ /**
123
+ * Options used for converting strings to pascal/camel case.
124
+ */
125
+ interface PascalCaseOptions extends Options {
126
+ mergeAmbiguousCharacters?: boolean;
127
+ }
128
+ /**
129
+ * Options used for converting strings to any case.
130
+ */
131
+ interface Options {
132
+ locale?: Locale;
133
+ split?: (value: string) => string[];
134
+ /** @deprecated Pass `split: splitSeparateNumbers` instead. */
135
+ separateNumbers?: boolean;
136
+ delimiter?: string;
137
+ prefixCharacters?: string;
138
+ suffixCharacters?: string;
139
+ }
140
+ /**
141
+ * Convert a string to space separated lower case (`foo bar`).
142
+ */
143
+ declare function noCase(input: string, options?: Options): string;
144
+ /**
145
+ * Convert a string to camel case (`fooBar`).
146
+ */
147
+ declare function camelCase(input: string, options?: PascalCaseOptions): string;
148
+ /**
149
+ * Convert a string to pascal case (`FooBar`).
150
+ */
151
+ declare function pascalCase(input: string, options?: PascalCaseOptions): string;
152
+ /**
153
+ * Convert a string to pascal snake case (`Foo_Bar`).
154
+ */
155
+ declare function pascalSnakeCase(input: string, options?: Options): string;
156
+ /**
157
+ * Convert a string to capital case (`Foo Bar`).
158
+ */
159
+ declare function capitalCase(input: string, options?: Options): string;
160
+ /**
161
+ * Convert a string to constant case (`FOO_BAR`).
162
+ */
163
+ declare function constantCase(input: string, options?: Options): string;
164
+ /**
165
+ * Convert a string to dot case (`foo.bar`).
166
+ */
167
+ declare function dotCase(input: string, options?: Options): string;
168
+ /**
169
+ * Convert a string to kebab case (`foo-bar`).
170
+ */
171
+ declare function kebabCase(input: string, options?: Options): string;
172
+ /**
173
+ * Convert a string to path case (`foo/bar`).
174
+ */
175
+ declare function pathCase(input: string, options?: Options): string;
176
+ /**
177
+ * Convert a string to path case (`Foo bar`).
178
+ */
179
+ declare function sentenceCase(input: string, options?: Options): string;
180
+ /**
181
+ * Convert a string to snake case (`foo_bar`).
182
+ */
183
+ declare function snakeCase(input: string, options?: Options): string;
184
+ /**
185
+ * Convert a string to header case (`Foo-Bar`).
186
+ */
187
+ declare function trainCase(input: string, options?: Options): string;
188
+
138
189
  declare const BIG_INTS: {
139
190
  t: {
140
191
  v: number;
@@ -179,11 +230,12 @@ interface FormatNumericOptions {
179
230
  zeromove?: boolean;
180
231
  format?: Bignumber.Format;
181
232
  }
182
- declare function BigNum(num?: Numberish): Bignumber;
183
- declare function gte(num: Numberish, n: Numberish): boolean;
184
- declare function gt(num: Numberish, n: Numberish): boolean;
185
- declare function lte(num: Numberish, n: Numberish): boolean;
186
- declare function lt(num: Numberish, n: Numberish): boolean;
233
+ declare function bignum(n?: Numberish): Bignumber;
234
+ declare function numfix(value: any): string;
235
+ declare function gte(a: Numberish, b: Numberish): boolean;
236
+ declare function gt(a: Numberish, b: Numberish): boolean;
237
+ declare function lte(a: Numberish, b: Numberish): boolean;
238
+ declare function lt(a: Numberish, b: Numberish): boolean;
187
239
  declare function plus(array: Numberish[], options?: DecimalOptions): string;
188
240
  declare function average(array: Numberish[], options?: DecimalOptions): string;
189
241
  /**
@@ -200,7 +252,6 @@ declare function percentage(total: Numberish, count: Numberish, options?: Decima
200
252
  */
201
253
  declare function zerofill(value: Numberish, n?: number, type?: 'positive' | 'reverse'): Numberish;
202
254
  declare function zeromove(value: Numberish): string;
203
- declare function numerfix(value: any): string;
204
255
  /**
205
256
  * format as a positive integer
206
257
  * @param value
@@ -476,5 +527,6 @@ declare function arange(x1: number, x2?: number, stp?: number, z?: number[], z0?
476
527
  declare function riposte<T>(...args: [cond: boolean, value: T][]): T;
477
528
  declare function unwrap<T extends object>(value: T | (() => T)): T;
478
529
  declare function whenever<T, C extends (value: Exclude<T, null | undefined>) => any>(value: T, callback: C): ReturnType<C> | undefined;
530
+ declare function call<T extends Fn$1<any>>(fn: T, ...args: Parameters<T>): ReturnType<T>;
479
531
 
480
- export { type AnyFn, type ArgumentsType, type Arrayable, type Awaitable, BIG_INTS, BigNum, type BooleanLike, type ConstructorType, type DecimalOptions, type DeepKeyof, type DeepMerge, type DeepPartial, type DeepReadonly, type DeepReplace, type DeepRequired, Deferred, type Delimiter, type Dimension, type DynamicObject, type ElementOf, type Fn$1 as Fn, type FormatGroupOptions, type FormatNumericOptions, type IfAny, type IsAny, type Key, type Looper, type MergeInsertions, type Noop, type Nullable, type NumberObject, type Numberish, type Numeric, type NumericObject, type Option, type PromiseFn, type PromiseType, type Promisify, type StringObject, type SymbolObject, type Typeof, arange, average, camelCase, capitalCase, compose, constantCase, cover, decimal, delay, dotCase, formToObject, formatNumeric, formatSize, formatUnit, getTypeof, gt, gte, integer, isAndroid, isBrowser, isChrome, isEdge, isFF, isFormData, isIE, isIE11, isIE9, isIOS, isMobile, isPhantomJS, isTruthy, isTypeof, isWeex, isWindow, jsonTryParse, kebabCase, loop, lt, lte, noCase, noop, numerfix, objectToForm, parseNumeric, pascalCase, pascalSnakeCase, pathCase, percentage, pipe, plus, proxy, randomArray, randomNumer, riposte, sentenceCase, snakeCase, to, trainCase, unwrap, whenever, zerofill, zeromove };
532
+ export { type AnyFn, type ArgumentsType, type Arrayable, type Awaitable, BIG_INTS, type BooleanLike, type ConstructorType, type DecimalOptions, type DeepKeyof, type DeepMerge, type DeepPartial, type DeepReadonly, type DeepReplace, type DeepRequired, Deferred, type Delimiter, type Dimension, type DynamicObject, type ElementOf, type Fn$1 as Fn, type FormatGroupOptions, type FormatNumericOptions, type IfAny, type IsAny, type Key, type Looper, type MergeInsertions, type Noop, type Nullable, type NumberObject, type Numberish, type Numeric, type NumericObject, type OpenFilePickerOptions, type OpenImagePickerOptions, type Option, type PromiseFn, type PromiseType, type Promisify, type ReaderType, type StringObject, type SymbolObject, type Typeof, arange, average, bignum, call, camelCase, capitalCase, compose, constantCase, cover, decimal, delay, dialsPhone, dotCase, downloadBlobFile, downloadNetworkFile, formToObject, formatNumeric, formatSize, formatUnit, getTypeof, gt, gte, integer, isAndroid, isBrowser, isChrome, isEdge, isFF, isFormData, isIE, isIE11, isIE9, isIOS, isMobile, isPhantomJS, isTruthy, isTypeof, isWeex, isWindow, jsonTryParse, kebabCase, loop, lt, lte, noCase, noop, numfix, objectToForm, off, on, parseNumeric, pascalCase, pascalSnakeCase, pathCase, percentage, pipe, plus, proxy, randomArray, randomNumer, readFileReader, redirectTo, riposte, selectImages, sentenceCase, showOpenFilePicker, showOpenImagePicker, snakeCase, to, trainCase, unwrap, whenever, zerofill, zeromove };
@@ -1,5 +1,80 @@
1
1
  "use strict";
2
2
  (() => {
3
+ // src/browser/file.ts
4
+ function showOpenFilePicker(option = {}) {
5
+ const { multiple = true, accept } = option;
6
+ return new Promise((resolve, reject) => {
7
+ const inputElement = document.createElement("input");
8
+ inputElement.type = "file";
9
+ inputElement.multiple = multiple;
10
+ accept && (inputElement.accept = accept);
11
+ inputElement.click();
12
+ const timer = setTimeout(reject, 20 * 1e3);
13
+ inputElement.addEventListener("change", (event) => {
14
+ const files = event.target.files;
15
+ if (files) {
16
+ resolve(Object.values(files));
17
+ clearTimeout(timer);
18
+ }
19
+ });
20
+ });
21
+ }
22
+ function showOpenImagePicker(options = {}) {
23
+ const { multiple = true } = options;
24
+ return showOpenFilePicker({ multiple, accept: "image/jpeg,image/x-png,image/gif" });
25
+ }
26
+ var selectImages = showOpenImagePicker;
27
+ function downloadBlobFile(data, name) {
28
+ const blob = new Blob([data]);
29
+ const link = document.createElement("a");
30
+ const url = window.URL.createObjectURL(blob);
31
+ link.href = url;
32
+ link.download = name;
33
+ link.click();
34
+ }
35
+ function downloadNetworkFile(url, name) {
36
+ const a = document.createElement("a");
37
+ name && (a.download = name);
38
+ a.href = url;
39
+ a.click();
40
+ }
41
+ function readFileReader(formType, file) {
42
+ return new Promise((resolve, reject) => {
43
+ if (typeof FileReader === "undefined") {
44
+ console.warn("\u5F53\u524D\u73AF\u5883\u4E0D\u652F\u6301\u4F7F\u7528 FileReader Api");
45
+ reject();
46
+ }
47
+ const reader = new FileReader();
48
+ reader[formType](file);
49
+ reader.onloadend = function() {
50
+ isNull(this.result) ? reject() : resolve(this.result);
51
+ };
52
+ });
53
+ }
54
+
55
+ // src/browser/util.ts
56
+ function redirectTo(url, target = "_blank") {
57
+ const link = document.createElement("a");
58
+ link.href = url;
59
+ link.target = target;
60
+ link.click();
61
+ link.remove();
62
+ }
63
+ function dialsPhone(phoneNumber) {
64
+ const aTag = document.createElement("a");
65
+ aTag.setAttribute("href", `tel:${phoneNumber}`);
66
+ aTag.setAttribute("target", "_blank");
67
+ aTag.click();
68
+ }
69
+ function on(obj, ...args) {
70
+ if (obj && obj.addEventListener)
71
+ obj.addEventListener(...args);
72
+ }
73
+ function off(obj, ...args) {
74
+ if (obj && obj.removeEventListener)
75
+ obj.removeEventListener(...args);
76
+ }
77
+
3
78
  // ../../node_modules/.pnpm/change-case@5.4.4/node_modules/change-case/dist/index.js
4
79
  var SPLIT_LOWER_UPPER_RE = /([\p{Ll}\d])(\p{Lu})/gu;
5
80
  var SPLIT_UPPER_UPPER_RE = /(\p{Lu})([\p{Lu}][\p{Ll}])/gu;
@@ -2311,6 +2386,17 @@
2311
2386
  }
2312
2387
  var baseIteratee_default = baseIteratee;
2313
2388
 
2389
+ // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_arrayAggregator.js
2390
+ function arrayAggregator(array, setter, iteratee, accumulator) {
2391
+ var index = -1, length = array == null ? 0 : array.length;
2392
+ while (++index < length) {
2393
+ var value = array[index];
2394
+ setter(accumulator, value, iteratee(value), array);
2395
+ }
2396
+ return accumulator;
2397
+ }
2398
+ var arrayAggregator_default = arrayAggregator;
2399
+
2314
2400
  // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_createBaseFor.js
2315
2401
  function createBaseFor(fromRight) {
2316
2402
  return function(object, iteratee, keysFunc) {
@@ -2330,6 +2416,54 @@
2330
2416
  var baseFor = createBaseFor_default();
2331
2417
  var baseFor_default = baseFor;
2332
2418
 
2419
+ // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseForOwn.js
2420
+ function baseForOwn(object, iteratee) {
2421
+ return object && baseFor_default(object, iteratee, keys_default);
2422
+ }
2423
+ var baseForOwn_default = baseForOwn;
2424
+
2425
+ // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_createBaseEach.js
2426
+ function createBaseEach(eachFunc, fromRight) {
2427
+ return function(collection, iteratee) {
2428
+ if (collection == null) {
2429
+ return collection;
2430
+ }
2431
+ if (!isArrayLike_default(collection)) {
2432
+ return eachFunc(collection, iteratee);
2433
+ }
2434
+ var length = collection.length, index = fromRight ? length : -1, iterable = Object(collection);
2435
+ while (fromRight ? index-- : ++index < length) {
2436
+ if (iteratee(iterable[index], index, iterable) === false) {
2437
+ break;
2438
+ }
2439
+ }
2440
+ return collection;
2441
+ };
2442
+ }
2443
+ var createBaseEach_default = createBaseEach;
2444
+
2445
+ // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseEach.js
2446
+ var baseEach = createBaseEach_default(baseForOwn_default);
2447
+ var baseEach_default = baseEach;
2448
+
2449
+ // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseAggregator.js
2450
+ function baseAggregator(collection, setter, iteratee, accumulator) {
2451
+ baseEach_default(collection, function(value, key, collection2) {
2452
+ setter(accumulator, value, iteratee(value), collection2);
2453
+ });
2454
+ return accumulator;
2455
+ }
2456
+ var baseAggregator_default = baseAggregator;
2457
+
2458
+ // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_createAggregator.js
2459
+ function createAggregator(setter, initializer) {
2460
+ return function(collection, iteratee) {
2461
+ var func = isArray_default(collection) ? arrayAggregator_default : baseAggregator_default, accumulator = initializer ? initializer() : {};
2462
+ return func(collection, setter, baseIteratee_default(iteratee, 2), accumulator);
2463
+ };
2464
+ }
2465
+ var createAggregator_default = createAggregator;
2466
+
2333
2467
  // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/now.js
2334
2468
  var now = function() {
2335
2469
  return root_default.Date.now();
@@ -2575,6 +2709,18 @@
2575
2709
  var find = createFind_default(findIndex_default);
2576
2710
  var find_default = find;
2577
2711
 
2712
+ // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/groupBy.js
2713
+ var objectProto17 = Object.prototype;
2714
+ var hasOwnProperty14 = objectProto17.hasOwnProperty;
2715
+ var groupBy = createAggregator_default(function(result, value, key) {
2716
+ if (hasOwnProperty14.call(result, key)) {
2717
+ result[key].push(value);
2718
+ } else {
2719
+ baseAssignValue_default(result, key, [value]);
2720
+ }
2721
+ });
2722
+ var groupBy_default = groupBy;
2723
+
2578
2724
  // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isString.js
2579
2725
  var stringTag5 = "[object String]";
2580
2726
  function isString(value) {
@@ -2618,8 +2764,8 @@
2618
2764
  // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isEmpty.js
2619
2765
  var mapTag7 = "[object Map]";
2620
2766
  var setTag7 = "[object Set]";
2621
- var objectProto17 = Object.prototype;
2622
- var hasOwnProperty14 = objectProto17.hasOwnProperty;
2767
+ var objectProto18 = Object.prototype;
2768
+ var hasOwnProperty15 = objectProto18.hasOwnProperty;
2623
2769
  function isEmpty(value) {
2624
2770
  if (value == null) {
2625
2771
  return true;
@@ -2635,7 +2781,7 @@
2635
2781
  return !baseKeys_default(value).length;
2636
2782
  }
2637
2783
  for (var key in value) {
2638
- if (hasOwnProperty14.call(value, key)) {
2784
+ if (hasOwnProperty15.call(value, key)) {
2639
2785
  return false;
2640
2786
  }
2641
2787
  }
@@ -2677,10 +2823,10 @@
2677
2823
  var isNative_default = isNative;
2678
2824
 
2679
2825
  // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isNull.js
2680
- function isNull(value) {
2826
+ function isNull2(value) {
2681
2827
  return value === null;
2682
2828
  }
2683
- var isNull_default = isNull;
2829
+ var isNull_default = isNull2;
2684
2830
 
2685
2831
  // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseIsRegExp.js
2686
2832
  var regexpTag5 = "[object RegExp]";
@@ -4228,40 +4374,43 @@
4228
4374
  m: { v: 10 ** 6, d: 7, n: "m" },
4229
4375
  k: { v: 10 ** 3, d: 4, n: "k" }
4230
4376
  };
4231
- function BigNum(num = "0") {
4232
- return new bignumber_default(numerfix(num));
4377
+ function bignum(n = "0") {
4378
+ return new bignumber_default(numfix(n));
4233
4379
  }
4234
- function gte(num, n) {
4235
- return BigNum(num).gte(BigNum(n));
4380
+ function numfix(value) {
4381
+ return Number.isNaN(Number(value)) || value.toString() === "NaN" ? "0" : String(value);
4236
4382
  }
4237
- function gt(num, n) {
4238
- return BigNum(num).gt(BigNum(n));
4383
+ function gte(a, b) {
4384
+ return bignum(a).gte(bignum(b));
4239
4385
  }
4240
- function lte(num, n) {
4241
- return BigNum(num).lte(BigNum(n));
4386
+ function gt(a, b) {
4387
+ return bignum(a).gt(bignum(b));
4242
4388
  }
4243
- function lt(num, n) {
4244
- return BigNum(num).lt(BigNum(n));
4389
+ function lte(a, b) {
4390
+ return bignum(a).lte(bignum(b));
4391
+ }
4392
+ function lt(a, b) {
4393
+ return bignum(a).lt(bignum(b));
4245
4394
  }
4246
4395
  function plus(array, options) {
4247
4396
  const rounding = options?.r || bignumber_default.ROUND_DOWN;
4248
4397
  const decimal2 = options?.d || 0;
4249
- return array.filter((v) => BigNum(v).gt(0)).reduce((t, v) => t.plus(BigNum(v)), BigNum(0)).toFixed(decimal2, rounding);
4398
+ return array.filter((v) => bignum(v).gt(0)).reduce((t, v) => t.plus(bignum(v)), bignum(0)).toFixed(decimal2, rounding);
4250
4399
  }
4251
4400
  function average(array, options) {
4252
4401
  const rounding = options?.r || bignumber_default.ROUND_DOWN;
4253
4402
  const decimal2 = options?.d || 0;
4254
4403
  if (array.length === 0)
4255
4404
  return "0";
4256
- return BigNum(plus(array)).div(array.length).toFixed(decimal2, rounding);
4405
+ return bignum(plus(array)).div(array.length).toFixed(decimal2, rounding);
4257
4406
  }
4258
4407
  function percentage(total, count, options) {
4259
4408
  options ??= { d: 3, r: bignumber_default.ROUND_DOWN };
4260
4409
  const rounding = options?.r || bignumber_default.ROUND_DOWN;
4261
4410
  const decimal2 = options?.d || 3;
4262
- if (BigNum(total).lte(0) || BigNum(count).lte(0))
4411
+ if (bignum(total).lte(0) || bignum(count).lte(0))
4263
4412
  return "0";
4264
- return BigNum(count).div(BigNum(total)).times(100).toFixed(decimal2, rounding);
4413
+ return bignum(count).div(bignum(total)).times(100).toFixed(decimal2, rounding);
4265
4414
  }
4266
4415
  function zerofill(value, n = 2, type = "positive") {
4267
4416
  const _value = integer(value);
@@ -4277,15 +4426,11 @@
4277
4426
  function zeromove(value) {
4278
4427
  return value.toString().replace(/\.?0+$/, "");
4279
4428
  }
4280
- function numerfix(value) {
4281
- const _isNaN = Number.isNaN(Number(value)) || value.toString() === "NaN";
4282
- return _isNaN ? "0" : String(value);
4283
- }
4284
4429
  function integer(value) {
4285
- return new bignumber_default(numerfix(value)).toFixed(0);
4430
+ return new bignumber_default(numfix(value)).toFixed(0);
4286
4431
  }
4287
4432
  function decimal(value, n = 2) {
4288
- let [integer2, decimal2] = numerfix(value).split(".");
4433
+ let [integer2, decimal2] = numfix(value).split(".");
4289
4434
  if (n <= 0)
4290
4435
  return integer2;
4291
4436
  if (!decimal2)
@@ -4303,7 +4448,7 @@
4303
4448
  ];
4304
4449
  let options;
4305
4450
  for (const analy of mappings) {
4306
- const opts = analy && analy(BigNum(num).toFixed(0));
4451
+ const opts = analy && analy(bignum(num).toFixed(0));
4307
4452
  opts && (options = opts);
4308
4453
  }
4309
4454
  return options || { v: 1, d: 0, n: "" };
@@ -4316,7 +4461,7 @@
4316
4461
  decimals = 2
4317
4462
  } = options || {};
4318
4463
  const config = parseNumeric(value, delimiters || []);
4319
- let number = BigNum(value).div(config.v).toFormat(decimals, rounding, {
4464
+ let number = bignum(value).div(config.v).toFormat(decimals, rounding, {
4320
4465
  decimalSeparator: ".",
4321
4466
  groupSeparator: ",",
4322
4467
  groupSize: 3,
@@ -4561,6 +4706,9 @@
4561
4706
  function whenever(value, callback) {
4562
4707
  return value ? callback(value) : void 0;
4563
4708
  }
4709
+ function call(fn, ...args) {
4710
+ return fn(...args);
4711
+ }
4564
4712
  })();
4565
4713
  /*! Bundled license information:
4566
4714
 
package/dist/index.js CHANGED
@@ -1,3 +1,78 @@
1
+ // src/browser/file.ts
2
+ function showOpenFilePicker(option = {}) {
3
+ const { multiple = true, accept } = option;
4
+ return new Promise((resolve, reject) => {
5
+ const inputElement = document.createElement("input");
6
+ inputElement.type = "file";
7
+ inputElement.multiple = multiple;
8
+ accept && (inputElement.accept = accept);
9
+ inputElement.click();
10
+ const timer = setTimeout(reject, 20 * 1e3);
11
+ inputElement.addEventListener("change", (event) => {
12
+ const files = event.target.files;
13
+ if (files) {
14
+ resolve(Object.values(files));
15
+ clearTimeout(timer);
16
+ }
17
+ });
18
+ });
19
+ }
20
+ function showOpenImagePicker(options = {}) {
21
+ const { multiple = true } = options;
22
+ return showOpenFilePicker({ multiple, accept: "image/jpeg,image/x-png,image/gif" });
23
+ }
24
+ var selectImages = showOpenImagePicker;
25
+ function downloadBlobFile(data, name) {
26
+ const blob = new Blob([data]);
27
+ const link = document.createElement("a");
28
+ const url = window.URL.createObjectURL(blob);
29
+ link.href = url;
30
+ link.download = name;
31
+ link.click();
32
+ }
33
+ function downloadNetworkFile(url, name) {
34
+ const a = document.createElement("a");
35
+ name && (a.download = name);
36
+ a.href = url;
37
+ a.click();
38
+ }
39
+ function readFileReader(formType, file) {
40
+ return new Promise((resolve, reject) => {
41
+ if (typeof FileReader === "undefined") {
42
+ console.warn("\u5F53\u524D\u73AF\u5883\u4E0D\u652F\u6301\u4F7F\u7528 FileReader Api");
43
+ reject();
44
+ }
45
+ const reader = new FileReader();
46
+ reader[formType](file);
47
+ reader.onloadend = function() {
48
+ isNull(this.result) ? reject() : resolve(this.result);
49
+ };
50
+ });
51
+ }
52
+
53
+ // src/browser/util.ts
54
+ function redirectTo(url, target = "_blank") {
55
+ const link = document.createElement("a");
56
+ link.href = url;
57
+ link.target = target;
58
+ link.click();
59
+ link.remove();
60
+ }
61
+ function dialsPhone(phoneNumber) {
62
+ const aTag = document.createElement("a");
63
+ aTag.setAttribute("href", `tel:${phoneNumber}`);
64
+ aTag.setAttribute("target", "_blank");
65
+ aTag.click();
66
+ }
67
+ function on(obj, ...args) {
68
+ if (obj && obj.addEventListener)
69
+ obj.addEventListener(...args);
70
+ }
71
+ function off(obj, ...args) {
72
+ if (obj && obj.removeEventListener)
73
+ obj.removeEventListener(...args);
74
+ }
75
+
1
76
  // ../../node_modules/.pnpm/change-case@5.4.4/node_modules/change-case/dist/index.js
2
77
  var SPLIT_LOWER_UPPER_RE = /([\p{Ll}\d])(\p{Lu})/gu;
3
78
  var SPLIT_UPPER_UPPER_RE = /(\p{Lu})([\p{Lu}][\p{Ll}])/gu;
@@ -2309,6 +2384,17 @@ function baseIteratee(value) {
2309
2384
  }
2310
2385
  var baseIteratee_default = baseIteratee;
2311
2386
 
2387
+ // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_arrayAggregator.js
2388
+ function arrayAggregator(array, setter, iteratee, accumulator) {
2389
+ var index = -1, length = array == null ? 0 : array.length;
2390
+ while (++index < length) {
2391
+ var value = array[index];
2392
+ setter(accumulator, value, iteratee(value), array);
2393
+ }
2394
+ return accumulator;
2395
+ }
2396
+ var arrayAggregator_default = arrayAggregator;
2397
+
2312
2398
  // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_createBaseFor.js
2313
2399
  function createBaseFor(fromRight) {
2314
2400
  return function(object, iteratee, keysFunc) {
@@ -2328,6 +2414,54 @@ var createBaseFor_default = createBaseFor;
2328
2414
  var baseFor = createBaseFor_default();
2329
2415
  var baseFor_default = baseFor;
2330
2416
 
2417
+ // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseForOwn.js
2418
+ function baseForOwn(object, iteratee) {
2419
+ return object && baseFor_default(object, iteratee, keys_default);
2420
+ }
2421
+ var baseForOwn_default = baseForOwn;
2422
+
2423
+ // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_createBaseEach.js
2424
+ function createBaseEach(eachFunc, fromRight) {
2425
+ return function(collection, iteratee) {
2426
+ if (collection == null) {
2427
+ return collection;
2428
+ }
2429
+ if (!isArrayLike_default(collection)) {
2430
+ return eachFunc(collection, iteratee);
2431
+ }
2432
+ var length = collection.length, index = fromRight ? length : -1, iterable = Object(collection);
2433
+ while (fromRight ? index-- : ++index < length) {
2434
+ if (iteratee(iterable[index], index, iterable) === false) {
2435
+ break;
2436
+ }
2437
+ }
2438
+ return collection;
2439
+ };
2440
+ }
2441
+ var createBaseEach_default = createBaseEach;
2442
+
2443
+ // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseEach.js
2444
+ var baseEach = createBaseEach_default(baseForOwn_default);
2445
+ var baseEach_default = baseEach;
2446
+
2447
+ // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseAggregator.js
2448
+ function baseAggregator(collection, setter, iteratee, accumulator) {
2449
+ baseEach_default(collection, function(value, key, collection2) {
2450
+ setter(accumulator, value, iteratee(value), collection2);
2451
+ });
2452
+ return accumulator;
2453
+ }
2454
+ var baseAggregator_default = baseAggregator;
2455
+
2456
+ // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_createAggregator.js
2457
+ function createAggregator(setter, initializer) {
2458
+ return function(collection, iteratee) {
2459
+ var func = isArray_default(collection) ? arrayAggregator_default : baseAggregator_default, accumulator = initializer ? initializer() : {};
2460
+ return func(collection, setter, baseIteratee_default(iteratee, 2), accumulator);
2461
+ };
2462
+ }
2463
+ var createAggregator_default = createAggregator;
2464
+
2331
2465
  // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/now.js
2332
2466
  var now = function() {
2333
2467
  return root_default.Date.now();
@@ -2573,6 +2707,18 @@ var findIndex_default = findIndex;
2573
2707
  var find = createFind_default(findIndex_default);
2574
2708
  var find_default = find;
2575
2709
 
2710
+ // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/groupBy.js
2711
+ var objectProto17 = Object.prototype;
2712
+ var hasOwnProperty14 = objectProto17.hasOwnProperty;
2713
+ var groupBy = createAggregator_default(function(result, value, key) {
2714
+ if (hasOwnProperty14.call(result, key)) {
2715
+ result[key].push(value);
2716
+ } else {
2717
+ baseAssignValue_default(result, key, [value]);
2718
+ }
2719
+ });
2720
+ var groupBy_default = groupBy;
2721
+
2576
2722
  // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isString.js
2577
2723
  var stringTag5 = "[object String]";
2578
2724
  function isString(value) {
@@ -2616,8 +2762,8 @@ var isDate_default = isDate;
2616
2762
  // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isEmpty.js
2617
2763
  var mapTag7 = "[object Map]";
2618
2764
  var setTag7 = "[object Set]";
2619
- var objectProto17 = Object.prototype;
2620
- var hasOwnProperty14 = objectProto17.hasOwnProperty;
2765
+ var objectProto18 = Object.prototype;
2766
+ var hasOwnProperty15 = objectProto18.hasOwnProperty;
2621
2767
  function isEmpty(value) {
2622
2768
  if (value == null) {
2623
2769
  return true;
@@ -2633,7 +2779,7 @@ function isEmpty(value) {
2633
2779
  return !baseKeys_default(value).length;
2634
2780
  }
2635
2781
  for (var key in value) {
2636
- if (hasOwnProperty14.call(value, key)) {
2782
+ if (hasOwnProperty15.call(value, key)) {
2637
2783
  return false;
2638
2784
  }
2639
2785
  }
@@ -2675,10 +2821,10 @@ function isNative(value) {
2675
2821
  var isNative_default = isNative;
2676
2822
 
2677
2823
  // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isNull.js
2678
- function isNull(value) {
2824
+ function isNull2(value) {
2679
2825
  return value === null;
2680
2826
  }
2681
- var isNull_default = isNull;
2827
+ var isNull_default = isNull2;
2682
2828
 
2683
2829
  // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseIsRegExp.js
2684
2830
  var regexpTag5 = "[object RegExp]";
@@ -2883,40 +3029,43 @@ var BIG_INTS = {
2883
3029
  m: { v: 10 ** 6, d: 7, n: "m" },
2884
3030
  k: { v: 10 ** 3, d: 4, n: "k" }
2885
3031
  };
2886
- function BigNum(num = "0") {
2887
- return new Bignumber(numerfix(num));
3032
+ function bignum(n = "0") {
3033
+ return new Bignumber(numfix(n));
2888
3034
  }
2889
- function gte(num, n) {
2890
- return BigNum(num).gte(BigNum(n));
3035
+ function numfix(value) {
3036
+ return Number.isNaN(Number(value)) || value.toString() === "NaN" ? "0" : String(value);
2891
3037
  }
2892
- function gt(num, n) {
2893
- return BigNum(num).gt(BigNum(n));
3038
+ function gte(a, b) {
3039
+ return bignum(a).gte(bignum(b));
2894
3040
  }
2895
- function lte(num, n) {
2896
- return BigNum(num).lte(BigNum(n));
3041
+ function gt(a, b) {
3042
+ return bignum(a).gt(bignum(b));
2897
3043
  }
2898
- function lt(num, n) {
2899
- return BigNum(num).lt(BigNum(n));
3044
+ function lte(a, b) {
3045
+ return bignum(a).lte(bignum(b));
3046
+ }
3047
+ function lt(a, b) {
3048
+ return bignum(a).lt(bignum(b));
2900
3049
  }
2901
3050
  function plus(array, options) {
2902
3051
  const rounding = options?.r || Bignumber.ROUND_DOWN;
2903
3052
  const decimal2 = options?.d || 0;
2904
- return array.filter((v) => BigNum(v).gt(0)).reduce((t, v) => t.plus(BigNum(v)), BigNum(0)).toFixed(decimal2, rounding);
3053
+ return array.filter((v) => bignum(v).gt(0)).reduce((t, v) => t.plus(bignum(v)), bignum(0)).toFixed(decimal2, rounding);
2905
3054
  }
2906
3055
  function average(array, options) {
2907
3056
  const rounding = options?.r || Bignumber.ROUND_DOWN;
2908
3057
  const decimal2 = options?.d || 0;
2909
3058
  if (array.length === 0)
2910
3059
  return "0";
2911
- return BigNum(plus(array)).div(array.length).toFixed(decimal2, rounding);
3060
+ return bignum(plus(array)).div(array.length).toFixed(decimal2, rounding);
2912
3061
  }
2913
3062
  function percentage(total, count, options) {
2914
3063
  options ??= { d: 3, r: Bignumber.ROUND_DOWN };
2915
3064
  const rounding = options?.r || Bignumber.ROUND_DOWN;
2916
3065
  const decimal2 = options?.d || 3;
2917
- if (BigNum(total).lte(0) || BigNum(count).lte(0))
3066
+ if (bignum(total).lte(0) || bignum(count).lte(0))
2918
3067
  return "0";
2919
- return BigNum(count).div(BigNum(total)).times(100).toFixed(decimal2, rounding);
3068
+ return bignum(count).div(bignum(total)).times(100).toFixed(decimal2, rounding);
2920
3069
  }
2921
3070
  function zerofill(value, n = 2, type = "positive") {
2922
3071
  const _value = integer(value);
@@ -2932,15 +3081,11 @@ function zerofill(value, n = 2, type = "positive") {
2932
3081
  function zeromove(value) {
2933
3082
  return value.toString().replace(/\.?0+$/, "");
2934
3083
  }
2935
- function numerfix(value) {
2936
- const _isNaN = Number.isNaN(Number(value)) || value.toString() === "NaN";
2937
- return _isNaN ? "0" : String(value);
2938
- }
2939
3084
  function integer(value) {
2940
- return new Bignumber(numerfix(value)).toFixed(0);
3085
+ return new Bignumber(numfix(value)).toFixed(0);
2941
3086
  }
2942
3087
  function decimal(value, n = 2) {
2943
- let [integer2, decimal2] = numerfix(value).split(".");
3088
+ let [integer2, decimal2] = numfix(value).split(".");
2944
3089
  if (n <= 0)
2945
3090
  return integer2;
2946
3091
  if (!decimal2)
@@ -2958,7 +3103,7 @@ function parseNumeric(num, delimiters = ["t", "b", "m"]) {
2958
3103
  ];
2959
3104
  let options;
2960
3105
  for (const analy of mappings) {
2961
- const opts = analy && analy(BigNum(num).toFixed(0));
3106
+ const opts = analy && analy(bignum(num).toFixed(0));
2962
3107
  opts && (options = opts);
2963
3108
  }
2964
3109
  return options || { v: 1, d: 0, n: "" };
@@ -2971,7 +3116,7 @@ function formatNumeric(value = "0", options) {
2971
3116
  decimals = 2
2972
3117
  } = options || {};
2973
3118
  const config = parseNumeric(value, delimiters || []);
2974
- let number = BigNum(value).div(config.v).toFormat(decimals, rounding, {
3119
+ let number = bignum(value).div(config.v).toFormat(decimals, rounding, {
2975
3120
  decimalSeparator: ".",
2976
3121
  groupSeparator: ",",
2977
3122
  groupSize: 3,
@@ -3216,13 +3361,17 @@ function unwrap(value) {
3216
3361
  function whenever(value, callback) {
3217
3362
  return value ? callback(value) : void 0;
3218
3363
  }
3364
+ function call(fn, ...args) {
3365
+ return fn(...args);
3366
+ }
3219
3367
  export {
3220
3368
  BIG_INTS,
3221
- BigNum,
3222
3369
  Bignumber,
3223
3370
  Deferred,
3224
3371
  arange,
3225
3372
  average,
3373
+ bignum,
3374
+ call,
3226
3375
  camelCase,
3227
3376
  capitalCase,
3228
3377
  clone_default as clone,
@@ -3236,13 +3385,17 @@ export {
3236
3385
  debounce_default as debounce,
3237
3386
  decimal,
3238
3387
  delay,
3388
+ dialsPhone,
3239
3389
  dotCase,
3390
+ downloadBlobFile,
3391
+ downloadNetworkFile,
3240
3392
  find_default as find,
3241
3393
  formToObject,
3242
3394
  formatNumeric,
3243
3395
  formatSize,
3244
3396
  formatUnit,
3245
3397
  getTypeof,
3398
+ groupBy_default as groupBy,
3246
3399
  gt,
3247
3400
  gte,
3248
3401
  integer,
@@ -3289,8 +3442,10 @@ export {
3289
3442
  mergeWith_default as mergeWith,
3290
3443
  noCase,
3291
3444
  noop2 as noop,
3292
- numerfix,
3445
+ numfix,
3293
3446
  objectToForm,
3447
+ off,
3448
+ on,
3294
3449
  parseNumeric,
3295
3450
  pascalCase,
3296
3451
  pascalSnakeCase,
@@ -3301,8 +3456,13 @@ export {
3301
3456
  proxy,
3302
3457
  randomArray,
3303
3458
  randomNumer,
3459
+ readFileReader,
3460
+ redirectTo,
3304
3461
  riposte,
3462
+ selectImages,
3305
3463
  sentenceCase,
3464
+ showOpenFilePicker,
3465
+ showOpenImagePicker,
3306
3466
  snakeCase,
3307
3467
  to,
3308
3468
  trainCase,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hairy/utils",
3
3
  "type": "module",
4
- "version": "1.30.0",
4
+ "version": "1.32.0",
5
5
  "description": "Library for anywhere",
6
6
  "author": "Hairyf <wwu710632@gmail.com>",
7
7
  "license": "MIT",