@daysnap/utils 0.1.32 → 0.1.34

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.
@@ -0,0 +1,26 @@
1
+ import {
2
+ isObject
3
+ } from "./chunk-XCSSSEK2.js";
4
+
5
+ // src/merge.ts
6
+ function merge(target, ...sources) {
7
+ sources.forEach((source) => {
8
+ if (!isObject(source)) {
9
+ return;
10
+ }
11
+ Object.keys(source).forEach((key) => {
12
+ const sourceValue = source[key];
13
+ const targetValue = target[key];
14
+ if (isObject(targetValue) && isObject(sourceValue)) {
15
+ target[key] = merge(targetValue, sourceValue);
16
+ } else {
17
+ target[key] = sourceValue;
18
+ }
19
+ });
20
+ });
21
+ return target;
22
+ }
23
+
24
+ export {
25
+ merge
26
+ };
@@ -0,0 +1,29 @@
1
+ import {
2
+ isPromiseLike
3
+ } from "./chunk-P5GEZD4D.js";
4
+
5
+ // src/createWithToast.ts
6
+ function createWithToast(options = {}) {
7
+ const { onError } = options;
8
+ return (fn) => {
9
+ return function(...args) {
10
+ try {
11
+ const result = fn.apply(this, args);
12
+ if (isPromiseLike(result)) {
13
+ return Promise.resolve(result).catch((err) => {
14
+ onError?.(err);
15
+ throw "cancel:handled";
16
+ });
17
+ }
18
+ return result;
19
+ } catch (error) {
20
+ onError?.(error);
21
+ throw "cancel:handled";
22
+ }
23
+ };
24
+ };
25
+ }
26
+
27
+ export {
28
+ createWithToast
29
+ };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * 处理错误信息可以弹出提示
3
+ */
4
+ interface CreateWithToastOptions {
5
+ /** error */
6
+ onError?: (err: unknown) => void;
7
+ }
8
+ declare function createWithToast(options?: CreateWithToastOptions): <T extends (...args: any) => any>(fn: T) => T;
9
+
10
+ export { type CreateWithToastOptions, createWithToast };
@@ -0,0 +1,7 @@
1
+ import {
2
+ createWithToast
3
+ } from "./chunk-YUYAN2IU.js";
4
+ import "./chunk-P5GEZD4D.js";
5
+ export {
6
+ createWithToast
7
+ };
package/es/index.d.ts CHANGED
@@ -16,6 +16,7 @@ export { createFactory } from './createFactory.js';
16
16
  export { colorGenByHash } from './createHexColorByHash.js';
17
17
  export { createLinearFunction } from './createLinearFunction.js';
18
18
  export { createWithLoading } from './createWithLoading.js';
19
+ export { CreateWithToastOptions, createWithToast } from './createWithToast.js';
19
20
  export { crlfToBr, filterCRLF } from './crlfToBr.js';
20
21
  export { debounce } from './debounce.js';
21
22
  export { atob, btoa } from './decode.js';
@@ -97,6 +98,7 @@ export { kebabCase } from './kebabCase.js';
97
98
  export { lfToBr } from './lfToBr.js';
98
99
  export { listGenerator } from './listGenerator.js';
99
100
  export { makePhoneCall } from './makePhoneCall.js';
101
+ export { merge } from './merge.js';
100
102
  export { mousewheel } from './mousewheel.js';
101
103
  export { nf } from './nf.js';
102
104
  export { normalizeDate } from './normalizeDate.js';
package/es/index.js CHANGED
@@ -1,10 +1,24 @@
1
+ import {
2
+ withPreventConsecutiveClicks
3
+ } from "./chunk-S6UH3LMW.js";
1
4
  import {
2
5
  getCache,
3
6
  getLocal
4
7
  } from "./chunk-LG2TIXRB.js";
8
+ import {
9
+ factory
10
+ } from "./chunk-M6B3UGFI.js";
5
11
  import {
6
12
  Storage
7
13
  } from "./chunk-SBMDM4VS.js";
14
+ import {
15
+ throttle,
16
+ throttleLeading,
17
+ throttleTrailing
18
+ } from "./chunk-ASYHV5B7.js";
19
+ import {
20
+ toCDB
21
+ } from "./chunk-J2Y5ZZA3.js";
8
22
  import {
9
23
  toDBC
10
24
  } from "./chunk-ONTP5SDE.js";
