@strapi/utils 5.4.2 → 5.5.1

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.mjs CHANGED
@@ -59,8 +59,7 @@ const parseDate = (value) => {
59
59
  }
60
60
  try {
61
61
  const date = dates$1.parseISO(value);
62
- if (dates$1.isValid(date))
63
- return dates$1.format(date, "yyyy-MM-dd");
62
+ if (dates$1.isValid(date)) return dates$1.format(date, "yyyy-MM-dd");
64
63
  throw new Error(`Invalid format, expected an ISO compatible date`);
65
64
  } catch (error) {
66
65
  throw new Error(`Invalid format, expected an ISO compatible date`);
@@ -75,11 +74,9 @@ const parseDateTimeOrTimestamp = (value) => {
75
74
  }
76
75
  try {
77
76
  const date = dates$1.parseISO(value);
78
- if (dates$1.isValid(date))
79
- return date;
77
+ if (dates$1.isValid(date)) return date;
80
78
  const milliUnixDate = dates$1.parse(value, "T", /* @__PURE__ */ new Date());
81
- if (dates$1.isValid(milliUnixDate))
82
- return milliUnixDate;
79
+ if (dates$1.isValid(milliUnixDate)) return milliUnixDate;
83
80
  throw new Error(`Invalid format, expected a timestamp or an ISO date`);
84
81
  } catch (error) {
85
82
  throw new Error(`Invalid format, expected a timestamp or an ISO date`);
@@ -244,8 +241,7 @@ const getCreatorFields = (model) => {
244
241
  return attributes;
245
242
  };
246
243
  const getNonWritableAttributes = (model) => {
247
- if (!model)
248
- return [];
244
+ if (!model) return [];
249
245
  const nonWritableAttributes = ___default.reduce(
250
246
  model.attributes,
251
247
  (acc, attr, attrName) => attr.writable === false ? acc.concat(attrName) : acc,
@@ -259,8 +255,7 @@ const getNonWritableAttributes = (model) => {
259
255
  ]);
260
256
  };
261
257
  const getWritableAttributes = (model) => {
262
- if (!model)
263
- return [];
258
+ if (!model) return [];
264
259
  return ___default.difference(Object.keys(model.attributes), getNonWritableAttributes(model));
265
260
  };
266
261
  const isWritableAttribute = (model, attributeName) => {
@@ -330,8 +325,7 @@ const getComponentAttributes = (schema) => {
330
325
  return ___default.reduce(
331
326
  schema.attributes,
332
327
  (acc, attr, attrName) => {
333
- if (isComponentAttribute(attr))
334
- acc.push(attrName);
328
+ if (isComponentAttribute(attr)) acc.push(attrName);
335
329
  return acc;
336
330
  },
337
331
  []
@@ -341,8 +335,7 @@ const getScalarAttributes = (schema) => {
341
335
  return ___default.reduce(
342
336
  schema.attributes,
343
337
  (acc, attr, attrName) => {
344
- if (isScalarAttribute(attr))
345
- acc.push(attrName);
338
+ if (isScalarAttribute(attr)) acc.push(attrName);
346
339
  return acc;
347
340
  },
348
341
  []
@@ -352,8 +345,7 @@ const getRelationalAttributes = (schema) => {
352
345
  return ___default.reduce(
353
346
  schema.attributes,
354
347
  (acc, attr, attrName) => {
355
- if (isRelationalAttribute(attr))
356
- acc.push(attrName);
348
+ if (isRelationalAttribute(attr)) acc.push(attrName);
357
349
  return acc;
358
350
  },
359
351
  []
@@ -3177,8 +3169,7 @@ const kbytesToBytes = (kbytes) => kbytes * 1e3;
3177
3169
  const bytesToKbytes = (bytes) => Math.round(bytes / 1e3 * 100) / 100;
3178
3170
  const bytesToHumanReadable = (bytes) => {
3179
3171
  const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB"];
3180
- if (bytes === 0)
3181
- return "0 Bytes";
3172
+ if (bytes === 0) return "0 Bytes";
3182
3173
  const i = parseInt(`${Math.floor(Math.log(bytes) / Math.log(1e3))}`, 10);
3183
3174
  return `${Math.round(bytes / 1e3 ** i)} ${sizes[i]}`;
3184
3175
  };
@@ -3274,12 +3265,9 @@ const joinBy = (joint, ...args) => {
3274
3265
  const trimEnd = trimCharsEnd(joint);
3275
3266
  const trimStart = trimCharsStart(joint);
3276
3267
  return args.reduce((url, path, index2) => {
3277
- if (args.length === 1)
3278
- return path;
3279
- if (index2 === 0)
3280
- return trimEnd(path);
3281
- if (index2 === args.length - 1)
3282
- return url + joint + trimStart(path);
3268
+ if (args.length === 1) return path;
3269
+ if (index2 === 0) return trimEnd(path);
3270
+ if (index2 === args.length - 1) return url + joint + trimStart(path);
3283
3271
  return url + joint + trim2(path);
3284
3272
  }, "");
3285
3273
  };
@@ -3326,43 +3314,33 @@ const regExpToString = RegExp.prototype.toString;
3326
3314
  const symbolToString = typeof Symbol !== "undefined" ? Symbol.prototype.toString : () => "";
3327
3315
  const SYMBOL_REGEXP = /^Symbol\((.*)\)(.*)$/;
3328
3316
  function printNumber(val) {
3329
- if (val != +val)
3330
- return "NaN";
3317
+ if (val != +val) return "NaN";
3331
3318
  const isNegativeZero = val === 0 && 1 / val < 0;
3332
3319
  return isNegativeZero ? "-0" : `${val}`;
3333
3320
  }
3334
3321
  function printSimpleValue(val, quoteStrings = false) {
3335
- if (val == null || val === true || val === false)
3336
- return `${val}`;
3337
- if (typeof val === "number")
3338
- return printNumber(val);
3339
- if (typeof val === "string")
3340
- return quoteStrings ? `"${val}"` : val;
3341
- if (typeof val === "function")
3342
- return `[Function ${val.name || "anonymous"}]`;
3343
- if (typeof val === "symbol")
3344
- return symbolToString.call(val).replace(SYMBOL_REGEXP, "Symbol($1)");
3322
+ if (val == null || val === true || val === false) return `${val}`;
3323
+ if (typeof val === "number") return printNumber(val);
3324
+ if (typeof val === "string") return quoteStrings ? `"${val}"` : val;
3325
+ if (typeof val === "function") return `[Function ${val.name || "anonymous"}]`;
3326
+ if (typeof val === "symbol") return symbolToString.call(val).replace(SYMBOL_REGEXP, "Symbol($1)");
3345
3327
  const tag = toString.call(val).slice(8, -1);
3346
3328
  if (tag === "Date") {
3347
3329
  const v = val;
3348
3330
  return Number.isNaN(v.getTime()) ? `${v}` : v.toISOString();
3349
3331
  }
3350
- if (tag === "Error" || val instanceof Error)
3351
- return `[${errorToString.call(val)}]`;
3352
- if (tag === "RegExp")
3353
- return regExpToString.call(val);
3332
+ if (tag === "Error" || val instanceof Error) return `[${errorToString.call(val)}]`;
3333
+ if (tag === "RegExp") return regExpToString.call(val);
3354
3334
  return null;
3355
3335
  }
3356
3336
  function printValue(value, quoteStrings) {
3357
3337
  const result = printSimpleValue(value, quoteStrings);
3358
- if (result !== null)
3359
- return result;
3338
+ if (result !== null) return result;
3360
3339
  return JSON.stringify(
3361
3340
  value,
3362
3341
  function replacer(key, value2) {
3363
3342
  const result2 = printSimpleValue(this[key], quoteStrings);
3364
- if (result2 !== null)
3365
- return result2;
3343
+ if (result2 !== null) return result2;
3366
3344
  return value2;
3367
3345
  },
3368
3346
  2