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