@@ -25,11 +39,11 @@ import {
25
39
  withCache
26
40
  } from "./chunk-ZI7MCCMB.js";
27
41
  import {
28
- withPreventConsecutiveClicks
29
- } from "./chunk-S6UH3LMW.js";
42
+ scrollToTop
43
+ } from "./chunk-P7QW362C.js";
30
44
  import {
31
- factory
32
- } from "./chunk-M6B3UGFI.js";
45
+ setScrollTop
46
+ } from "./chunk-BULTIEJG.js";
33
47
  import {
34
48
  sounds
35
49
  } from "./chunk-ODZQXCS4.js";
@@ -46,13 +60,14 @@ import {
46
60
  stringifyQueryString
47
61
  } from "./chunk-TSFGLHCP.js";
48
62
  import {
49
- throttle,
50
- throttleLeading,
51
- throttleTrailing
52
- } from "./chunk-ASYHV5B7.js";
63
+ pickBy
64
+ } from "./chunk-2OEHQMIN.js";
53
65
  import {
54
- toCDB
55
- } from "./chunk-J2Y5ZZA3.js";
66
+ Poller
67
+ } from "./chunk-QT2EM4X2.js";
68
+ import {
69
+ sleep
70
+ } from "./chunk-YUID5DXT.js";
56
71
  import {
57
72
  replaceCrlf
58
73
  } from "./chunk-GNGSV7F7.js";
@@ -72,11 +87,11 @@ import {
72
87
  roundUpToNearestInteger
73
88
  } from "./chunk-OSACZX5M.js";
74
89
  import {
75
- scrollToTop
76
- } from "./chunk-P7QW362C.js";
90
+ parseError
91
+ } from "./chunk-EJMUWNXI.js";
77
92
  import {
78
- setScrollTop
79
- } from "./chunk-BULTIEJG.js";
93
+ parseNumberString
94
+ } from "./chunk-ANY3ULZW.js";
80
95
  import {
81
96
  parseObject
82
97
  } from "./chunk-M3NXNABN.js";
@@ -93,14 +108,8 @@ import {
93
108
  pick
94
109
  } from "./chunk-IPAT3N4P.js";
95
110
  import {
96
- pickBy
97
- } from "./chunk-2OEHQMIN.js";
98
- import {
99
- Poller
100
- } from "./chunk-QT2EM4X2.js";
101
- import {
102
- sleep
103
- } from "./chunk-YUID5DXT.js";
111
+ normalizePath
112
+ } from "./chunk-CMP4T3ZH.js";
104
113
  import {
105
114
  numberToLetter
106
115
  } from "./chunk-U7BK2TT3.js";
@@ -120,11 +129,8 @@ import {
120
129
  parseDecimalString
121
130
  } from "./chunk-N6ZMEBBU.js";
122
131
  import {
123
- parseError
124
- } from "./chunk-EJMUWNXI.js";
125
- import {
126
- parseNumberString
127
- } from "./chunk-ANY3ULZW.js";
132
+ isWindow
133
+ } from "./chunk-QYCMY2T4.js";
128
134
  import {
129
135
  kebabCase
130
136
  } from "./chunk-IPIA4Z65.js";
@@ -134,6 +140,9 @@ import {
134
140
  import {
135
141
  makePhoneCall
136
142
  } from "./chunk-GYOXULKV.js";
143
+ import {
144
+ merge
145
+ } from "./chunk-B6HL3YHK.js";
137
146
  import {
138
147
  mousewheel
139
148
  } from "./chunk-GVPHHNDY.js";
@@ -141,8 +150,8 @@ import {
141
150
  nf
142
151
  } from "./chunk-PAERS3SW.js";
143
152
  import {
144
- normalizePath
145
- } from "./chunk-CMP4T3ZH.js";
153
+ isRegExp
154
+ } from "./chunk-Y4V5R7XA.js";
146
155
  import {
147
156
  isType
148
157
  } from "./chunk-5EVWQVDV.js";
@@ -160,8 +169,8 @@ import {
160
169
  isWeChatMiniProgram
161
170
  } from "./chunk-SQ3L6IQW.js";
