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