@deot/helper-utils 1.0.1 → 1.0.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 +0 -1
- package/dist/index.cjs.js +5 -26
- package/dist/index.d.ts +4 -6
- package/dist/index.es.js +5 -25
- package/dist/index.iife.js +5 -26
- package/dist/index.umd.js +5 -26
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -24,7 +24,6 @@ import { Utils } from '@deot/helper';
|
|
|
24
24
|
| [getPropByPath][./src/get-prop-by-path.ts] | 根据路径找值 |
|
|
25
25
|
| [getUid][./src/get-uid.ts] | 生成唯一id |
|
|
26
26
|
| [hasOwn][./src/has-own.ts] | 是否在原型上 |
|
|
27
|
-
| [isObj][./src/is-obj.ts] | 是否对象 |
|
|
28
27
|
| [numberToUnit][./src/number-to-unit.ts] | 大数据转成中文单位 |
|
|
29
28
|
| [preZero][./src/pre-zero.ts] | 加零 |
|
|
30
29
|
| [raf][./src/raf.ts] | raf |
|
package/dist/index.cjs.js
CHANGED
|
@@ -150,7 +150,7 @@ const debounce = (original, wait, options) => {
|
|
|
150
150
|
};
|
|
151
151
|
|
|
152
152
|
const def = (target, key, value, options) => {
|
|
153
|
-
Object.defineProperty(target, key, {
|
|
153
|
+
return Object.defineProperty(target, key, {
|
|
154
154
|
value,
|
|
155
155
|
enumerable: false,
|
|
156
156
|
writable: true,
|
|
@@ -192,8 +192,6 @@ const getUid = (prefix) => {
|
|
|
192
192
|
|
|
193
193
|
const hasOwn = (target, key) => Object.prototype.hasOwnProperty.call(target, key);
|
|
194
194
|
|
|
195
|
-
const isObj = (target) => typeof target === "object";
|
|
196
|
-
|
|
197
195
|
const getDigit = (integer) => {
|
|
198
196
|
let digit = -1;
|
|
199
197
|
while (integer >= 1) {
|
|
@@ -295,7 +293,7 @@ const throttle = (original, wait, options) => {
|
|
|
295
293
|
);
|
|
296
294
|
};
|
|
297
295
|
|
|
298
|
-
const
|
|
296
|
+
const flatten = (value, parser) => {
|
|
299
297
|
let need = true;
|
|
300
298
|
let safeCount = 1;
|
|
301
299
|
let parseValue = value;
|
|
@@ -304,7 +302,7 @@ const flattenDecodeURIComponent = (value) => {
|
|
|
304
302
|
throw new Error(value);
|
|
305
303
|
}
|
|
306
304
|
try {
|
|
307
|
-
let next = decodeURIComponent(parseValue);
|
|
305
|
+
let next = (parser || decodeURIComponent)(parseValue);
|
|
308
306
|
if (parseValue === next) {
|
|
309
307
|
need = false;
|
|
310
308
|
}
|
|
@@ -324,25 +322,7 @@ const flattenJSONParse = (value) => {
|
|
|
324
322
|
if (regex.test(value) && value.length >= 16 && +value > Number.MAX_SAFE_INTEGER) {
|
|
325
323
|
return value;
|
|
326
324
|
}
|
|
327
|
-
|
|
328
|
-
let safeCount = 1;
|
|
329
|
-
let parseValue = value;
|
|
330
|
-
while (need) {
|
|
331
|
-
if (safeCount > 10) {
|
|
332
|
-
throw new Error(value);
|
|
333
|
-
}
|
|
334
|
-
try {
|
|
335
|
-
let next = JSON.parse(parseValue);
|
|
336
|
-
if (parseValue === next) {
|
|
337
|
-
need = false;
|
|
338
|
-
}
|
|
339
|
-
parseValue = next;
|
|
340
|
-
} catch {
|
|
341
|
-
need = false;
|
|
342
|
-
}
|
|
343
|
-
safeCount++;
|
|
344
|
-
}
|
|
345
|
-
return parseValue;
|
|
325
|
+
return flatten(value, JSON.parse);
|
|
346
326
|
};
|
|
347
327
|
|
|
348
328
|
exports.asterisk = asterisk;
|
|
@@ -353,12 +333,11 @@ exports.compressImage = compressImage;
|
|
|
353
333
|
exports.dataURLToFile = dataURLToFile;
|
|
354
334
|
exports.debounce = debounce;
|
|
355
335
|
exports.def = def;
|
|
356
|
-
exports.
|
|
336
|
+
exports.flatten = flatten;
|
|
357
337
|
exports.flattenJSONParse = flattenJSONParse;
|
|
358
338
|
exports.getPropByPath = getPropByPath;
|
|
359
339
|
exports.getUid = getUid;
|
|
360
340
|
exports.hasOwn = hasOwn;
|
|
361
|
-
exports.isObj = isObj;
|
|
362
341
|
exports.numberToUnit = numberToUnit;
|
|
363
342
|
exports.preZero = preZero;
|
|
364
343
|
exports.probs = probs;
|
package/dist/index.d.ts
CHANGED
|
@@ -8,12 +8,12 @@ export declare const canvasToImage: (canvas: HTMLCanvasElement, filename?: strin
|
|
|
8
8
|
|
|
9
9
|
export declare const cloneDeepEasier: (source: object) => any;
|
|
10
10
|
|
|
11
|
-
export declare const compressImage: (file: File, options?:
|
|
11
|
+
export declare const compressImage: (file: File, options?: CompressImageOptions) => Promise<{
|
|
12
12
|
dataURL: string;
|
|
13
13
|
file: File;
|
|
14
14
|
}>;
|
|
15
15
|
|
|
16
|
-
export declare interface
|
|
16
|
+
export declare interface CompressImageOptions {
|
|
17
17
|
width?: number;
|
|
18
18
|
height?: number;
|
|
19
19
|
filetype?: string;
|
|
@@ -28,9 +28,9 @@ export declare const debounce: (original: Function, wait?: number, options?: Opt
|
|
|
28
28
|
flush(): void;
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
export declare const def: (target:
|
|
31
|
+
export declare const def: <T = object>(target: T, key: PropertyKey, value?: any, options?: PropertyDescriptor) => T;
|
|
32
32
|
|
|
33
|
-
export declare const
|
|
33
|
+
export declare const flatten: (value: any, parser?: ((x: any) => any) | undefined) => any;
|
|
34
34
|
|
|
35
35
|
export declare const flattenJSONParse: (value: string | null) => any;
|
|
36
36
|
|
|
@@ -40,8 +40,6 @@ export declare const getUid: (prefix?: string) => string;
|
|
|
40
40
|
|
|
41
41
|
export declare const hasOwn: (target: object, key: PropertyKey) => boolean;
|
|
42
42
|
|
|
43
|
-
export declare const isObj: (target?: any) => boolean;
|
|
44
|
-
|
|
45
43
|
export declare const numberToUnit: (number: number, decimalDigit?: number) => string | number;
|
|
46
44
|
|
|
47
45
|
declare interface ObjectKeyValue {
|
package/dist/index.es.js
CHANGED
|
@@ -146,7 +146,7 @@ const debounce = (original, wait, options) => {
|
|
|
146
146
|
};
|
|
147
147
|
|
|
148
148
|
const def = (target, key, value, options) => {
|
|
149
|
-
Object.defineProperty(target, key, {
|
|
149
|
+
return Object.defineProperty(target, key, {
|
|
150
150
|
value,
|
|
151
151
|
enumerable: false,
|
|
152
152
|
writable: true,
|
|
@@ -188,8 +188,6 @@ const getUid = (prefix) => {
|
|
|
188
188
|
|
|
189
189
|
const hasOwn = (target, key) => Object.prototype.hasOwnProperty.call(target, key);
|
|
190
190
|
|
|
191
|
-
const isObj = (target) => typeof target === "object";
|
|
192
|
-
|
|
193
191
|
const getDigit = (integer) => {
|
|
194
192
|
let digit = -1;
|
|
195
193
|
while (integer >= 1) {
|
|
@@ -291,7 +289,7 @@ const throttle = (original, wait, options) => {
|
|
|
291
289
|
);
|
|
292
290
|
};
|
|
293
291
|
|
|
294
|
-
const
|
|
292
|
+
const flatten = (value, parser) => {
|
|
295
293
|
let need = true;
|
|
296
294
|
let safeCount = 1;
|
|
297
295
|
let parseValue = value;
|
|
@@ -300,7 +298,7 @@ const flattenDecodeURIComponent = (value) => {
|
|
|
300
298
|
throw new Error(value);
|
|
301
299
|
}
|
|
302
300
|
try {
|
|
303
|
-
let next = decodeURIComponent(parseValue);
|
|
301
|
+
let next = (parser || decodeURIComponent)(parseValue);
|
|
304
302
|
if (parseValue === next) {
|
|
305
303
|
need = false;
|
|
306
304
|
}
|
|
@@ -320,25 +318,7 @@ const flattenJSONParse = (value) => {
|
|
|
320
318
|
if (regex.test(value) && value.length >= 16 && +value > Number.MAX_SAFE_INTEGER) {
|
|
321
319
|
return value;
|
|
322
320
|
}
|
|
323
|
-
|
|
324
|
-
let safeCount = 1;
|
|
325
|
-
let parseValue = value;
|
|
326
|
-
while (need) {
|
|
327
|
-
if (safeCount > 10) {
|
|
328
|
-
throw new Error(value);
|
|
329
|
-
}
|
|
330
|
-
try {
|
|
331
|
-
let next = JSON.parse(parseValue);
|
|
332
|
-
if (parseValue === next) {
|
|
333
|
-
need = false;
|
|
334
|
-
}
|
|
335
|
-
parseValue = next;
|
|
336
|
-
} catch {
|
|
337
|
-
need = false;
|
|
338
|
-
}
|
|
339
|
-
safeCount++;
|
|
340
|
-
}
|
|
341
|
-
return parseValue;
|
|
321
|
+
return flatten(value, JSON.parse);
|
|
342
322
|
};
|
|
343
323
|
|
|
344
|
-
export { asterisk, autoCatch, canvasToImage, cloneDeepEasier, compressImage, dataURLToFile, debounce, def,
|
|
324
|
+
export { asterisk, autoCatch, canvasToImage, cloneDeepEasier, compressImage, dataURLToFile, debounce, def, flatten, flattenJSONParse, getPropByPath, getUid, hasOwn, numberToUnit, preZero, probs, raf, range, sleep, throttle };
|
package/dist/index.iife.js
CHANGED
|
@@ -149,7 +149,7 @@ var HelperUtils = (function (exports) {
|
|
|
149
149
|
};
|
|
150
150
|
|
|
151
151
|
const def = (target, key, value, options) => {
|
|
152
|
-
Object.defineProperty(target, key, {
|
|
152
|
+
return Object.defineProperty(target, key, {
|
|
153
153
|
value,
|
|
154
154
|
enumerable: false,
|
|
155
155
|
writable: true,
|
|
@@ -191,8 +191,6 @@ var HelperUtils = (function (exports) {
|
|
|
191
191
|
|
|
192
192
|
const hasOwn = (target, key) => Object.prototype.hasOwnProperty.call(target, key);
|
|
193
193
|
|
|
194
|
-
const isObj = (target) => typeof target === "object";
|
|
195
|
-
|
|
196
194
|
const getDigit = (integer) => {
|
|
197
195
|
let digit = -1;
|
|
198
196
|
while (integer >= 1) {
|
|
@@ -294,7 +292,7 @@ var HelperUtils = (function (exports) {
|
|
|
294
292
|
);
|
|
295
293
|
};
|
|
296
294
|
|
|
297
|
-
const
|
|
295
|
+
const flatten = (value, parser) => {
|
|
298
296
|
let need = true;
|
|
299
297
|
let safeCount = 1;
|
|
300
298
|
let parseValue = value;
|
|
@@ -303,7 +301,7 @@ var HelperUtils = (function (exports) {
|
|
|
303
301
|
throw new Error(value);
|
|
304
302
|
}
|
|
305
303
|
try {
|
|
306
|
-
let next = decodeURIComponent(parseValue);
|
|
304
|
+
let next = (parser || decodeURIComponent)(parseValue);
|
|
307
305
|
if (parseValue === next) {
|
|
308
306
|
need = false;
|
|
309
307
|
}
|
|
@@ -323,25 +321,7 @@ var HelperUtils = (function (exports) {
|
|
|
323
321
|
if (regex.test(value) && value.length >= 16 && +value > Number.MAX_SAFE_INTEGER) {
|
|
324
322
|
return value;
|
|
325
323
|
}
|
|
326
|
-
|
|
327
|
-
let safeCount = 1;
|
|
328
|
-
let parseValue = value;
|
|
329
|
-
while (need) {
|
|
330
|
-
if (safeCount > 10) {
|
|
331
|
-
throw new Error(value);
|
|
332
|
-
}
|
|
333
|
-
try {
|
|
334
|
-
let next = JSON.parse(parseValue);
|
|
335
|
-
if (parseValue === next) {
|
|
336
|
-
need = false;
|
|
337
|
-
}
|
|
338
|
-
parseValue = next;
|
|
339
|
-
} catch {
|
|
340
|
-
need = false;
|
|
341
|
-
}
|
|
342
|
-
safeCount++;
|
|
343
|
-
}
|
|
344
|
-
return parseValue;
|
|
324
|
+
return flatten(value, JSON.parse);
|
|
345
325
|
};
|
|
346
326
|
|
|
347
327
|
exports.asterisk = asterisk;
|
|
@@ -352,12 +332,11 @@ var HelperUtils = (function (exports) {
|
|
|
352
332
|
exports.dataURLToFile = dataURLToFile;
|
|
353
333
|
exports.debounce = debounce;
|
|
354
334
|
exports.def = def;
|
|
355
|
-
exports.
|
|
335
|
+
exports.flatten = flatten;
|
|
356
336
|
exports.flattenJSONParse = flattenJSONParse;
|
|
357
337
|
exports.getPropByPath = getPropByPath;
|
|
358
338
|
exports.getUid = getUid;
|
|
359
339
|
exports.hasOwn = hasOwn;
|
|
360
|
-
exports.isObj = isObj;
|
|
361
340
|
exports.numberToUnit = numberToUnit;
|
|
362
341
|
exports.preZero = preZero;
|
|
363
342
|
exports.probs = probs;
|
package/dist/index.umd.js
CHANGED
|
@@ -152,7 +152,7 @@
|
|
|
152
152
|
};
|
|
153
153
|
|
|
154
154
|
const def = (target, key, value, options) => {
|
|
155
|
-
Object.defineProperty(target, key, {
|
|
155
|
+
return Object.defineProperty(target, key, {
|
|
156
156
|
value,
|
|
157
157
|
enumerable: false,
|
|
158
158
|
writable: true,
|
|
@@ -194,8 +194,6 @@
|
|
|
194
194
|
|
|
195
195
|
const hasOwn = (target, key) => Object.prototype.hasOwnProperty.call(target, key);
|
|
196
196
|
|
|
197
|
-
const isObj = (target) => typeof target === "object";
|
|
198
|
-
|
|
199
197
|
const getDigit = (integer) => {
|
|
200
198
|
let digit = -1;
|
|
201
199
|
while (integer >= 1) {
|
|
@@ -297,7 +295,7 @@
|
|
|
297
295
|
);
|
|
298
296
|
};
|
|
299
297
|
|
|
300
|
-
const
|
|
298
|
+
const flatten = (value, parser) => {
|
|
301
299
|
let need = true;
|
|
302
300
|
let safeCount = 1;
|
|
303
301
|
let parseValue = value;
|
|
@@ -306,7 +304,7 @@
|
|
|
306
304
|
throw new Error(value);
|
|
307
305
|
}
|
|
308
306
|
try {
|
|
309
|
-
let next = decodeURIComponent(parseValue);
|
|
307
|
+
let next = (parser || decodeURIComponent)(parseValue);
|
|
310
308
|
if (parseValue === next) {
|
|
311
309
|
need = false;
|
|
312
310
|
}
|
|
@@ -326,25 +324,7 @@
|
|
|
326
324
|
if (regex.test(value) && value.length >= 16 && +value > Number.MAX_SAFE_INTEGER) {
|
|
327
325
|
return value;
|
|
328
326
|
}
|
|
329
|
-
|
|
330
|
-
let safeCount = 1;
|
|
331
|
-
let parseValue = value;
|
|
332
|
-
while (need) {
|
|
333
|
-
if (safeCount > 10) {
|
|
334
|
-
throw new Error(value);
|
|
335
|
-
}
|
|
336
|
-
try {
|
|
337
|
-
let next = JSON.parse(parseValue);
|
|
338
|
-
if (parseValue === next) {
|
|
339
|
-
need = false;
|
|
340
|
-
}
|
|
341
|
-
parseValue = next;
|
|
342
|
-
} catch {
|
|
343
|
-
need = false;
|
|
344
|
-
}
|
|
345
|
-
safeCount++;
|
|
346
|
-
}
|
|
347
|
-
return parseValue;
|
|
327
|
+
return flatten(value, JSON.parse);
|
|
348
328
|
};
|
|
349
329
|
|
|
350
330
|
exports.asterisk = asterisk;
|
|
@@ -355,12 +335,11 @@
|
|
|
355
335
|
exports.dataURLToFile = dataURLToFile;
|
|
356
336
|
exports.debounce = debounce;
|
|
357
337
|
exports.def = def;
|
|
358
|
-
exports.
|
|
338
|
+
exports.flatten = flatten;
|
|
359
339
|
exports.flattenJSONParse = flattenJSONParse;
|
|
360
340
|
exports.getPropByPath = getPropByPath;
|
|
361
341
|
exports.getUid = getUid;
|
|
362
342
|
exports.hasOwn = hasOwn;
|
|
363
|
-
exports.isObj = isObj;
|
|
364
343
|
exports.numberToUnit = numberToUnit;
|
|
365
344
|
exports.preZero = preZero;
|
|
366
345
|
exports.probs = probs;
|