162
171
  import {
163
- isWindow
164
- } from "./chunk-QYCMY2T4.js";
172
+ isNativeFunction
173
+ } from "./chunk-4N33UIAB.js";
165
174
  import {
166
175
  isNotEmpty
167
176
  } from "./chunk-YYH4INGK.js";
@@ -175,11 +184,8 @@ import {
175
184
  isPromise
176
185
  } from "./chunk-LJ4CEJ5C.js";
177
186
  import {
178
- isPromiseLike
179
- } from "./chunk-P5GEZD4D.js";
180
- import {
181
- isRegExp
182
- } from "./chunk-Y4V5R7XA.js";
187
+ isIE
188
+ } from "./chunk-QTKWJHHW.js";
183
189
  import {
184
190
  isIOS
185
191
  } from "./chunk-5BVFSCCX.js";
@@ -202,8 +208,8 @@ import {
202
208
  isMobile
203
209
  } from "./chunk-L52JSZDZ.js";
204
210
  import {
205
- isNativeFunction
206
- } from "./chunk-4N33UIAB.js";
211
+ isChinese
212
+ } from "./chunk-KYLBUCGC.js";
207
213
  import {
208
214
  isDate
209
215
  } from "./chunk-A4YRDVZ4.js";
@@ -213,9 +219,6 @@ import {
213
219
  import {
214
220
  isError
215
221
  } from "./chunk-6UGTRW2S.js";
216
- import {
217
- isIE
218
- } from "./chunk-QTKWJHHW.js";
219
222
  import {
220
223
  insertLink
221
224
  } from "./chunk-FIHEVMN6.js";
@@ -235,8 +238,8 @@ import {
235
238
  isBoolean
236
239
  } from "./chunk-ZWXX326Y.js";
237
240
  import {
238
- isChinese
239
- } from "./chunk-KYLBUCGC.js";
241
+ getRandomColor
242
+ } from "./chunk-D7OBO7J6.js";
240
243
  import {
241
244
  getRandomNumber
242
245
  } from "./chunk-TZ2EQSRZ.js";
@@ -258,6 +261,9 @@ import {
258
261
  import {
259
262
  inBrowser
260
263
  } from "./chunk-ZDRIUWKX.js";
264
+ import {
265
+ formatPathParams
266
+ } from "./chunk-JG33SHAK.js";
261
267
  import {
262
268
  getBlobByUrl
263
269
  } from "./chunk-4QMOXXPL.js";
@@ -283,8 +289,8 @@ import {
283
289
  listGenerator
284
290
  } from "./chunk-2SUOLGG5.js";
285
291
  import {
286
- getRandomColor
287
- } from "./chunk-D7OBO7J6.js";
292
+ filterString
293
+ } from "./chunk-KJX7IWF5.js";
288
294
  import {
289
295
  formatDateToZN
290
296
  } from "./chunk-DW5GIB4A.js";
@@ -316,8 +322,8 @@ import {
316
322
  parsePath
317
323
  } from "./chunk-VMJHCN3P.js";
318
324
  import {
319
- formatPathParams
320
- } from "./chunk-JG33SHAK.js";
325
+ eventBus
326
+ } from "./chunk-HYCW7PL5.js";
321
327
  import {
322
328
  exitFullscreen
323
329
  } from "./chunk-GV4IJGB2.js";
