@deot/helper-utils 1.0.2 → 1.1.0

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
@@ -30,3 +30,4 @@ import { Utils } from '@deot/helper';
30
30
  | [random][./src/random.ts] | `range` 和 `probs` |
31
31
  | [sleep][./src/sleep.ts] | 等待 |
32
32
  | [throttle][./src/throttle.ts] | 节流 |
33
+ | [genterateString][./src/genterate-string.ts] | 随机生成指定长度的字符串 |
package/dist/index.cjs.js CHANGED
@@ -325,6 +325,20 @@ const flattenJSONParse = (value) => {
325
325
  return flatten(value, JSON.parse);
326
326
  };
327
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];
338
+ }
339
+ return str;
340
+ };
341
+
328
342
  exports.asterisk = asterisk;
329
343
  exports.autoCatch = autoCatch;
330
344
  exports.canvasToImage = canvasToImage;
@@ -335,6 +349,7 @@ exports.debounce = debounce;
335
349
  exports.def = def;
336
350
  exports.flatten = flatten;
337
351
  exports.flattenJSONParse = flattenJSONParse;
352
+ exports.generateString = generateString;
338
353
  exports.getPropByPath = getPropByPath;
339
354
  exports.getUid = getUid;
340
355
  exports.hasOwn = hasOwn;
package/dist/index.d.ts CHANGED
@@ -34,6 +34,8 @@ export declare const flatten: (value: any, parser?: ((x: any) => any) | undefine
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;
package/dist/index.es.js CHANGED
@@ -321,4 +321,18 @@ const flattenJSONParse = (value) => {
321
321
  return flatten(value, JSON.parse);
322
322
  };
323
323
 
324
- export { asterisk, autoCatch, canvasToImage, cloneDeepEasier, compressImage, dataURLToFile, debounce, def, flatten, flattenJSONParse, getPropByPath, getUid, hasOwn, numberToUnit, preZero, probs, raf, range, sleep, throttle };
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];
334
+ }
335
+ return str;
336
+ };
337
+
338
+ export { asterisk, autoCatch, canvasToImage, cloneDeepEasier, compressImage, dataURLToFile, debounce, def, flatten, flattenJSONParse, generateString, getPropByPath, getUid, hasOwn, numberToUnit, preZero, probs, raf, range, sleep, throttle };
@@ -324,6 +324,20 @@ var HelperUtils = (function (exports) {
324
324
  return flatten(value, JSON.parse);
325
325
  };
326
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];
337
+ }
338
+ return str;
339
+ };
340
+
327
341
  exports.asterisk = asterisk;
328
342
  exports.autoCatch = autoCatch;
329
343
  exports.canvasToImage = canvasToImage;
@@ -334,6 +348,7 @@ var HelperUtils = (function (exports) {
334
348
  exports.def = def;
335
349
  exports.flatten = flatten;
336
350
  exports.flattenJSONParse = flattenJSONParse;
351
+ exports.generateString = generateString;
337
352
  exports.getPropByPath = getPropByPath;
338
353
  exports.getUid = getUid;
339
354
  exports.hasOwn = hasOwn;
package/dist/index.umd.js CHANGED
@@ -327,6 +327,20 @@
327
327
  return flatten(value, JSON.parse);
328
328
  };
329
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];
340
+ }
341
+ return str;
342
+ };
343
+
330
344
  exports.asterisk = asterisk;
331
345
  exports.autoCatch = autoCatch;
332
346
  exports.canvasToImage = canvasToImage;
@@ -337,6 +351,7 @@
337
351
  exports.def = def;
338
352
  exports.flatten = flatten;
339
353
  exports.flattenJSONParse = flattenJSONParse;
354
+ exports.generateString = generateString;
340
355
  exports.getPropByPath = getPropByPath;
341
356
  exports.getUid = getUid;
342
357
  exports.hasOwn = hasOwn;
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@deot/helper-utils",
3
- "version": "1.0.2",
4
- "main": "dist/index.cjs.js",
5
- "module": "dist/index.es.js",
3
+ "version": "1.1.0",
4
+ "type": "module",
5
+ "main": "dist/index.es.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {
8
8
  ".": {