@deot/helper-utils 1.1.4 → 1.1.5

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
@@ -12,25 +12,25 @@ import { Utils } from '@deot/helper';
12
12
 
13
13
  | 方法 | 说明 |
14
14
  | ------------------------------------------------------------------ | ------------------------------ |
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` |
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();
@@ -293,7 +292,7 @@ const throttle = (original, wait, options) => {
293
292
  );
294
293
  };
295
294
 
296
- const flatten = (value, parser) => {
295
+ const flatten = (value, parser, exit) => {
297
296
  let need = true;
298
297
  let safeCount = 1;
299
298
  let parseValue = value;
@@ -303,7 +302,7 @@ const flatten = (value, parser) => {
303
302
  }
304
303
  try {
305
304
  const next = (parser || decodeURIComponent)(parseValue);
306
- if (parseValue === next) {
305
+ if (parseValue === next || typeof exit === "function" && exit(next)) {
307
306
  need = false;
308
307
  }
309
308
  parseValue = next;
@@ -316,8 +315,7 @@ const flatten = (value, parser) => {
316
315
  };
317
316
 
318
317
  const flattenJSONParse = (value) => {
319
- if (value === null)
320
- return null;
318
+ if (value === null) return null;
321
319
  const regex = /^\d+$/;
322
320
  if (regex.test(value) && value.length >= 16 && +value > Number.MAX_SAFE_INTEGER) {
323
321
  return value;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,3 @@
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>;
@@ -30,7 +28,7 @@ export declare const debounce: (original: Function, wait?: number, options?: Opt
30
28
 
31
29
  export declare const def: <T = object>(target: T, key: PropertyKey, value?: any, options?: PropertyDescriptor) => T;
32
30
 
33
- export declare const flatten: (value: any, parser?: ((x: any) => any) | undefined) => any;
31
+ export declare const flatten: (value: any, parser?: ((x: any) => any), exit?: ((x: any) => boolean)) => any;
34
32
 
35
33
  export declare const flattenJSONParse: (value: string | null) => any;
36
34
 
@@ -85,7 +83,7 @@ declare interface Result {
85
83
  export declare const sleep: (wait?: number | {
86
84
  min: number;
87
85
  max: number;
88
- }, immediate?: ((timer: ReturnType<typeof global.setTimeout>, duration: number, done: Function) => any) | undefined) => Promise<unknown>;
86
+ }, immediate?: (timer: ReturnType<typeof global.setTimeout>, duration: number, done: Function) => any) => Promise<unknown>;
89
87
 
90
88
  export declare const throttle: (original: Function, wait?: number, options?: Options_2) => {
91
89
  (this: any, ...args: any[]): any;
@@ -93,6 +91,6 @@ export declare const throttle: (original: Function, wait?: number, options?: Opt
93
91
  flush(): void;
94
92
  };
95
93
 
96
- export declare const toPromise: <T extends {}, K = any>(target: T, promise: Promise<K>) => T & IPromise<K, any>;
94
+ export declare const toPromise: <T extends {}, K = any>(target: T, promise: Promise<K>) => T & IPromise<K>;
97
95
 
98
96
  export { }
@@ -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();
@@ -292,7 +291,7 @@ var HelperUtils = (function (exports) {
292
291
  );
293
292
  };
294
293
 
295
- const flatten = (value, parser) => {
294
+ const flatten = (value, parser, exit) => {
296
295
  let need = true;
297
296
  let safeCount = 1;
298
297
  let parseValue = value;
@@ -302,7 +301,7 @@ var HelperUtils = (function (exports) {
302
301
  }
303
302
  try {
304
303
  const next = (parser || decodeURIComponent)(parseValue);
305
- if (parseValue === next) {
304
+ if (parseValue === next || typeof exit === "function" && exit(next)) {
306
305
  need = false;
307
306
  }
308
307
  parseValue = next;
@@ -315,8 +314,7 @@ var HelperUtils = (function (exports) {
315
314
  };
316
315
 
317
316
  const flattenJSONParse = (value) => {
318
- if (value === null)
319
- return null;
317
+ if (value === null) return null;
320
318
  const regex = /^\d+$/;
321
319
  if (regex.test(value) && value.length >= 16 && +value > Number.MAX_SAFE_INTEGER) {
322
320
  return value;
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();
@@ -289,7 +288,7 @@ const throttle = (original, wait, options) => {
289
288
  );
290
289
  };
291
290
 
292
- const flatten = (value, parser) => {
291
+ const flatten = (value, parser, exit) => {
293
292
  let need = true;
294
293
  let safeCount = 1;
295
294
  let parseValue = value;
@@ -299,7 +298,7 @@ const flatten = (value, parser) => {
299
298
  }
300
299
  try {
301
300
  const next = (parser || decodeURIComponent)(parseValue);
302
- if (parseValue === next) {
301
+ if (parseValue === next || typeof exit === "function" && exit(next)) {
303
302
  need = false;
304
303
  }
305
304
  parseValue = next;
@@ -312,8 +311,7 @@ const flatten = (value, parser) => {
312
311
  };
313
312
 
314
313
  const flattenJSONParse = (value) => {
315
- if (value === null)
316
- return null;
314
+ if (value === null) return null;
317
315
  const regex = /^\d+$/;
318
316
  if (regex.test(value) && value.length >= 16 && +value > Number.MAX_SAFE_INTEGER) {
319
317
  return value;
@@ -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();
@@ -295,7 +294,7 @@
295
294
  );
296
295
  };
297
296
 
298
- const flatten = (value, parser) => {
297
+ const flatten = (value, parser, exit) => {
299
298
  let need = true;
300
299
  let safeCount = 1;
301
300
  let parseValue = value;
@@ -305,7 +304,7 @@
305
304
  }
306
305
  try {
307
306
  const next = (parser || decodeURIComponent)(parseValue);
308
- if (parseValue === next) {
307
+ if (parseValue === next || typeof exit === "function" && exit(next)) {
309
308
  need = false;
310
309
  }
311
310
  parseValue = next;
@@ -318,8 +317,7 @@
318
317
  };
319
318
 
320
319
  const flattenJSONParse = (value) => {
321
- if (value === null)
322
- return null;
320
+ if (value === null) return null;
323
321
  const regex = /^\d+$/;
324
322
  if (regex.test(value) && value.length >= 16 && +value > Number.MAX_SAFE_INTEGER) {
325
323
  return value;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deot/helper-utils",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",