@@ -357,15 +363,18 @@ import {
357
363
  import {
358
364
  filterPhone
359
365
  } from "./chunk-5Z3KN6O2.js";
360
- import {
361
- filterString
362
- } from "./chunk-KJX7IWF5.js";
363
366
  import {
364
367
  createLinearFunction
365
368
  } from "./chunk-53VI5KBY.js";
366
369
  import {
367
370
  createWithLoading
368
371
  } from "./chunk-OC64NXZ2.js";
372
+ import {
373
+ createWithToast
374
+ } from "./chunk-YUYAN2IU.js";
375
+ import {
376
+ isPromiseLike
377
+ } from "./chunk-P5GEZD4D.js";
369
378
  import {
370
379
  crlfToBr,
371
380
  filterCRLF
@@ -383,9 +392,6 @@ import {
383
392
  import {
384
393
  each
385
394
  } from "./chunk-K4SQME6B.js";
386
- import {
387
- eventBus
388
- } from "./chunk-HYCW7PL5.js";
389
395
  import {
390
396
  clamp
391
397
  } from "./chunk-W52BRMSD.js";
@@ -464,6 +470,7 @@ export {
464
470
  createLinearFunction,
465
471
  createTrapInstance,
466
472
  createWithLoading,
473
+ createWithToast,
467
474
  crlfToBr,
468
475
  debounce,
469
476
  downloadFile,
@@ -549,6 +556,7 @@ export {
549
556
  lfToBr,
550
557
  listGenerator,
551
558
  makePhoneCall,
559
+ merge,
552
560
  mousewheel,
553
561
  nf,
554
562
  normalizeDate,
package/es/merge.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 深度合并对象,返回新对象
3
+ */
4
+ declare function merge<R extends Record<string, any> = any>(target: Record<string, any>, ...sources: Record<string, any>[]): R;
5
+
6
+ export { merge };
package/es/merge.js ADDED
@@ -0,0 +1,7 @@
1
+ import {
2
+ merge
3
+ } from "./chunk-B6HL3YHK.js";
4
+ import "./chunk-XCSSSEK2.js";
5
+ export {
6
+ merge
7
+ };
@@ -2,12 +2,12 @@ import {
2
2
  getCache,
3
3
  getLocal
4
4
  } from "../chunk-LG2TIXRB.js";
5
- import {
6
- Storage
7
- } from "../chunk-SBMDM4VS.js";
8
5
  import {
9
6
  factory
10
7
  } from "../chunk-M6B3UGFI.js";
8
+ import {
9
+ Storage
10
+ } from "../chunk-SBMDM4VS.js";
11
11
  import "../chunk-CSZ7G34M.js";
12
12
  import "../chunk-XCSSSEK2.js";
13
13
  export {
@@ -0,0 +1,26 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkOSEQ7XR6cjs = require('./chunk-OSEQ7XR6.cjs');
4
+
5
+ // src/merge.ts
6
+ function merge(target, ...sources) {
7
+ sources.forEach((source) => {
8
+ if (!_chunkOSEQ7XR6cjs.isObject.call(void 0, source)) {
9
+ return;
10
+ }
11
+ Object.keys(source).forEach((key) => {
12
+ const sourceValue = source[key];
13
+ const targetValue = target[key];
14
+ if (_chunkOSEQ7XR6cjs.isObject.call(void 0, targetValue) && _chunkOSEQ7XR6cjs.isObject.call(void 0, sourceValue)) {
15
+ target[key] = merge(targetValue, sourceValue);
16
+ } else {
17
+ target[key] = sourceValue;
18
+ }
19
+ });
20
+ });
21
+ return target;
22
+ }
23
+
24
+
25
+
26
+ exports.merge = merge;
@@ -0,0 +1,29 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+ var _chunkN455COPHcjs = require('./chunk-N455COPH.cjs');
4
+
5
+ // src/createWithToast.ts
6
+ function createWithToast(options = {}) {
7
+ const { onError } = options;
8
+ return (fn) => {
9
+ return function(...args) {
10
+ try {
11
+ const result = fn.apply(this, args);
12
+ if (_chunkN455COPHcjs.isPromiseLike.call(void 0, result)) {
13
+ return Promise.resolve(result).catch((err) => {
14
+ _optionalChain([onError, 'optionalCall', _ => _(err)]);
15
+ throw "cancel:handled";
16
+ });
17
+ }
18
+ return result;
19
+ } catch (error) {
20
+ _optionalChain([onError, 'optionalCall', _2 => _2(error)]);
21
+ throw "cancel:handled";
22
+ }
23
+ };
24
+ };
25
+ }
26
+
27
+
28
+
29
+ exports.createWithToast = createWithToast;
@@ -0,0 +1,7 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunk6TPHE34Jcjs = require('./chunk-6TPHE34J.cjs');
4
+ require('./chunk-N455COPH.cjs');
5
+
6
+
7
+ exports.createWithToast = _chunk6TPHE34Jcjs.createWithToast;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * 处理错误信息可以弹出提示
3
+ */
4
+ interface CreateWithToastOptions {
5
+ /** error */
6
+ onError?: (err: unknown) => void;
7
+ }
8
+ declare function createWithToast(options?: CreateWithToastOptions): <T extends (...args: any) => any>(fn: T) => T;
9
+
10
+ export { type CreateWithToastOptions, createWithToast };