@deot/helper-utils 1.0.1 → 1.0.3
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 +1 -1
- package/dist/index.cjs.js +19 -25
- package/dist/index.d.ts +6 -6
- package/dist/index.es.js +18 -24
- package/dist/index.iife.js +19 -25
- package/dist/index.umd.js +19 -25
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -24,10 +24,10 @@ 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 |
|
|
31
30
|
| [random][./src/random.ts] | `range` 和 `probs` |
|
|
32
31
|
| [sleep][./src/sleep.ts] | 等待 |
|
|
33
32
|
| [throttle][./src/throttle.ts] | 节流 |
|
|
33
|
+
| [genterateString][./src/genterate-string.ts] | 随机生成指定长度的字符串 |
|
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,21 @@ 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
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
} catch {
|
|
341
|
-
need = false;
|
|
342
|
-
}
|
|
343
|
-
safeCount++;
|
|
325
|
+
return flatten(value, JSON.parse);
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
const ALPHA = "abcdefghijklmnopqrstuvwxyz";
|
|
329
|
+
const DIGIT = "0123456789";
|
|
330
|
+
const BOUNDARY_ALPHABET = ALPHA + ALPHA.toUpperCase() + DIGIT + "-_";
|
|
331
|
+
const generateString = (size, alphabet) => {
|
|
332
|
+
size = size || 16;
|
|
333
|
+
alphabet = alphabet || BOUNDARY_ALPHABET;
|
|
334
|
+
let str = "";
|
|
335
|
+
const { length } = alphabet;
|
|
336
|
+
while (size--) {
|
|
337
|
+
str += alphabet[Math.random() * length | 0];
|
|
344
338
|
}
|
|
345
|
-
return
|
|
339
|
+
return str;
|
|
346
340
|
};
|
|
347
341
|
|
|
348
342
|
exports.asterisk = asterisk;
|
|
@@ -353,12 +347,12 @@ exports.compressImage = compressImage;
|
|
|
353
347
|
exports.dataURLToFile = dataURLToFile;
|
|
354
348
|
exports.debounce = debounce;
|
|
355
349
|
exports.def = def;
|
|
356
|
-
exports.
|
|
350
|
+
exports.flatten = flatten;
|
|
357
351
|
exports.flattenJSONParse = flattenJSONParse;
|
|
352
|
+
exports.generateString = generateString;
|
|
358
353
|
exports.getPropByPath = getPropByPath;
|
|
359
354
|
exports.getUid = getUid;
|
|
360
355
|
exports.hasOwn = hasOwn;
|
|
361
|
-
exports.isObj = isObj;
|
|
362
356
|
exports.numberToUnit = numberToUnit;
|
|
363
357
|
exports.preZero = preZero;
|
|
364
358
|
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,20 +28,20 @@ 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
|
|
|
37
|
+
export declare const generateString: (size?: number, alphabet?: string) => string;
|
|
38
|
+
|
|
37
39
|
export declare const getPropByPath: (target: object, path: string) => ObjectKeyValue;
|
|
38
40
|
|
|
39
41
|
export declare const getUid: (prefix?: string) => string;
|
|
40
42
|
|
|
41
43
|
export declare const hasOwn: (target: object, key: PropertyKey) => boolean;
|
|
42
44
|
|
|
43
|
-
export declare const isObj: (target?: any) => boolean;
|
|
44
|
-
|
|
45
45
|
export declare const numberToUnit: (number: number, decimalDigit?: number) => string | number;
|
|
46
46
|
|
|
47
47
|
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,21 @@ 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
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
} catch {
|
|
337
|
-
need = false;
|
|
338
|
-
}
|
|
339
|
-
safeCount++;
|
|
321
|
+
return flatten(value, JSON.parse);
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
const ALPHA = "abcdefghijklmnopqrstuvwxyz";
|
|
325
|
+
const DIGIT = "0123456789";
|
|
326
|
+
const BOUNDARY_ALPHABET = ALPHA + ALPHA.toUpperCase() + DIGIT + "-_";
|
|
327
|
+
const generateString = (size, alphabet) => {
|
|
328
|
+
size = size || 16;
|
|
329
|
+
alphabet = alphabet || BOUNDARY_ALPHABET;
|
|
330
|
+
let str = "";
|
|
331
|
+
const { length } = alphabet;
|
|
332
|
+
while (size--) {
|
|
333
|
+
str += alphabet[Math.random() * length | 0];
|
|
340
334
|
}
|
|
341
|
-
return
|
|
335
|
+
return str;
|
|
342
336
|
};
|
|
343
337
|
|
|
344
|
-
export { asterisk, autoCatch, canvasToImage, cloneDeepEasier, compressImage, dataURLToFile, debounce, def,
|
|
338
|
+
export { asterisk, autoCatch, canvasToImage, cloneDeepEasier, compressImage, dataURLToFile, debounce, def, flatten, flattenJSONParse, generateString, 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,21 @@ 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
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
} catch {
|
|
340
|
-
need = false;
|
|
341
|
-
}
|
|
342
|
-
safeCount++;
|
|
324
|
+
return flatten(value, JSON.parse);
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
const ALPHA = "abcdefghijklmnopqrstuvwxyz";
|
|
328
|
+
const DIGIT = "0123456789";
|
|
329
|
+
const BOUNDARY_ALPHABET = ALPHA + ALPHA.toUpperCase() + DIGIT + "-_";
|
|
330
|
+
const generateString = (size, alphabet) => {
|
|
331
|
+
size = size || 16;
|
|
332
|
+
alphabet = alphabet || BOUNDARY_ALPHABET;
|
|
333
|
+
let str = "";
|
|
334
|
+
const { length } = alphabet;
|
|
335
|
+
while (size--) {
|
|
336
|
+
str += alphabet[Math.random() * length | 0];
|
|
343
337
|
}
|
|
344
|
-
return
|
|
338
|
+
return str;
|
|
345
339
|
};
|
|
346
340
|
|
|
347
341
|
exports.asterisk = asterisk;
|
|
@@ -352,12 +346,12 @@ var HelperUtils = (function (exports) {
|
|
|
352
346
|
exports.dataURLToFile = dataURLToFile;
|
|
353
347
|
exports.debounce = debounce;
|
|
354
348
|
exports.def = def;
|
|
355
|
-
exports.
|
|
349
|
+
exports.flatten = flatten;
|
|
356
350
|
exports.flattenJSONParse = flattenJSONParse;
|
|
351
|
+
exports.generateString = generateString;
|
|
357
352
|
exports.getPropByPath = getPropByPath;
|
|
358
353
|
exports.getUid = getUid;
|
|
359
354
|
exports.hasOwn = hasOwn;
|
|
360
|
-
exports.isObj = isObj;
|
|
361
355
|
exports.numberToUnit = numberToUnit;
|
|
362
356
|
exports.preZero = preZero;
|
|
363
357
|
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,21 @@
|
|
|
326
324
|
if (regex.test(value) && value.length >= 16 && +value > Number.MAX_SAFE_INTEGER) {
|
|
327
325
|
return value;
|
|
328
326
|
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
} catch {
|
|
343
|
-
need = false;
|
|
344
|
-
}
|
|
345
|
-
safeCount++;
|
|
327
|
+
return flatten(value, JSON.parse);
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
const ALPHA = "abcdefghijklmnopqrstuvwxyz";
|
|
331
|
+
const DIGIT = "0123456789";
|
|
332
|
+
const BOUNDARY_ALPHABET = ALPHA + ALPHA.toUpperCase() + DIGIT + "-_";
|
|
333
|
+
const generateString = (size, alphabet) => {
|
|
334
|
+
size = size || 16;
|
|
335
|
+
alphabet = alphabet || BOUNDARY_ALPHABET;
|
|
336
|
+
let str = "";
|
|
337
|
+
const { length } = alphabet;
|
|
338
|
+
while (size--) {
|
|
339
|
+
str += alphabet[Math.random() * length | 0];
|
|
346
340
|
}
|
|
347
|
-
return
|
|
341
|
+
return str;
|
|
348
342
|
};
|
|
349
343
|
|
|
350
344
|
exports.asterisk = asterisk;
|
|
@@ -355,12 +349,12 @@
|
|
|
355
349
|
exports.dataURLToFile = dataURLToFile;
|
|
356
350
|
exports.debounce = debounce;
|
|
357
351
|
exports.def = def;
|
|
358
|
-
exports.
|
|
352
|
+
exports.flatten = flatten;
|
|
359
353
|
exports.flattenJSONParse = flattenJSONParse;
|
|
354
|
+
exports.generateString = generateString;
|
|
360
355
|
exports.getPropByPath = getPropByPath;
|
|
361
356
|
exports.getUid = getUid;
|
|
362
357
|
exports.hasOwn = hasOwn;
|
|
363
|
-
exports.isObj = isObj;
|
|
364
358
|
exports.numberToUnit = numberToUnit;
|
|
365
359
|
exports.preZero = preZero;
|
|
366
360
|
exports.probs = probs;
|