@deot/helper-utils 1.1.0 → 1.1.2

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 CHANGED
@@ -9,25 +9,27 @@ import { Utils } from '@deot/helper';
9
9
 
10
10
  ```
11
11
 
12
- | 方法 | 说明 |
13
- | ------------------------------------------------------------------ | ----------------- |
14
- | [asterisk][./src/asterisk.ts] | 文字加`*` |
15
- | [autoCatch][./src/auto-catch.ts] | 捕获异常 |
16
- | [canvasToImage][./src/canvas-to-image.ts] | 转图片信息 |
17
- | [cloneDeepEasier][./src/clone-deep-easier.ts] | 深拷贝 |
18
- | [compressImage][./src/compress-image.ts] | 压缩图片 |
19
- | [dataURLToFile][./src/dataURL-to-file.ts] | base64转文件 |
20
- | [debounce][./src/debounce.ts] | 防抖 |
21
- | [def][./src/def.ts] | 定义 |
22
- | [flattenDecodeURIComponent][./src/flatten-decode-uri-component.ts] | 深度解码 |
23
- | [flattenJSONParse][./src/flatten-json-parse.ts] | 深度反序列化 |
24
- | [getPropByPath][./src/get-prop-by-path.ts] | 根据路径找值 |
25
- | [getUid][./src/get-uid.ts] | 生成唯一id |
26
- | [hasOwn][./src/has-own.ts] | 是否在原型上 |
27
- | [numberToUnit][./src/number-to-unit.ts] | 大数据转成中文单位 |
28
- | [preZero][./src/pre-zero.ts] | 加零 |
29
- | [raf][./src/raf.ts] | raf |
30
- | [random][./src/random.ts] | `range` 和 `probs` |
31
- | [sleep][./src/sleep.ts] | 等待 |
32
- | [throttle][./src/throttle.ts] | 节流 |
33
- | [genterateString][./src/genterate-string.ts] | 随机生成指定长度的字符串 |
12
+ | 方法 | 说明 |
13
+ | ------------------------------------------------------------------ | ------------------------------ |
14
+ | [asterisk][./src/asterisk.ts] | 文字加`*` |
15
+ | [autoCatch][./src/auto-catch.ts] | 捕获异常 |
16
+ | [canvasToImage][./src/canvas-to-image.ts] | 转图片信息 |
17
+ | [cloneDeepEasier][./src/clone-deep-easier.ts] | 深拷贝 |
18
+ | [compressImage][./src/compress-image.ts] | 压缩图片 |
19
+ | [dataURLToFile][./src/dataURL-to-file.ts] | base64转文件 |
20
+ | [debounce][./src/debounce.ts] | 防抖 |
21
+ | [def][./src/def.ts] | 定义 |
22
+ | [flattenDecodeURIComponent][./src/flatten-decode-uri-component.ts] | 深度解码 |
23
+ | [flattenJSONParse][./src/flatten-json-parse.ts] | 深度反序列化 |
24
+ | [getPropByPath][./src/get-prop-by-path.ts] | 根据路径找值 |
25
+ | [getUid][./src/get-uid.ts] | 生成唯一id |
26
+ | [hasOwn][./src/has-own.ts] | 是否在原型上 |
27
+ | [numberToUnit][./src/number-to-unit.ts] | 大数据转成中文单位 |
28
+ | [preZero][./src/pre-zero.ts] | 加零 |
29
+ | [raf][./src/raf.ts] | raf |
30
+ | [random][./src/random.ts] | `range` 和 `probs` |
31
+ | [sleep][./src/sleep.ts] | 等待 |
32
+ | [throttle][./src/throttle.ts] | 节流 |
33
+ | [genterateString][./src/genterate-string.ts] | 随机生成指定长度的字符串 |
34
+ | [toPromise][./src/to-promise.ts] | 让返回对象可操作且能直接使用`await instance` |
35
+
@@ -339,6 +339,18 @@ const generateString = (size, alphabet) => {
339
339
  return str;
340
340
  };
341
341
 
342
+ const toPromise = (target, promise) => {
343
+ const instance = target;
344
+ const target$ = target;
345
+ if (!target$ || target$.then || target$.catch || target$.finally) {
346
+ throw new Error(`TypeError`);
347
+ }
348
+ instance.then = (resolve, reject) => promise.then(resolve, reject);
349
+ instance.catch = (callback) => promise.catch(callback);
350
+ instance.finally = (callback) => promise.finally(callback);
351
+ return instance;
352
+ };
353
+
342
354
  exports.asterisk = asterisk;
343
355
  exports.autoCatch = autoCatch;
344
356
  exports.canvasToImage = canvasToImage;
@@ -360,3 +372,4 @@ exports.raf = raf;
360
372
  exports.range = range;
361
373
  exports.sleep = sleep;
362
374
  exports.throttle = throttle;
375
+ exports.toPromise = toPromise;
package/dist/index.d.ts CHANGED
@@ -42,6 +42,12 @@ export declare const getUid: (prefix?: string) => string;
42
42
 
43
43
  export declare const hasOwn: (target: object, key: PropertyKey) => boolean;
44
44
 
45
+ declare interface IPromise<T = any, K = any> {
46
+ then: (resolve: (a: T) => void, reject: (b: K) => void) => Promise<any>;
47
+ catch: (callback?: (b: K) => void) => Promise<any>;
48
+ finally: (callback?: () => void) => Promise<any>;
49
+ }
50
+
45
51
  export declare const numberToUnit: (number: number, decimalDigit?: number) => string | number;
46
52
 
47
53
  declare interface ObjectKeyValue {
@@ -87,4 +93,6 @@ export declare const throttle: (original: Function, wait?: number, options?: Opt
87
93
  flush(): void;
88
94
  };
89
95
 
96
+ export declare const toPromise: <T extends {}, K = any>(target: T, promise: Promise<K>) => T & IPromise<K, any>;
97
+
90
98
  export { }
@@ -338,6 +338,18 @@ var HelperUtils = (function (exports) {
338
338
  return str;
339
339
  };
340
340
 
341
+ const toPromise = (target, promise) => {
342
+ const instance = target;
343
+ const target$ = target;
344
+ if (!target$ || target$.then || target$.catch || target$.finally) {
345
+ throw new Error(`TypeError`);
346
+ }
347
+ instance.then = (resolve, reject) => promise.then(resolve, reject);
348
+ instance.catch = (callback) => promise.catch(callback);
349
+ instance.finally = (callback) => promise.finally(callback);
350
+ return instance;
351
+ };
352
+
341
353
  exports.asterisk = asterisk;
342
354
  exports.autoCatch = autoCatch;
343
355
  exports.canvasToImage = canvasToImage;
@@ -359,6 +371,7 @@ var HelperUtils = (function (exports) {
359
371
  exports.range = range;
360
372
  exports.sleep = sleep;
361
373
  exports.throttle = throttle;
374
+ exports.toPromise = toPromise;
362
375
 
363
376
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
364
377
 
@@ -335,4 +335,16 @@ const generateString = (size, alphabet) => {
335
335
  return str;
336
336
  };
337
337
 
338
- export { asterisk, autoCatch, canvasToImage, cloneDeepEasier, compressImage, dataURLToFile, debounce, def, flatten, flattenJSONParse, generateString, getPropByPath, getUid, hasOwn, numberToUnit, preZero, probs, raf, range, sleep, throttle };
338
+ const toPromise = (target, promise) => {
339
+ const instance = target;
340
+ const target$ = target;
341
+ if (!target$ || target$.then || target$.catch || target$.finally) {
342
+ throw new Error(`TypeError`);
343
+ }
344
+ instance.then = (resolve, reject) => promise.then(resolve, reject);
345
+ instance.catch = (callback) => promise.catch(callback);
346
+ instance.finally = (callback) => promise.finally(callback);
347
+ return instance;
348
+ };
349
+
350
+ export { asterisk, autoCatch, canvasToImage, cloneDeepEasier, compressImage, dataURLToFile, debounce, def, flatten, flattenJSONParse, generateString, getPropByPath, getUid, hasOwn, numberToUnit, preZero, probs, raf, range, sleep, throttle, toPromise };
@@ -341,6 +341,18 @@
341
341
  return str;
342
342
  };
343
343
 
344
+ const toPromise = (target, promise) => {
345
+ const instance = target;
346
+ const target$ = target;
347
+ if (!target$ || target$.then || target$.catch || target$.finally) {
348
+ throw new Error(`TypeError`);
349
+ }
350
+ instance.then = (resolve, reject) => promise.then(resolve, reject);
351
+ instance.catch = (callback) => promise.catch(callback);
352
+ instance.finally = (callback) => promise.finally(callback);
353
+ return instance;
354
+ };
355
+
344
356
  exports.asterisk = asterisk;
345
357
  exports.autoCatch = autoCatch;
346
358
  exports.canvasToImage = canvasToImage;
@@ -362,6 +374,7 @@
362
374
  exports.range = range;
363
375
  exports.sleep = sleep;
364
376
  exports.throttle = throttle;
377
+ exports.toPromise = toPromise;
365
378
 
366
379
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
367
380
 
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@deot/helper-utils",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "type": "module",
5
- "main": "dist/index.es.js",
5
+ "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {
8
8
  ".": {
9
- "import": "./dist/index.es.js",
10
- "require": "./dist/index.cjs.js",
9
+ "import": "./dist/index.js",
10
+ "require": "./dist/index.cjs",
11
11
  "types": "./dist/index.d.ts"
12
12
  }
13
13
  },