@deot/helper-utils 1.1.4 → 1.1.6
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/README.md +21 -21
- package/dist/index.cjs +6 -6
- package/dist/index.d.ts +7 -5
- package/dist/index.iife.js +6 -6
- package/dist/index.js +6 -7
- package/dist/index.umd.cjs +6 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,25 +12,25 @@ import { Utils } from '@deot/helper';
|
|
|
12
12
|
|
|
13
13
|
| 方法 | 说明 |
|
|
14
14
|
| ------------------------------------------------------------------ | ------------------------------ |
|
|
15
|
-
| [asterisk]
|
|
16
|
-
| [autoCatch]
|
|
17
|
-
| [canvasToImage]
|
|
18
|
-
| [cloneDeepEasier]
|
|
19
|
-
| [compressImage]
|
|
20
|
-
| [dataURLToFile]
|
|
21
|
-
| [debounce]
|
|
22
|
-
| [def]
|
|
23
|
-
| [flattenDecodeURIComponent]
|
|
24
|
-
| [flattenJSONParse]
|
|
25
|
-
| [getPropByPath]
|
|
26
|
-
| [getUid]
|
|
27
|
-
| [hasOwn]
|
|
28
|
-
| [numberToUnit]
|
|
29
|
-
| [preZero]
|
|
30
|
-
| [raf]
|
|
31
|
-
| [random]
|
|
32
|
-
| [sleep]
|
|
33
|
-
| [throttle]
|
|
34
|
-
| [genterateString]
|
|
35
|
-
| [toPromise]
|
|
15
|
+
| [asterisk](./src/asterisk.ts) | 文字加`*` |
|
|
16
|
+
| [autoCatch](./src/auto-catch.ts) | 捕获异常 |
|
|
17
|
+
| [canvasToImage](./src/canvas-to-image.ts) | 转图片信息 |
|
|
18
|
+
| [cloneDeepEasier](./src/clone-deep-easier.ts) | 深拷贝 |
|
|
19
|
+
| [compressImage](./src/compress-image.ts) | 压缩图片 |
|
|
20
|
+
| [dataURLToFile](./src/dataURL-to-file.ts) | base64转文件 |
|
|
21
|
+
| [debounce](./src/debounce.ts) | 防抖 |
|
|
22
|
+
| [def](./src/def.ts) | 定义 |
|
|
23
|
+
| [flattenDecodeURIComponent](./src/flatten-decode-uri-component.ts) | 深度解码 |
|
|
24
|
+
| [flattenJSONParse](./src/flatten-json-parse.ts) | 深度反序列化 |
|
|
25
|
+
| [getPropByPath](./src/get-prop-by-path.ts) | 根据路径找值 |
|
|
26
|
+
| [getUid](./src/get-uid.ts) | 生成唯一id |
|
|
27
|
+
| [hasOwn](./src/has-own.ts) | 是否在原型上 |
|
|
28
|
+
| [numberToUnit](./src/number-to-unit.ts) | 大数据转成中文单位 |
|
|
29
|
+
| [preZero](./src/pre-zero.ts) | 加零 |
|
|
30
|
+
| [raf](./src/raf.ts) | raf |
|
|
31
|
+
| [random](./src/random.ts) | `range` 和 `probs` |
|
|
32
|
+
| [sleep](./src/sleep.ts) | 等待 |
|
|
33
|
+
| [throttle](./src/throttle.ts) | 节流 |
|
|
34
|
+
| [genterateString](./src/genterate-string.ts) | 随机生成指定长度的字符串 |
|
|
35
|
+
| [toPromise](./src/to-promise.ts) | 让返回对象可操作且能直接使用`await instance` |
|
|
36
36
|
|
package/dist/index.cjs
CHANGED
|
@@ -128,8 +128,7 @@ const debounce = (original, wait, options) => {
|
|
|
128
128
|
original.apply(this, args);
|
|
129
129
|
invoke = null;
|
|
130
130
|
};
|
|
131
|
-
if (!wait && throttle)
|
|
132
|
-
return invoke();
|
|
131
|
+
if (!wait && throttle) return invoke();
|
|
133
132
|
if (!timer) {
|
|
134
133
|
leading && invoke();
|
|
135
134
|
start();
|
|
@@ -247,6 +246,7 @@ const preZero = (num) => {
|
|
|
247
246
|
};
|
|
248
247
|
|
|
249
248
|
const raf = typeof window !== "undefined" && window.requestAnimationFrame || ((fn) => setTimeout(fn, 16));
|
|
249
|
+
const caf = typeof window !== "undefined" && window.cancelAnimationFrame || ((rafIf) => clearTimeout(rafIf));
|
|
250
250
|
|
|
251
251
|
const range = (min, max) => {
|
|
252
252
|
return Math.floor(Math.random() * (max - min + 1) + min);
|
|
@@ -293,7 +293,7 @@ const throttle = (original, wait, options) => {
|
|
|
293
293
|
);
|
|
294
294
|
};
|
|
295
295
|
|
|
296
|
-
const flatten = (value, parser) => {
|
|
296
|
+
const flatten = (value, parser, exit) => {
|
|
297
297
|
let need = true;
|
|
298
298
|
let safeCount = 1;
|
|
299
299
|
let parseValue = value;
|
|
@@ -303,7 +303,7 @@ const flatten = (value, parser) => {
|
|
|
303
303
|
}
|
|
304
304
|
try {
|
|
305
305
|
const next = (parser || decodeURIComponent)(parseValue);
|
|
306
|
-
if (parseValue === next) {
|
|
306
|
+
if (parseValue === next || typeof exit === "function" && exit(next)) {
|
|
307
307
|
need = false;
|
|
308
308
|
}
|
|
309
309
|
parseValue = next;
|
|
@@ -316,8 +316,7 @@ const flatten = (value, parser) => {
|
|
|
316
316
|
};
|
|
317
317
|
|
|
318
318
|
const flattenJSONParse = (value) => {
|
|
319
|
-
if (value === null)
|
|
320
|
-
return null;
|
|
319
|
+
if (value === null) return null;
|
|
321
320
|
const regex = /^\d+$/;
|
|
322
321
|
if (regex.test(value) && value.length >= 16 && +value > Number.MAX_SAFE_INTEGER) {
|
|
323
322
|
return value;
|
|
@@ -353,6 +352,7 @@ const toPromise = (target, promise) => {
|
|
|
353
352
|
|
|
354
353
|
exports.asterisk = asterisk;
|
|
355
354
|
exports.autoCatch = autoCatch;
|
|
355
|
+
exports.caf = caf;
|
|
356
356
|
exports.canvasToImage = canvasToImage;
|
|
357
357
|
exports.cloneDeepEasier = cloneDeepEasier;
|
|
358
358
|
exports.compressImage = compressImage;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
|
|
3
1
|
export declare const asterisk: (value: string, from?: number, length?: number) => string;
|
|
4
2
|
|
|
5
3
|
export declare const autoCatch: (impl: any, options?: Record<string, any>) => Promise<any>;
|
|
6
4
|
|
|
5
|
+
export declare type Caf = (radIf: number) => void;
|
|
6
|
+
|
|
7
|
+
export declare const caf: Caf;
|
|
8
|
+
|
|
7
9
|
export declare const canvasToImage: (canvas: HTMLCanvasElement, filename?: string) => Promise<Result>;
|
|
8
10
|
|
|
9
11
|
export declare const cloneDeepEasier: (source: object) => any;
|
|
@@ -30,7 +32,7 @@ export declare const debounce: (original: Function, wait?: number, options?: Opt
|
|
|
30
32
|
|
|
31
33
|
export declare const def: <T = object>(target: T, key: PropertyKey, value?: any, options?: PropertyDescriptor) => T;
|
|
32
34
|
|
|
33
|
-
export declare const flatten: (value: any, parser?: ((x: any) => any)
|
|
35
|
+
export declare const flatten: (value: any, parser?: ((x: any) => any), exit?: ((x: any) => boolean)) => any;
|
|
34
36
|
|
|
35
37
|
export declare const flattenJSONParse: (value: string | null) => any;
|
|
36
38
|
|
|
@@ -85,7 +87,7 @@ declare interface Result {
|
|
|
85
87
|
export declare const sleep: (wait?: number | {
|
|
86
88
|
min: number;
|
|
87
89
|
max: number;
|
|
88
|
-
}, immediate?: (
|
|
90
|
+
}, immediate?: (timer: ReturnType<typeof global.setTimeout>, duration: number, done: Function) => any) => Promise<unknown>;
|
|
89
91
|
|
|
90
92
|
export declare const throttle: (original: Function, wait?: number, options?: Options_2) => {
|
|
91
93
|
(this: any, ...args: any[]): any;
|
|
@@ -93,6 +95,6 @@ export declare const throttle: (original: Function, wait?: number, options?: Opt
|
|
|
93
95
|
flush(): void;
|
|
94
96
|
};
|
|
95
97
|
|
|
96
|
-
export declare const toPromise: <T extends {}, K = any>(target: T, promise: Promise<K>) => T & IPromise<K
|
|
98
|
+
export declare const toPromise: <T extends {}, K = any>(target: T, promise: Promise<K>) => T & IPromise<K>;
|
|
97
99
|
|
|
98
100
|
export { }
|
package/dist/index.iife.js
CHANGED
|
@@ -127,8 +127,7 @@ var HelperUtils = (function (exports) {
|
|
|
127
127
|
original.apply(this, args);
|
|
128
128
|
invoke = null;
|
|
129
129
|
};
|
|
130
|
-
if (!wait && throttle)
|
|
131
|
-
return invoke();
|
|
130
|
+
if (!wait && throttle) return invoke();
|
|
132
131
|
if (!timer) {
|
|
133
132
|
leading && invoke();
|
|
134
133
|
start();
|
|
@@ -246,6 +245,7 @@ var HelperUtils = (function (exports) {
|
|
|
246
245
|
};
|
|
247
246
|
|
|
248
247
|
const raf = typeof window !== "undefined" && window.requestAnimationFrame || ((fn) => setTimeout(fn, 16));
|
|
248
|
+
const caf = typeof window !== "undefined" && window.cancelAnimationFrame || ((rafIf) => clearTimeout(rafIf));
|
|
249
249
|
|
|
250
250
|
const range = (min, max) => {
|
|
251
251
|
return Math.floor(Math.random() * (max - min + 1) + min);
|
|
@@ -292,7 +292,7 @@ var HelperUtils = (function (exports) {
|
|
|
292
292
|
);
|
|
293
293
|
};
|
|
294
294
|
|
|
295
|
-
const flatten = (value, parser) => {
|
|
295
|
+
const flatten = (value, parser, exit) => {
|
|
296
296
|
let need = true;
|
|
297
297
|
let safeCount = 1;
|
|
298
298
|
let parseValue = value;
|
|
@@ -302,7 +302,7 @@ var HelperUtils = (function (exports) {
|
|
|
302
302
|
}
|
|
303
303
|
try {
|
|
304
304
|
const next = (parser || decodeURIComponent)(parseValue);
|
|
305
|
-
if (parseValue === next) {
|
|
305
|
+
if (parseValue === next || typeof exit === "function" && exit(next)) {
|
|
306
306
|
need = false;
|
|
307
307
|
}
|
|
308
308
|
parseValue = next;
|
|
@@ -315,8 +315,7 @@ var HelperUtils = (function (exports) {
|
|
|
315
315
|
};
|
|
316
316
|
|
|
317
317
|
const flattenJSONParse = (value) => {
|
|
318
|
-
if (value === null)
|
|
319
|
-
return null;
|
|
318
|
+
if (value === null) return null;
|
|
320
319
|
const regex = /^\d+$/;
|
|
321
320
|
if (regex.test(value) && value.length >= 16 && +value > Number.MAX_SAFE_INTEGER) {
|
|
322
321
|
return value;
|
|
@@ -352,6 +351,7 @@ var HelperUtils = (function (exports) {
|
|
|
352
351
|
|
|
353
352
|
exports.asterisk = asterisk;
|
|
354
353
|
exports.autoCatch = autoCatch;
|
|
354
|
+
exports.caf = caf;
|
|
355
355
|
exports.canvasToImage = canvasToImage;
|
|
356
356
|
exports.cloneDeepEasier = cloneDeepEasier;
|
|
357
357
|
exports.compressImage = compressImage;
|
package/dist/index.js
CHANGED
|
@@ -124,8 +124,7 @@ const debounce = (original, wait, options) => {
|
|
|
124
124
|
original.apply(this, args);
|
|
125
125
|
invoke = null;
|
|
126
126
|
};
|
|
127
|
-
if (!wait && throttle)
|
|
128
|
-
return invoke();
|
|
127
|
+
if (!wait && throttle) return invoke();
|
|
129
128
|
if (!timer) {
|
|
130
129
|
leading && invoke();
|
|
131
130
|
start();
|
|
@@ -243,6 +242,7 @@ const preZero = (num) => {
|
|
|
243
242
|
};
|
|
244
243
|
|
|
245
244
|
const raf = typeof window !== "undefined" && window.requestAnimationFrame || ((fn) => setTimeout(fn, 16));
|
|
245
|
+
const caf = typeof window !== "undefined" && window.cancelAnimationFrame || ((rafIf) => clearTimeout(rafIf));
|
|
246
246
|
|
|
247
247
|
const range = (min, max) => {
|
|
248
248
|
return Math.floor(Math.random() * (max - min + 1) + min);
|
|
@@ -289,7 +289,7 @@ const throttle = (original, wait, options) => {
|
|
|
289
289
|
);
|
|
290
290
|
};
|
|
291
291
|
|
|
292
|
-
const flatten = (value, parser) => {
|
|
292
|
+
const flatten = (value, parser, exit) => {
|
|
293
293
|
let need = true;
|
|
294
294
|
let safeCount = 1;
|
|
295
295
|
let parseValue = value;
|
|
@@ -299,7 +299,7 @@ const flatten = (value, parser) => {
|
|
|
299
299
|
}
|
|
300
300
|
try {
|
|
301
301
|
const next = (parser || decodeURIComponent)(parseValue);
|
|
302
|
-
if (parseValue === next) {
|
|
302
|
+
if (parseValue === next || typeof exit === "function" && exit(next)) {
|
|
303
303
|
need = false;
|
|
304
304
|
}
|
|
305
305
|
parseValue = next;
|
|
@@ -312,8 +312,7 @@ const flatten = (value, parser) => {
|
|
|
312
312
|
};
|
|
313
313
|
|
|
314
314
|
const flattenJSONParse = (value) => {
|
|
315
|
-
if (value === null)
|
|
316
|
-
return null;
|
|
315
|
+
if (value === null) return null;
|
|
317
316
|
const regex = /^\d+$/;
|
|
318
317
|
if (regex.test(value) && value.length >= 16 && +value > Number.MAX_SAFE_INTEGER) {
|
|
319
318
|
return value;
|
|
@@ -347,4 +346,4 @@ const toPromise = (target, promise) => {
|
|
|
347
346
|
return instance;
|
|
348
347
|
};
|
|
349
348
|
|
|
350
|
-
export { asterisk, autoCatch, canvasToImage, cloneDeepEasier, compressImage, dataURLToFile, debounce, def, flatten, flattenJSONParse, generateString, getPropByPath, getUid, hasOwn, numberToUnit, preZero, probs, raf, range, sleep, throttle, toPromise };
|
|
349
|
+
export { asterisk, autoCatch, caf, canvasToImage, cloneDeepEasier, compressImage, dataURLToFile, debounce, def, flatten, flattenJSONParse, generateString, getPropByPath, getUid, hasOwn, numberToUnit, preZero, probs, raf, range, sleep, throttle, toPromise };
|
package/dist/index.umd.cjs
CHANGED
|
@@ -130,8 +130,7 @@
|
|
|
130
130
|
original.apply(this, args);
|
|
131
131
|
invoke = null;
|
|
132
132
|
};
|
|
133
|
-
if (!wait && throttle)
|
|
134
|
-
return invoke();
|
|
133
|
+
if (!wait && throttle) return invoke();
|
|
135
134
|
if (!timer) {
|
|
136
135
|
leading && invoke();
|
|
137
136
|
start();
|
|
@@ -249,6 +248,7 @@
|
|
|
249
248
|
};
|
|
250
249
|
|
|
251
250
|
const raf = typeof window !== "undefined" && window.requestAnimationFrame || ((fn) => setTimeout(fn, 16));
|
|
251
|
+
const caf = typeof window !== "undefined" && window.cancelAnimationFrame || ((rafIf) => clearTimeout(rafIf));
|
|
252
252
|
|
|
253
253
|
const range = (min, max) => {
|
|
254
254
|
return Math.floor(Math.random() * (max - min + 1) + min);
|
|
@@ -295,7 +295,7 @@
|
|
|
295
295
|
);
|
|
296
296
|
};
|
|
297
297
|
|
|
298
|
-
const flatten = (value, parser) => {
|
|
298
|
+
const flatten = (value, parser, exit) => {
|
|
299
299
|
let need = true;
|
|
300
300
|
let safeCount = 1;
|
|
301
301
|
let parseValue = value;
|
|
@@ -305,7 +305,7 @@
|
|
|
305
305
|
}
|
|
306
306
|
try {
|
|
307
307
|
const next = (parser || decodeURIComponent)(parseValue);
|
|
308
|
-
if (parseValue === next) {
|
|
308
|
+
if (parseValue === next || typeof exit === "function" && exit(next)) {
|
|
309
309
|
need = false;
|
|
310
310
|
}
|
|
311
311
|
parseValue = next;
|
|
@@ -318,8 +318,7 @@
|
|
|
318
318
|
};
|
|
319
319
|
|
|
320
320
|
const flattenJSONParse = (value) => {
|
|
321
|
-
if (value === null)
|
|
322
|
-
return null;
|
|
321
|
+
if (value === null) return null;
|
|
323
322
|
const regex = /^\d+$/;
|
|
324
323
|
if (regex.test(value) && value.length >= 16 && +value > Number.MAX_SAFE_INTEGER) {
|
|
325
324
|
return value;
|
|
@@ -355,6 +354,7 @@
|
|
|
355
354
|
|
|
356
355
|
exports.asterisk = asterisk;
|
|
357
356
|
exports.autoCatch = autoCatch;
|
|
357
|
+
exports.caf = caf;
|
|
358
358
|
exports.canvasToImage = canvasToImage;
|
|
359
359
|
exports.cloneDeepEasier = cloneDeepEasier;
|
|
360
360
|
exports.compressImage = compressImage;
|