@deot/helper-utils 1.1.2 → 1.1.4

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
@@ -3,10 +3,11 @@
3
3
  ### `Utils`
4
4
  ```js
5
5
  import * as Utils from '@deot/helper-utils';
6
+ ```
6
7
 
8
+ ```js
7
9
  // or
8
10
  import { Utils } from '@deot/helper';
9
-
10
11
  ```
11
12
 
12
13
  | 方法 | 说明 |
package/dist/index.cjs CHANGED
@@ -39,11 +39,11 @@ const dataURLToFile = (dataURL, filename, filetype) => {
39
39
  if (!hasPrefix) {
40
40
  dataURL = `data:${filetype || getMime(filename)};base64,${dataURL}`;
41
41
  }
42
- let [suffix, dataURL$] = dataURL.split(",");
43
- let mime = suffix.match(/:(.*?);/)?.[1];
44
- let bstr = window.atob(dataURL$);
42
+ const [suffix, dataURL$] = dataURL.split(",");
43
+ const mime = suffix.match(/:(.*?);/)?.[1];
44
+ const bstr = window.atob(dataURL$);
45
45
  let n = bstr.length;
46
- let u8arr = new Uint8Array(n);
46
+ const u8arr = new Uint8Array(n);
47
47
  while (n--) {
48
48
  u8arr[n] = bstr.charCodeAt(n);
49
49
  }
@@ -53,7 +53,7 @@ const dataURLToFile = (dataURL, filename, filetype) => {
53
53
  const canvasToImage = (canvas, filename) => {
54
54
  const dataURL = canvas.toDataURL("image/png");
55
55
  return new Promise((resolve) => {
56
- let result = {
56
+ const result = {
57
57
  dataURL
58
58
  };
59
59
  if (typeof filename === "string") {
@@ -113,11 +113,11 @@ const debounce = (original, wait, options) => {
113
113
  const { leading, trailing = true, throttle } = options || {};
114
114
  let timer;
115
115
  let invoke;
116
- let cancel = () => {
116
+ const cancel = () => {
117
117
  timer && clearTimeout(timer);
118
118
  timer = null;
119
119
  };
120
- let start = () => {
120
+ const start = () => {
121
121
  timer = setTimeout(() => {
122
122
  timer = null;
123
123
  trailing && invoke && invoke();
@@ -163,17 +163,17 @@ const getPropByPath = (target, path) => {
163
163
  let o = target;
164
164
  path = path.replace(/\[(\w+)\]/g, ".$1");
165
165
  path = path.replace(/^\./, "");
166
- let keyArr = path.split(".");
166
+ const keyArr = path.split(".");
167
167
  let i = 0;
168
168
  for (let len = keyArr.length; i < len - 1; ++i) {
169
- let key = keyArr[i];
169
+ const key = keyArr[i];
170
170
  try {
171
171
  if (key in o) {
172
172
  o = o[key];
173
173
  } else {
174
174
  throw new Error();
175
175
  }
176
- } catch {
176
+ } catch (_) {
177
177
  throw new Error("无效路径!");
178
178
  }
179
179
  }
@@ -201,7 +201,7 @@ const getDigit = (integer) => {
201
201
  return digit;
202
202
  };
203
203
  const addWan = (integer, num, mutiple, decimalDigit) => {
204
- let digit = getDigit(integer);
204
+ const digit = getDigit(integer);
205
205
  if (digit > 3) {
206
206
  let remainder = digit % 8;
207
207
  if (remainder >= 5) {
@@ -217,11 +217,11 @@ const numberToUnit = (number, decimalDigit) => {
217
217
  number = Number.MAX_SAFE_INTEGER;
218
218
  }
219
219
  decimalDigit = decimalDigit == null ? 2 : decimalDigit;
220
- let integer = Math.floor(number);
221
- let digit = getDigit(integer);
222
- let unit = [];
220
+ const integer = Math.floor(number);
221
+ const digit = getDigit(integer);
222
+ const unit = [];
223
223
  if (digit > 3) {
224
- let multiple = Math.floor(digit / 8);
224
+ const multiple = Math.floor(digit / 8);
225
225
  if (multiple >= 1) {
226
226
  let tmp = Math.round(integer / Math.pow(10, 8 * multiple));
227
227
  unit.push(addWan(tmp, number, 8 * multiple, decimalDigit));
@@ -252,11 +252,11 @@ const range = (min, max) => {
252
252
  return Math.floor(Math.random() * (max - min + 1) + min);
253
253
  };
254
254
  const probs = (weights) => {
255
- let sum = weights.reduce((pre, cur) => pre + (!cur || cur <= 0 ? 0 : cur), 0);
255
+ const sum = weights.reduce((pre, cur) => pre + (!cur || cur <= 0 ? 0 : cur), 0);
256
256
  if (!sum) {
257
257
  throw new Error("不可能得到索引值");
258
258
  }
259
- let probs$ = weights.map((i) => i / sum);
259
+ const probs$ = weights.map((i) => i / sum);
260
260
  let index = 0;
261
261
  let r = Math.random();
262
262
  while (r > 0) {
@@ -275,7 +275,7 @@ const sleep = (wait, immediate) => {
275
275
  duration = wait || 0;
276
276
  }
277
277
  return new Promise((r) => {
278
- let timer = setTimeout(r, duration);
278
+ const timer = setTimeout(r, duration);
279
279
  immediate && immediate(timer, duration, r);
280
280
  });
281
281
  };
@@ -302,12 +302,12 @@ const flatten = (value, parser) => {
302
302
  throw new Error(value);
303
303
  }
304
304
  try {
305
- let next = (parser || decodeURIComponent)(parseValue);
305
+ const next = (parser || decodeURIComponent)(parseValue);
306
306
  if (parseValue === next) {
307
307
  need = false;
308
308
  }
309
309
  parseValue = next;
310
- } catch {
310
+ } catch (_) {
311
311
  need = false;
312
312
  }
313
313
  safeCount++;
@@ -318,7 +318,7 @@ const flatten = (value, parser) => {
318
318
  const flattenJSONParse = (value) => {
319
319
  if (value === null)
320
320
  return null;
321
- let regex = /^\d+$/;
321
+ const regex = /^\d+$/;
322
322
  if (regex.test(value) && value.length >= 16 && +value > Number.MAX_SAFE_INTEGER) {
323
323
  return value;
324
324
  }
@@ -38,11 +38,11 @@ var HelperUtils = (function (exports) {
38
38
  if (!hasPrefix) {
39
39
  dataURL = `data:${filetype || getMime(filename)};base64,${dataURL}`;
40
40
  }
41
- let [suffix, dataURL$] = dataURL.split(",");
42
- let mime = suffix.match(/:(.*?);/)?.[1];
43
- let bstr = window.atob(dataURL$);
41
+ const [suffix, dataURL$] = dataURL.split(",");
42
+ const mime = suffix.match(/:(.*?);/)?.[1];
43
+ const bstr = window.atob(dataURL$);
44
44
  let n = bstr.length;
45
- let u8arr = new Uint8Array(n);
45
+ const u8arr = new Uint8Array(n);
46
46
  while (n--) {
47
47
  u8arr[n] = bstr.charCodeAt(n);
48
48
  }
@@ -52,7 +52,7 @@ var HelperUtils = (function (exports) {
52
52
  const canvasToImage = (canvas, filename) => {
53
53
  const dataURL = canvas.toDataURL("image/png");
54
54
  return new Promise((resolve) => {
55
- let result = {
55
+ const result = {
56
56
  dataURL
57
57
  };
58
58
  if (typeof filename === "string") {
@@ -112,11 +112,11 @@ var HelperUtils = (function (exports) {
112
112
  const { leading, trailing = true, throttle } = options || {};
113
113
  let timer;
114
114
  let invoke;
115
- let cancel = () => {
115
+ const cancel = () => {
116
116
  timer && clearTimeout(timer);
117
117
  timer = null;
118
118
  };
119
- let start = () => {
119
+ const start = () => {
120
120
  timer = setTimeout(() => {
121
121
  timer = null;
122
122
  trailing && invoke && invoke();
@@ -162,17 +162,17 @@ var HelperUtils = (function (exports) {
162
162
  let o = target;
163
163
  path = path.replace(/\[(\w+)\]/g, ".$1");
164
164
  path = path.replace(/^\./, "");
165
- let keyArr = path.split(".");
165
+ const keyArr = path.split(".");
166
166
  let i = 0;
167
167
  for (let len = keyArr.length; i < len - 1; ++i) {
168
- let key = keyArr[i];
168
+ const key = keyArr[i];
169
169
  try {
170
170
  if (key in o) {
171
171
  o = o[key];
172
172
  } else {
173
173
  throw new Error();
174
174
  }
175
- } catch {
175
+ } catch (_) {
176
176
  throw new Error("无效路径!");
177
177
  }
178
178
  }
@@ -200,7 +200,7 @@ var HelperUtils = (function (exports) {
200
200
  return digit;
201
201
  };
202
202
  const addWan = (integer, num, mutiple, decimalDigit) => {
203
- let digit = getDigit(integer);
203
+ const digit = getDigit(integer);
204
204
  if (digit > 3) {
205
205
  let remainder = digit % 8;
206
206
  if (remainder >= 5) {
@@ -216,11 +216,11 @@ var HelperUtils = (function (exports) {
216
216
  number = Number.MAX_SAFE_INTEGER;
217
217
  }
218
218
  decimalDigit = decimalDigit == null ? 2 : decimalDigit;
219
- let integer = Math.floor(number);
220
- let digit = getDigit(integer);
221
- let unit = [];
219
+ const integer = Math.floor(number);
220
+ const digit = getDigit(integer);
221
+ const unit = [];
222
222
  if (digit > 3) {
223
- let multiple = Math.floor(digit / 8);
223
+ const multiple = Math.floor(digit / 8);
224
224
  if (multiple >= 1) {
225
225
  let tmp = Math.round(integer / Math.pow(10, 8 * multiple));
226
226
  unit.push(addWan(tmp, number, 8 * multiple, decimalDigit));
@@ -251,11 +251,11 @@ var HelperUtils = (function (exports) {
251
251
  return Math.floor(Math.random() * (max - min + 1) + min);
252
252
  };
253
253
  const probs = (weights) => {
254
- let sum = weights.reduce((pre, cur) => pre + (!cur || cur <= 0 ? 0 : cur), 0);
254
+ const sum = weights.reduce((pre, cur) => pre + (!cur || cur <= 0 ? 0 : cur), 0);
255
255
  if (!sum) {
256
256
  throw new Error("不可能得到索引值");
257
257
  }
258
- let probs$ = weights.map((i) => i / sum);
258
+ const probs$ = weights.map((i) => i / sum);
259
259
  let index = 0;
260
260
  let r = Math.random();
261
261
  while (r > 0) {
@@ -274,7 +274,7 @@ var HelperUtils = (function (exports) {
274
274
  duration = wait || 0;
275
275
  }
276
276
  return new Promise((r) => {
277
- let timer = setTimeout(r, duration);
277
+ const timer = setTimeout(r, duration);
278
278
  immediate && immediate(timer, duration, r);
279
279
  });
280
280
  };
@@ -301,12 +301,12 @@ var HelperUtils = (function (exports) {
301
301
  throw new Error(value);
302
302
  }
303
303
  try {
304
- let next = (parser || decodeURIComponent)(parseValue);
304
+ const next = (parser || decodeURIComponent)(parseValue);
305
305
  if (parseValue === next) {
306
306
  need = false;
307
307
  }
308
308
  parseValue = next;
309
- } catch {
309
+ } catch (_) {
310
310
  need = false;
311
311
  }
312
312
  safeCount++;
@@ -317,7 +317,7 @@ var HelperUtils = (function (exports) {
317
317
  const flattenJSONParse = (value) => {
318
318
  if (value === null)
319
319
  return null;
320
- let regex = /^\d+$/;
320
+ const regex = /^\d+$/;
321
321
  if (regex.test(value) && value.length >= 16 && +value > Number.MAX_SAFE_INTEGER) {
322
322
  return value;
323
323
  }
package/dist/index.js CHANGED
@@ -35,11 +35,11 @@ const dataURLToFile = (dataURL, filename, filetype) => {
35
35
  if (!hasPrefix) {
36
36
  dataURL = `data:${filetype || getMime(filename)};base64,${dataURL}`;
37
37
  }
38
- let [suffix, dataURL$] = dataURL.split(",");
39
- let mime = suffix.match(/:(.*?);/)?.[1];
40
- let bstr = window.atob(dataURL$);
38
+ const [suffix, dataURL$] = dataURL.split(",");
39
+ const mime = suffix.match(/:(.*?);/)?.[1];
40
+ const bstr = window.atob(dataURL$);
41
41
  let n = bstr.length;
42
- let u8arr = new Uint8Array(n);
42
+ const u8arr = new Uint8Array(n);
43
43
  while (n--) {
44
44
  u8arr[n] = bstr.charCodeAt(n);
45
45
  }
@@ -49,7 +49,7 @@ const dataURLToFile = (dataURL, filename, filetype) => {
49
49
  const canvasToImage = (canvas, filename) => {
50
50
  const dataURL = canvas.toDataURL("image/png");
51
51
  return new Promise((resolve) => {
52
- let result = {
52
+ const result = {
53
53
  dataURL
54
54
  };
55
55
  if (typeof filename === "string") {
@@ -109,11 +109,11 @@ const debounce = (original, wait, options) => {
109
109
  const { leading, trailing = true, throttle } = options || {};
110
110
  let timer;
111
111
  let invoke;
112
- let cancel = () => {
112
+ const cancel = () => {
113
113
  timer && clearTimeout(timer);
114
114
  timer = null;
115
115
  };
116
- let start = () => {
116
+ const start = () => {
117
117
  timer = setTimeout(() => {
118
118
  timer = null;
119
119
  trailing && invoke && invoke();
@@ -159,17 +159,17 @@ const getPropByPath = (target, path) => {
159
159
  let o = target;
160
160
  path = path.replace(/\[(\w+)\]/g, ".$1");
161
161
  path = path.replace(/^\./, "");
162
- let keyArr = path.split(".");
162
+ const keyArr = path.split(".");
163
163
  let i = 0;
164
164
  for (let len = keyArr.length; i < len - 1; ++i) {
165
- let key = keyArr[i];
165
+ const key = keyArr[i];
166
166
  try {
167
167
  if (key in o) {
168
168
  o = o[key];
169
169
  } else {
170
170
  throw new Error();
171
171
  }
172
- } catch {
172
+ } catch (_) {
173
173
  throw new Error("无效路径!");
174
174
  }
175
175
  }
@@ -197,7 +197,7 @@ const getDigit = (integer) => {
197
197
  return digit;
198
198
  };
199
199
  const addWan = (integer, num, mutiple, decimalDigit) => {
200
- let digit = getDigit(integer);
200
+ const digit = getDigit(integer);
201
201
  if (digit > 3) {
202
202
  let remainder = digit % 8;
203
203
  if (remainder >= 5) {
@@ -213,11 +213,11 @@ const numberToUnit = (number, decimalDigit) => {
213
213
  number = Number.MAX_SAFE_INTEGER;
214
214
  }
215
215
  decimalDigit = decimalDigit == null ? 2 : decimalDigit;
216
- let integer = Math.floor(number);
217
- let digit = getDigit(integer);
218
- let unit = [];
216
+ const integer = Math.floor(number);
217
+ const digit = getDigit(integer);
218
+ const unit = [];
219
219
  if (digit > 3) {
220
- let multiple = Math.floor(digit / 8);
220
+ const multiple = Math.floor(digit / 8);
221
221
  if (multiple >= 1) {
222
222
  let tmp = Math.round(integer / Math.pow(10, 8 * multiple));
223
223
  unit.push(addWan(tmp, number, 8 * multiple, decimalDigit));
@@ -248,11 +248,11 @@ const range = (min, max) => {
248
248
  return Math.floor(Math.random() * (max - min + 1) + min);
249
249
  };
250
250
  const probs = (weights) => {
251
- let sum = weights.reduce((pre, cur) => pre + (!cur || cur <= 0 ? 0 : cur), 0);
251
+ const sum = weights.reduce((pre, cur) => pre + (!cur || cur <= 0 ? 0 : cur), 0);
252
252
  if (!sum) {
253
253
  throw new Error("不可能得到索引值");
254
254
  }
255
- let probs$ = weights.map((i) => i / sum);
255
+ const probs$ = weights.map((i) => i / sum);
256
256
  let index = 0;
257
257
  let r = Math.random();
258
258
  while (r > 0) {
@@ -271,7 +271,7 @@ const sleep = (wait, immediate) => {
271
271
  duration = wait || 0;
272
272
  }
273
273
  return new Promise((r) => {
274
- let timer = setTimeout(r, duration);
274
+ const timer = setTimeout(r, duration);
275
275
  immediate && immediate(timer, duration, r);
276
276
  });
277
277
  };
@@ -298,12 +298,12 @@ const flatten = (value, parser) => {
298
298
  throw new Error(value);
299
299
  }
300
300
  try {
301
- let next = (parser || decodeURIComponent)(parseValue);
301
+ const next = (parser || decodeURIComponent)(parseValue);
302
302
  if (parseValue === next) {
303
303
  need = false;
304
304
  }
305
305
  parseValue = next;
306
- } catch {
306
+ } catch (_) {
307
307
  need = false;
308
308
  }
309
309
  safeCount++;
@@ -314,7 +314,7 @@ const flatten = (value, parser) => {
314
314
  const flattenJSONParse = (value) => {
315
315
  if (value === null)
316
316
  return null;
317
- let regex = /^\d+$/;
317
+ const regex = /^\d+$/;
318
318
  if (regex.test(value) && value.length >= 16 && +value > Number.MAX_SAFE_INTEGER) {
319
319
  return value;
320
320
  }
@@ -41,11 +41,11 @@
41
41
  if (!hasPrefix) {
42
42
  dataURL = `data:${filetype || getMime(filename)};base64,${dataURL}`;
43
43
  }
44
- let [suffix, dataURL$] = dataURL.split(",");
45
- let mime = suffix.match(/:(.*?);/)?.[1];
46
- let bstr = window.atob(dataURL$);
44
+ const [suffix, dataURL$] = dataURL.split(",");
45
+ const mime = suffix.match(/:(.*?);/)?.[1];
46
+ const bstr = window.atob(dataURL$);
47
47
  let n = bstr.length;
48
- let u8arr = new Uint8Array(n);
48
+ const u8arr = new Uint8Array(n);
49
49
  while (n--) {
50
50
  u8arr[n] = bstr.charCodeAt(n);
51
51
  }
@@ -55,7 +55,7 @@
55
55
  const canvasToImage = (canvas, filename) => {
56
56
  const dataURL = canvas.toDataURL("image/png");
57
57
  return new Promise((resolve) => {
58
- let result = {
58
+ const result = {
59
59
  dataURL
60
60
  };
61
61
  if (typeof filename === "string") {
@@ -115,11 +115,11 @@
115
115
  const { leading, trailing = true, throttle } = options || {};
116
116
  let timer;
117
117
  let invoke;
118
- let cancel = () => {
118
+ const cancel = () => {
119
119
  timer && clearTimeout(timer);
120
120
  timer = null;
121
121
  };
122
- let start = () => {
122
+ const start = () => {
123
123
  timer = setTimeout(() => {
124
124
  timer = null;
125
125
  trailing && invoke && invoke();
@@ -165,17 +165,17 @@
165
165
  let o = target;
166
166
  path = path.replace(/\[(\w+)\]/g, ".$1");
167
167
  path = path.replace(/^\./, "");
168
- let keyArr = path.split(".");
168
+ const keyArr = path.split(".");
169
169
  let i = 0;
170
170
  for (let len = keyArr.length; i < len - 1; ++i) {
171
- let key = keyArr[i];
171
+ const key = keyArr[i];
172
172
  try {
173
173
  if (key in o) {
174
174
  o = o[key];
175
175
  } else {
176
176
  throw new Error();
177
177
  }
178
- } catch {
178
+ } catch (_) {
179
179
  throw new Error("无效路径!");
180
180
  }
181
181
  }
@@ -203,7 +203,7 @@
203
203
  return digit;
204
204
  };
205
205
  const addWan = (integer, num, mutiple, decimalDigit) => {
206
- let digit = getDigit(integer);
206
+ const digit = getDigit(integer);
207
207
  if (digit > 3) {
208
208
  let remainder = digit % 8;
209
209
  if (remainder >= 5) {
@@ -219,11 +219,11 @@
219
219
  number = Number.MAX_SAFE_INTEGER;
220
220
  }
221
221
  decimalDigit = decimalDigit == null ? 2 : decimalDigit;
222
- let integer = Math.floor(number);
223
- let digit = getDigit(integer);
224
- let unit = [];
222
+ const integer = Math.floor(number);
223
+ const digit = getDigit(integer);
224
+ const unit = [];
225
225
  if (digit > 3) {
226
- let multiple = Math.floor(digit / 8);
226
+ const multiple = Math.floor(digit / 8);
227
227
  if (multiple >= 1) {
228
228
  let tmp = Math.round(integer / Math.pow(10, 8 * multiple));
229
229
  unit.push(addWan(tmp, number, 8 * multiple, decimalDigit));
@@ -254,11 +254,11 @@
254
254
  return Math.floor(Math.random() * (max - min + 1) + min);
255
255
  };
256
256
  const probs = (weights) => {
257
- let sum = weights.reduce((pre, cur) => pre + (!cur || cur <= 0 ? 0 : cur), 0);
257
+ const sum = weights.reduce((pre, cur) => pre + (!cur || cur <= 0 ? 0 : cur), 0);
258
258
  if (!sum) {
259
259
  throw new Error("不可能得到索引值");
260
260
  }
261
- let probs$ = weights.map((i) => i / sum);
261
+ const probs$ = weights.map((i) => i / sum);
262
262
  let index = 0;
263
263
  let r = Math.random();
264
264
  while (r > 0) {
@@ -277,7 +277,7 @@
277
277
  duration = wait || 0;
278
278
  }
279
279
  return new Promise((r) => {
280
- let timer = setTimeout(r, duration);
280
+ const timer = setTimeout(r, duration);
281
281
  immediate && immediate(timer, duration, r);
282
282
  });
283
283
  };
@@ -304,12 +304,12 @@
304
304
  throw new Error(value);
305
305
  }
306
306
  try {
307
- let next = (parser || decodeURIComponent)(parseValue);
307
+ const next = (parser || decodeURIComponent)(parseValue);
308
308
  if (parseValue === next) {
309
309
  need = false;
310
310
  }
311
311
  parseValue = next;
312
- } catch {
312
+ } catch (_) {
313
313
  need = false;
314
314
  }
315
315
  safeCount++;
@@ -320,7 +320,7 @@
320
320
  const flattenJSONParse = (value) => {
321
321
  if (value === null)
322
322
  return null;
323
- let regex = /^\d+$/;
323
+ const regex = /^\d+$/;
324
324
  if (regex.test(value) && value.length >= 16 && +value > Number.MAX_SAFE_INTEGER) {
325
325
  return value;
326
326
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deot/helper-utils",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",