@whitesev/utils 1.5.2 → 1.5.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/dist/index.umd.js CHANGED
@@ -4047,7 +4047,7 @@
4047
4047
  ];
4048
4048
  let androidVersion = UtilsContext.getRandomValue(12, 14);
4049
4049
  let randomMobile = UtilsContext.getRandomValue(mobileNameList);
4050
- let chromeVersion1 = UtilsContext.getRandomValue(115, 125);
4050
+ let chromeVersion1 = UtilsContext.getRandomValue(115, 127);
4051
4051
  let chromeVersion2 = UtilsContext.getRandomValue(0, 0);
4052
4052
  let chromeVersion3 = UtilsContext.getRandomValue(2272, 6099);
4053
4053
  let chromeVersion4 = UtilsContext.getRandomValue(1, 218);
@@ -4102,7 +4102,7 @@
4102
4102
  **/
4103
4103
  getRandomPCUA() {
4104
4104
  let UtilsContext = this;
4105
- let chromeVersion1 = UtilsContext.getRandomValue(115, 126);
4105
+ let chromeVersion1 = UtilsContext.getRandomValue(115, 127);
4106
4106
  let chromeVersion2 = UtilsContext.getRandomValue(0, 0);
4107
4107
  let chromeVersion3 = UtilsContext.getRandomValue(2272, 6099);
4108
4108
  let chromeVersion4 = UtilsContext.getRandomValue(1, 218);
@@ -6189,12 +6189,21 @@
6189
6189
  /**
6190
6190
  * 将对象转换为FormData
6191
6191
  * @param data 待转换的对象
6192
- * @param isEncode 是否对值为string进行编码转换(encodeURIComponent)
6192
+ * @param isEncode 是否对值为string进行编码转换(encodeURIComponent),默认false
6193
+ * @param valueAutoParseToStr 是否对值强制使用JSON.stringify()转换,默认false
6194
+ * @example
6195
+ * Utils.toFormData({
6196
+ * test: "1",
6197
+ * 666: 666,
6198
+ * })
6193
6199
  */
6194
- toFormData(data, isEncode = false) {
6200
+ toFormData(data, isEncode = false, valueAutoParseToStr = false) {
6195
6201
  const formData = new FormData();
6196
6202
  Object.keys(data).forEach((key) => {
6197
6203
  let value = data[key];
6204
+ if (valueAutoParseToStr) {
6205
+ value = JSON.stringify(value);
6206
+ }
6198
6207
  if (typeof value === "number") {
6199
6208
  value = value.toString();
6200
6209
  }
@@ -6210,6 +6219,22 @@
6210
6219
  });
6211
6220
  return formData;
6212
6221
  }
6222
+ /**
6223
+ * 生成uuid
6224
+ * @example
6225
+ * Utils.generateUUID()
6226
+ */
6227
+ generateUUID() {
6228
+ if (typeof globalThis?.crypto?.randomUUID === "function") {
6229
+ return globalThis.crypto.randomUUID();
6230
+ }
6231
+ else {
6232
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (charStr) {
6233
+ var randomValue = (Math.random() * 16) | 0, randomCharValue = charStr === "x" ? randomValue : (randomValue & 0x3) | 0x8;
6234
+ return randomCharValue.toString(16);
6235
+ });
6236
+ }
6237
+ }
6213
6238
  }
6214
6239
  let utils = new Utils();
6215
6240