@strapi/utils 5.4.1 → 5.5.0
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.js +23 -46
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +22 -44
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -15,8 +15,7 @@ const slugify = require("@sindresorhus/slugify");
|
|
|
15
15
|
const zod = require("zod");
|
|
16
16
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
17
17
|
function _interopNamespace(e) {
|
|
18
|
-
if (e && e.__esModule)
|
|
19
|
-
return e;
|
|
18
|
+
if (e && e.__esModule) return e;
|
|
20
19
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
21
20
|
if (e) {
|
|
22
21
|
for (const k in e) {
|
|
@@ -86,8 +85,7 @@ const parseDate = (value) => {
|
|
|
86
85
|
}
|
|
87
86
|
try {
|
|
88
87
|
const date = dates__namespace.parseISO(value);
|
|
89
|
-
if (dates__namespace.isValid(date))
|
|
90
|
-
return dates__namespace.format(date, "yyyy-MM-dd");
|
|
88
|
+
if (dates__namespace.isValid(date)) return dates__namespace.format(date, "yyyy-MM-dd");
|
|
91
89
|
throw new Error(`Invalid format, expected an ISO compatible date`);
|
|
92
90
|
} catch (error) {
|
|
93
91
|
throw new Error(`Invalid format, expected an ISO compatible date`);
|
|
@@ -102,11 +100,9 @@ const parseDateTimeOrTimestamp = (value) => {
|
|
|
102
100
|
}
|
|
103
101
|
try {
|
|
104
102
|
const date = dates__namespace.parseISO(value);
|
|
105
|
-
if (dates__namespace.isValid(date))
|
|
106
|
-
return date;
|
|
103
|
+
if (dates__namespace.isValid(date)) return date;
|
|
107
104
|
const milliUnixDate = dates__namespace.parse(value, "T", /* @__PURE__ */ new Date());
|
|
108
|
-
if (dates__namespace.isValid(milliUnixDate))
|
|
109
|
-
return milliUnixDate;
|
|
105
|
+
if (dates__namespace.isValid(milliUnixDate)) return milliUnixDate;
|
|
110
106
|
throw new Error(`Invalid format, expected a timestamp or an ISO date`);
|
|
111
107
|
} catch (error) {
|
|
112
108
|
throw new Error(`Invalid format, expected a timestamp or an ISO date`);
|
|
@@ -271,8 +267,7 @@ const getCreatorFields = (model) => {
|
|
|
271
267
|
return attributes;
|
|
272
268
|
};
|
|
273
269
|
const getNonWritableAttributes = (model) => {
|
|
274
|
-
if (!model)
|
|
275
|
-
return [];
|
|
270
|
+
if (!model) return [];
|
|
276
271
|
const nonWritableAttributes = ___namespace.default.reduce(
|
|
277
272
|
model.attributes,
|
|
278
273
|
(acc, attr, attrName) => attr.writable === false ? acc.concat(attrName) : acc,
|
|
@@ -286,8 +281,7 @@ const getNonWritableAttributes = (model) => {
|
|
|
286
281
|
]);
|
|
287
282
|
};
|
|
288
283
|
const getWritableAttributes = (model) => {
|
|
289
|
-
if (!model)
|
|
290
|
-
return [];
|
|
284
|
+
if (!model) return [];
|
|
291
285
|
return ___namespace.default.difference(Object.keys(model.attributes), getNonWritableAttributes(model));
|
|
292
286
|
};
|
|
293
287
|
const isWritableAttribute = (model, attributeName) => {
|
|
@@ -357,8 +351,7 @@ const getComponentAttributes = (schema) => {
|
|
|
357
351
|
return ___namespace.default.reduce(
|
|
358
352
|
schema.attributes,
|
|
359
353
|
(acc, attr, attrName) => {
|
|
360
|
-
if (isComponentAttribute(attr))
|
|
361
|
-
acc.push(attrName);
|
|
354
|
+
if (isComponentAttribute(attr)) acc.push(attrName);
|
|
362
355
|
return acc;
|
|
363
356
|
},
|
|
364
357
|
[]
|
|
@@ -368,8 +361,7 @@ const getScalarAttributes = (schema) => {
|
|
|
368
361
|
return ___namespace.default.reduce(
|
|
369
362
|
schema.attributes,
|
|
370
363
|
(acc, attr, attrName) => {
|
|
371
|
-
if (isScalarAttribute(attr))
|
|
372
|
-
acc.push(attrName);
|
|
364
|
+
if (isScalarAttribute(attr)) acc.push(attrName);
|
|
373
365
|
return acc;
|
|
374
366
|
},
|
|
375
367
|
[]
|
|
@@ -379,8 +371,7 @@ const getRelationalAttributes = (schema) => {
|
|
|
379
371
|
return ___namespace.default.reduce(
|
|
380
372
|
schema.attributes,
|
|
381
373
|
(acc, attr, attrName) => {
|
|
382
|
-
if (isRelationalAttribute(attr))
|
|
383
|
-
acc.push(attrName);
|
|
374
|
+
if (isRelationalAttribute(attr)) acc.push(attrName);
|
|
384
375
|
return acc;
|
|
385
376
|
},
|
|
386
377
|
[]
|
|
@@ -3204,8 +3195,7 @@ const kbytesToBytes = (kbytes) => kbytes * 1e3;
|
|
|
3204
3195
|
const bytesToKbytes = (bytes) => Math.round(bytes / 1e3 * 100) / 100;
|
|
3205
3196
|
const bytesToHumanReadable = (bytes) => {
|
|
3206
3197
|
const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB"];
|
|
3207
|
-
if (bytes === 0)
|
|
3208
|
-
return "0 Bytes";
|
|
3198
|
+
if (bytes === 0) return "0 Bytes";
|
|
3209
3199
|
const i = parseInt(`${Math.floor(Math.log(bytes) / Math.log(1e3))}`, 10);
|
|
3210
3200
|
return `${Math.round(bytes / 1e3 ** i)} ${sizes[i]}`;
|
|
3211
3201
|
};
|
|
@@ -3301,12 +3291,9 @@ const joinBy = (joint, ...args) => {
|
|
|
3301
3291
|
const trimEnd = fp.trimCharsEnd(joint);
|
|
3302
3292
|
const trimStart = fp.trimCharsStart(joint);
|
|
3303
3293
|
return args.reduce((url, path, index2) => {
|
|
3304
|
-
if (args.length === 1)
|
|
3305
|
-
|
|
3306
|
-
if (index2 ===
|
|
3307
|
-
return trimEnd(path);
|
|
3308
|
-
if (index2 === args.length - 1)
|
|
3309
|
-
return url + joint + trimStart(path);
|
|
3294
|
+
if (args.length === 1) return path;
|
|
3295
|
+
if (index2 === 0) return trimEnd(path);
|
|
3296
|
+
if (index2 === args.length - 1) return url + joint + trimStart(path);
|
|
3310
3297
|
return url + joint + trim(path);
|
|
3311
3298
|
}, "");
|
|
3312
3299
|
};
|
|
@@ -3353,43 +3340,33 @@ const regExpToString = RegExp.prototype.toString;
|
|
|
3353
3340
|
const symbolToString = typeof Symbol !== "undefined" ? Symbol.prototype.toString : () => "";
|
|
3354
3341
|
const SYMBOL_REGEXP = /^Symbol\((.*)\)(.*)$/;
|
|
3355
3342
|
function printNumber(val) {
|
|
3356
|
-
if (val != +val)
|
|
3357
|
-
return "NaN";
|
|
3343
|
+
if (val != +val) return "NaN";
|
|
3358
3344
|
const isNegativeZero = val === 0 && 1 / val < 0;
|
|
3359
3345
|
return isNegativeZero ? "-0" : `${val}`;
|
|
3360
3346
|
}
|
|
3361
3347
|
function printSimpleValue(val, quoteStrings = false) {
|
|
3362
|
-
if (val == null || val === true || val === false)
|
|
3363
|
-
|
|
3364
|
-
if (typeof val === "
|
|
3365
|
-
|
|
3366
|
-
if (typeof val === "
|
|
3367
|
-
return quoteStrings ? `"${val}"` : val;
|
|
3368
|
-
if (typeof val === "function")
|
|
3369
|
-
return `[Function ${val.name || "anonymous"}]`;
|
|
3370
|
-
if (typeof val === "symbol")
|
|
3371
|
-
return symbolToString.call(val).replace(SYMBOL_REGEXP, "Symbol($1)");
|
|
3348
|
+
if (val == null || val === true || val === false) return `${val}`;
|
|
3349
|
+
if (typeof val === "number") return printNumber(val);
|
|
3350
|
+
if (typeof val === "string") return quoteStrings ? `"${val}"` : val;
|
|
3351
|
+
if (typeof val === "function") return `[Function ${val.name || "anonymous"}]`;
|
|
3352
|
+
if (typeof val === "symbol") return symbolToString.call(val).replace(SYMBOL_REGEXP, "Symbol($1)");
|
|
3372
3353
|
const tag = toString.call(val).slice(8, -1);
|
|
3373
3354
|
if (tag === "Date") {
|
|
3374
3355
|
const v = val;
|
|
3375
3356
|
return Number.isNaN(v.getTime()) ? `${v}` : v.toISOString();
|
|
3376
3357
|
}
|
|
3377
|
-
if (tag === "Error" || val instanceof Error)
|
|
3378
|
-
|
|
3379
|
-
if (tag === "RegExp")
|
|
3380
|
-
return regExpToString.call(val);
|
|
3358
|
+
if (tag === "Error" || val instanceof Error) return `[${errorToString.call(val)}]`;
|
|
3359
|
+
if (tag === "RegExp") return regExpToString.call(val);
|
|
3381
3360
|
return null;
|
|
3382
3361
|
}
|
|
3383
3362
|
function printValue(value, quoteStrings) {
|
|
3384
3363
|
const result = printSimpleValue(value, quoteStrings);
|
|
3385
|
-
if (result !== null)
|
|
3386
|
-
return result;
|
|
3364
|
+
if (result !== null) return result;
|
|
3387
3365
|
return JSON.stringify(
|
|
3388
3366
|
value,
|
|
3389
3367
|
function replacer(key, value2) {
|
|
3390
3368
|
const result2 = printSimpleValue(this[key], quoteStrings);
|
|
3391
|
-
if (result2 !== null)
|
|
3392
|
-
return result2;
|
|
3369
|
+
if (result2 !== null) return result2;
|
|
3393
3370
|
return value2;
|
|
3394
3371
|
},
|
|
3395
3372
|
2
|