appwrite-utils-cli 0.0.274 → 0.0.275
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/README.md +4 -39
- package/dist/init.d.ts +2 -0
- package/dist/init.js +57 -0
- package/dist/main.js +62 -100
- package/dist/migrations/afterImportActions.d.ts +1 -4
- package/dist/migrations/afterImportActions.js +1 -0
- package/dist/migrations/appwriteToX.d.ts +46 -46
- package/dist/migrations/appwriteToX.js +6 -2
- package/dist/migrations/attributes.d.ts +1 -1
- package/dist/migrations/attributes.js +97 -71
- package/dist/migrations/backup.d.ts +240 -240
- package/dist/migrations/backup.js +1 -1
- package/dist/migrations/collections.d.ts +1 -1
- package/dist/migrations/collections.js +4 -4
- package/dist/migrations/converters.d.ts +9 -127
- package/dist/migrations/converters.js +1 -504
- package/dist/migrations/dataLoader.d.ts +470 -453
- package/dist/migrations/dataLoader.js +19 -1
- package/dist/migrations/dbHelpers.d.ts +1 -1
- package/dist/migrations/dbHelpers.js +3 -0
- package/dist/migrations/importController.d.ts +1 -1
- package/dist/migrations/importController.js +4 -7
- package/dist/migrations/importDataActions.d.ts +4 -6
- package/dist/migrations/importDataActions.js +6 -4
- package/dist/migrations/indexes.d.ts +1 -1
- package/dist/migrations/indexes.js +1 -1
- package/dist/migrations/migrationHelper.d.ts +29 -29
- package/dist/migrations/migrationHelper.js +1 -1
- package/dist/migrations/openapi.d.ts +1 -1
- package/dist/migrations/openapi.js +4 -1
- package/dist/migrations/queue.d.ts +1 -1
- package/dist/migrations/relationships.d.ts +5 -5
- package/dist/migrations/relationships.js +3 -0
- package/dist/migrations/schemaStrings.d.ts +2 -2
- package/dist/migrations/schemaStrings.js +93 -8
- package/dist/migrations/setupDatabase.d.ts +1 -1
- package/dist/migrations/setupDatabase.js +1 -1
- package/dist/migrations/storage.d.ts +1 -1
- package/dist/migrations/users.d.ts +1 -1
- package/dist/schemas/authUser.d.ts +12 -10
- package/dist/types.d.ts +0 -5
- package/dist/types.js +0 -2
- package/dist/utils/helperFunctions.d.ts +2 -3
- package/dist/utils/loadConfigs.d.ts +13 -0
- package/dist/utils/loadConfigs.js +47 -0
- package/dist/utils/setupFiles.d.ts +1 -0
- package/dist/utils/setupFiles.js +98 -223
- package/dist/utilsController.d.ts +1 -3
- package/dist/utilsController.js +14 -18
- package/package.json +9 -2
- package/src/init.ts +64 -0
- package/src/main.ts +73 -98
- package/src/migrations/afterImportActions.ts +1 -5
- package/src/migrations/appwriteToX.ts +6 -2
- package/src/migrations/attributes.ts +198 -150
- package/src/migrations/backup.ts +1 -1
- package/src/migrations/collections.ts +5 -11
- package/src/migrations/converters.ts +1 -540
- package/src/migrations/dataLoader.ts +19 -2
- package/src/migrations/dbHelpers.ts +4 -1
- package/src/migrations/importController.ts +5 -15
- package/src/migrations/importDataActions.ts +10 -14
- package/src/migrations/indexes.ts +1 -1
- package/src/migrations/migrationHelper.ts +1 -1
- package/src/migrations/openapi.ts +4 -1
- package/src/migrations/queue.ts +1 -1
- package/src/migrations/relationships.ts +4 -1
- package/src/migrations/schemaStrings.ts +106 -9
- package/src/migrations/setupDatabase.ts +1 -1
- package/src/migrations/storage.ts +1 -1
- package/src/migrations/users.ts +1 -1
- package/src/types.ts +0 -5
- package/src/utils/helperFunctions.ts +2 -3
- package/src/utils/loadConfigs.ts +55 -0
- package/src/utils/setupFiles.ts +114 -225
- package/src/utilsController.ts +27 -35
- package/src/migrations/schema.ts +0 -748
@@ -1,509 +1,6 @@
|
|
1
|
-
import { DateTime } from "luxon";
|
2
1
|
import _ from "lodash";
|
2
|
+
import { converterFunctions } from "appwrite-utils";
|
3
3
|
const { cloneDeep, isObject } = _;
|
4
|
-
export const converterFunctions = {
|
5
|
-
/**
|
6
|
-
* Converts any value to a string. Handles null and undefined explicitly.
|
7
|
-
* @param {any} value The value to convert.
|
8
|
-
* @return {string | null} The converted string or null if the value is null or undefined.
|
9
|
-
*/
|
10
|
-
anyToString(value) {
|
11
|
-
if (value == null)
|
12
|
-
return null;
|
13
|
-
return typeof value === "string" ? value : `${value}`;
|
14
|
-
},
|
15
|
-
/**
|
16
|
-
* Converts any value to a number. Returns null for non-numeric values, null, or undefined.
|
17
|
-
* @param {any} value The value to convert.
|
18
|
-
* @return {number | null} The converted number or null.
|
19
|
-
*/
|
20
|
-
anyToNumber(value) {
|
21
|
-
if (value == null)
|
22
|
-
return null;
|
23
|
-
const number = Number(value);
|
24
|
-
return isNaN(number) ? null : number;
|
25
|
-
},
|
26
|
-
/**
|
27
|
-
* Converts any value to a boolean. Specifically handles string representations.
|
28
|
-
* @param {any} value The value to convert.
|
29
|
-
* @return {boolean | null} The converted boolean or null if conversion is not possible.
|
30
|
-
*/
|
31
|
-
anyToBoolean(value) {
|
32
|
-
if (value == null)
|
33
|
-
return null;
|
34
|
-
if (typeof value === "string") {
|
35
|
-
const trimmedValue = value.trim().toLowerCase();
|
36
|
-
if (["true", "yes", "1"].includes(trimmedValue))
|
37
|
-
return true;
|
38
|
-
if (["false", "no", "0"].includes(trimmedValue))
|
39
|
-
return false;
|
40
|
-
return null; // Return null for strings that don't explicitly match
|
41
|
-
}
|
42
|
-
return Boolean(value);
|
43
|
-
},
|
44
|
-
/**
|
45
|
-
* Converts any value to an array, attempting to split strings by a specified separator.
|
46
|
-
* @param {any} value The value to convert.
|
47
|
-
* @param {string | undefined} separator The separator to use when splitting strings.
|
48
|
-
* @return {any[]} The resulting array after conversion.
|
49
|
-
*/
|
50
|
-
anyToAnyArray(value) {
|
51
|
-
if (Array.isArray(value)) {
|
52
|
-
return value;
|
53
|
-
}
|
54
|
-
else if (typeof value === "string") {
|
55
|
-
// Let's try a few
|
56
|
-
return converterFunctions.trySplitByDifferentSeparators(value);
|
57
|
-
}
|
58
|
-
return [value];
|
59
|
-
},
|
60
|
-
/**
|
61
|
-
* Converts any value to an array of strings. If the input is already an array, returns it as is.
|
62
|
-
* Otherwise, if the input is a string, returns an array with the string as the only element.
|
63
|
-
* Otherwise, returns an empty array.
|
64
|
-
* @param {any} value The value to convert.
|
65
|
-
* @return {string[]} The resulting array after conversion.
|
66
|
-
*/
|
67
|
-
anyToStringArray(value) {
|
68
|
-
if (Array.isArray(value)) {
|
69
|
-
return value.map((item) => String(item));
|
70
|
-
}
|
71
|
-
else if (typeof value === "string" && value.length > 0) {
|
72
|
-
return [value];
|
73
|
-
}
|
74
|
-
return [];
|
75
|
-
},
|
76
|
-
/**
|
77
|
-
* A function that converts any type of value to an array of numbers.
|
78
|
-
*
|
79
|
-
* @param {any} value - the value to be converted
|
80
|
-
* @return {number[]} an array of numbers
|
81
|
-
*/
|
82
|
-
anyToNumberArray(value) {
|
83
|
-
if (Array.isArray(value)) {
|
84
|
-
return value.map((item) => Number(item));
|
85
|
-
}
|
86
|
-
else if (typeof value === "string") {
|
87
|
-
return [Number(value)];
|
88
|
-
}
|
89
|
-
return [];
|
90
|
-
},
|
91
|
-
trim(value) {
|
92
|
-
try {
|
93
|
-
return value.trim();
|
94
|
-
}
|
95
|
-
catch (error) {
|
96
|
-
return value;
|
97
|
-
}
|
98
|
-
},
|
99
|
-
/**
|
100
|
-
* Removes the start and end quotes from a string.
|
101
|
-
* @param value The string to remove quotes from.
|
102
|
-
* @return The string with quotes removed.
|
103
|
-
**/
|
104
|
-
removeStartEndQuotes(value) {
|
105
|
-
return value.replace(/^["']|["']$/g, "");
|
106
|
-
},
|
107
|
-
/**
|
108
|
-
* Tries to split a string by different separators and returns the split that has the most uniform segment lengths.
|
109
|
-
* This can be particularly useful for structured data like phone numbers.
|
110
|
-
* @param value The string to split.
|
111
|
-
* @return The split string array that has the most uniform segment lengths.
|
112
|
-
*/
|
113
|
-
trySplitByDifferentSeparators(value) {
|
114
|
-
const separators = [",", ";", "|", ":", "/", "\\"];
|
115
|
-
let bestSplit = [];
|
116
|
-
let bestScore = -Infinity;
|
117
|
-
for (const separator of separators) {
|
118
|
-
const split = value.split(separator).map((s) => s.trim()); // Ensure we trim spaces
|
119
|
-
if (split.length <= 1)
|
120
|
-
continue; // Skip if no actual splitting occurred
|
121
|
-
// Calculate uniformity in segment length
|
122
|
-
const lengths = split.map((segment) => segment.length);
|
123
|
-
const averageLength = lengths.reduce((a, b) => a + b, 0) / lengths.length;
|
124
|
-
const lengthVariance = lengths.reduce((total, length) => total + Math.pow(length - averageLength, 2), 0) / lengths.length;
|
125
|
-
// Adjust scoring to prioritize splits with lower variance and/or specific segment count if needed
|
126
|
-
const score = split.length / (1 + lengthVariance); // Adjusted to prioritize lower variance
|
127
|
-
// Update bestSplit if this split has a better score
|
128
|
-
if (score > bestScore) {
|
129
|
-
bestSplit = split;
|
130
|
-
bestScore = score;
|
131
|
-
}
|
132
|
-
}
|
133
|
-
// If no suitable split was found, return the original value as a single-element array
|
134
|
-
if (bestSplit.length === 0) {
|
135
|
-
return [value];
|
136
|
-
}
|
137
|
-
return bestSplit;
|
138
|
-
},
|
139
|
-
joinValues(values) {
|
140
|
-
try {
|
141
|
-
return values.join("");
|
142
|
-
}
|
143
|
-
catch (error) {
|
144
|
-
return values;
|
145
|
-
}
|
146
|
-
},
|
147
|
-
joinBySpace(values) {
|
148
|
-
try {
|
149
|
-
return values.join(" ");
|
150
|
-
}
|
151
|
-
catch (error) {
|
152
|
-
return values;
|
153
|
-
}
|
154
|
-
},
|
155
|
-
joinByComma(values) {
|
156
|
-
try {
|
157
|
-
return values.join(",");
|
158
|
-
}
|
159
|
-
catch (error) {
|
160
|
-
return values;
|
161
|
-
}
|
162
|
-
},
|
163
|
-
joinByPipe(values) {
|
164
|
-
try {
|
165
|
-
return values.join("|");
|
166
|
-
}
|
167
|
-
catch (error) {
|
168
|
-
return values;
|
169
|
-
}
|
170
|
-
},
|
171
|
-
joinBySemicolon(values) {
|
172
|
-
try {
|
173
|
-
return values.join(";");
|
174
|
-
}
|
175
|
-
catch (error) {
|
176
|
-
return values;
|
177
|
-
}
|
178
|
-
},
|
179
|
-
joinByColon(values) {
|
180
|
-
try {
|
181
|
-
return values.join(":");
|
182
|
-
}
|
183
|
-
catch (error) {
|
184
|
-
return values;
|
185
|
-
}
|
186
|
-
},
|
187
|
-
joinBySlash(values) {
|
188
|
-
try {
|
189
|
-
return values.join("/");
|
190
|
-
}
|
191
|
-
catch (error) {
|
192
|
-
return values;
|
193
|
-
}
|
194
|
-
},
|
195
|
-
joinByHyphen(values) {
|
196
|
-
try {
|
197
|
-
return values.join("-");
|
198
|
-
}
|
199
|
-
catch (error) {
|
200
|
-
return values;
|
201
|
-
}
|
202
|
-
},
|
203
|
-
splitByComma(value) {
|
204
|
-
try {
|
205
|
-
return value.split(",");
|
206
|
-
}
|
207
|
-
catch (error) {
|
208
|
-
return value;
|
209
|
-
}
|
210
|
-
},
|
211
|
-
splitByPipe(value) {
|
212
|
-
try {
|
213
|
-
return value.split("|");
|
214
|
-
}
|
215
|
-
catch (error) {
|
216
|
-
return value;
|
217
|
-
}
|
218
|
-
},
|
219
|
-
splitBySemicolon(value) {
|
220
|
-
try {
|
221
|
-
return value.split(";");
|
222
|
-
}
|
223
|
-
catch (error) {
|
224
|
-
return value;
|
225
|
-
}
|
226
|
-
},
|
227
|
-
splitByColon(value) {
|
228
|
-
try {
|
229
|
-
return value.split(":");
|
230
|
-
}
|
231
|
-
catch (error) {
|
232
|
-
return value;
|
233
|
-
}
|
234
|
-
},
|
235
|
-
splitBySlash(value) {
|
236
|
-
try {
|
237
|
-
return value.split("/");
|
238
|
-
}
|
239
|
-
catch (error) {
|
240
|
-
return value;
|
241
|
-
}
|
242
|
-
},
|
243
|
-
splitByBackslash(value) {
|
244
|
-
try {
|
245
|
-
return value.split("\\");
|
246
|
-
}
|
247
|
-
catch (error) {
|
248
|
-
return value;
|
249
|
-
}
|
250
|
-
},
|
251
|
-
splitBySpace(value) {
|
252
|
-
try {
|
253
|
-
return value.split(" ");
|
254
|
-
}
|
255
|
-
catch (error) {
|
256
|
-
return value;
|
257
|
-
}
|
258
|
-
},
|
259
|
-
splitByDot(value) {
|
260
|
-
try {
|
261
|
-
return value.split(".");
|
262
|
-
}
|
263
|
-
catch (error) {
|
264
|
-
return value;
|
265
|
-
}
|
266
|
-
},
|
267
|
-
splitByUnderscore(value) {
|
268
|
-
try {
|
269
|
-
return value.split("_");
|
270
|
-
}
|
271
|
-
catch (error) {
|
272
|
-
return value;
|
273
|
-
}
|
274
|
-
},
|
275
|
-
splitByHyphen(value) {
|
276
|
-
try {
|
277
|
-
return value.split("-");
|
278
|
-
}
|
279
|
-
catch (error) {
|
280
|
-
return value;
|
281
|
-
}
|
282
|
-
},
|
283
|
-
/**
|
284
|
-
* Takes the first element of an array and returns it.
|
285
|
-
* @param {any[]} value The array to take the first element from.
|
286
|
-
* @return {any} The first element of the array.
|
287
|
-
*/
|
288
|
-
pickFirstElement(value) {
|
289
|
-
try {
|
290
|
-
return value[0];
|
291
|
-
}
|
292
|
-
catch (error) {
|
293
|
-
return value;
|
294
|
-
}
|
295
|
-
},
|
296
|
-
/**
|
297
|
-
* Takes the last element of an array and returns it.
|
298
|
-
* @param {any[]} value The array to take the last element from.
|
299
|
-
* @return {any} The last element of the array.
|
300
|
-
*/
|
301
|
-
pickLastElement(value) {
|
302
|
-
try {
|
303
|
-
return value[value.length - 1];
|
304
|
-
}
|
305
|
-
catch (error) {
|
306
|
-
return value;
|
307
|
-
}
|
308
|
-
},
|
309
|
-
/**
|
310
|
-
* Converts an object to a JSON string.
|
311
|
-
* @param {any} object The object to convert.
|
312
|
-
* @return {string} The JSON string representation of the object.
|
313
|
-
*/
|
314
|
-
stringifyObject(object) {
|
315
|
-
return JSON.stringify(object);
|
316
|
-
},
|
317
|
-
/**
|
318
|
-
* Converts a JSON string to an object.
|
319
|
-
* @param {string} jsonString The JSON string to convert.
|
320
|
-
* @return {any} The object representation of the JSON string.
|
321
|
-
*/
|
322
|
-
parseObject(jsonString) {
|
323
|
-
return JSON.parse(jsonString);
|
324
|
-
},
|
325
|
-
convertPhoneStringToUSInternational(value) {
|
326
|
-
// Normalize input: Remove all non-digit characters except the leading +
|
327
|
-
const normalizedValue = value.startsWith("+")
|
328
|
-
? "+" + value.slice(1).replace(/\D/g, "")
|
329
|
-
: value.replace(/\D/g, "");
|
330
|
-
// Check if the value is not a string or doesn't contain digits, return as is
|
331
|
-
if (typeof normalizedValue !== "string" || !/\d/.test(normalizedValue))
|
332
|
-
return value;
|
333
|
-
// Handle numbers with a leading + (indicating an international format)
|
334
|
-
if (normalizedValue.startsWith("+")) {
|
335
|
-
// If the number is already in a valid international format, return as is
|
336
|
-
if (normalizedValue.length > 11 && normalizedValue.length <= 15) {
|
337
|
-
return normalizedValue;
|
338
|
-
}
|
339
|
-
}
|
340
|
-
else {
|
341
|
-
// For numbers without a leading +, check the length and format
|
342
|
-
if (normalizedValue.length === 10) {
|
343
|
-
// US numbers without country code, prepend +1
|
344
|
-
return `+1${normalizedValue}`;
|
345
|
-
}
|
346
|
-
else if (normalizedValue.length === 11 &&
|
347
|
-
normalizedValue.startsWith("1")) {
|
348
|
-
// US numbers with country code but missing +, prepend +
|
349
|
-
return `+${normalizedValue}`;
|
350
|
-
}
|
351
|
-
}
|
352
|
-
// For numbers that don't fit expected formats, return the original value
|
353
|
-
return value;
|
354
|
-
},
|
355
|
-
convertEmptyToNull(value) {
|
356
|
-
if (Array.isArray(value)) {
|
357
|
-
return value.map((item) => this.convertEmptyToNull(item));
|
358
|
-
}
|
359
|
-
if (_.isEmpty(value))
|
360
|
-
return null;
|
361
|
-
return value;
|
362
|
-
},
|
363
|
-
/**
|
364
|
-
* A function that removes invalid elements from an array
|
365
|
-
*
|
366
|
-
* @param {any[]} array - the input array
|
367
|
-
* @return {any[]} the filtered array without invalid elements
|
368
|
-
*/
|
369
|
-
removeInvalidElements(array) {
|
370
|
-
if (!Array.isArray(array))
|
371
|
-
return array;
|
372
|
-
return _.filter(array, (element) => element !== null &&
|
373
|
-
element !== undefined &&
|
374
|
-
element !== "" &&
|
375
|
-
element !== "undefined" &&
|
376
|
-
element !== "null" &&
|
377
|
-
!_.isEmpty(element));
|
378
|
-
},
|
379
|
-
validateOrNullEmail(email) {
|
380
|
-
if (!email)
|
381
|
-
return null;
|
382
|
-
const emailRegex = /^[\w\-\.]+@([\w-]+\.)+[\w-]{2,}$/;
|
383
|
-
return emailRegex.test(email) ? email : null;
|
384
|
-
},
|
385
|
-
/**
|
386
|
-
* Tries to parse a date from various formats using Luxon with enhanced error reporting.
|
387
|
-
* @param {string | number} input The input date as a string or timestamp.
|
388
|
-
* @return {string | null} The parsed date in ISO 8601 format or null if parsing failed.
|
389
|
-
*/
|
390
|
-
safeParseDate(input) {
|
391
|
-
const formats = [
|
392
|
-
"M/d/yyyy HH:mm:ss", // U.S. style with time
|
393
|
-
"d/M/yyyy HH:mm:ss", // Rest of the world style with time
|
394
|
-
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", // ISO 8601 format
|
395
|
-
"yyyy-MM-dd'T'HH:mm:ss", // ISO 8601 without milliseconds
|
396
|
-
"yyyy-MM-dd HH:mm:ss", // SQL datetime format (common log format)
|
397
|
-
"M/d/yyyy", // U.S. style without time
|
398
|
-
"d/M/yyyy", // Rest of the world style without time
|
399
|
-
"yyyy-MM-dd", // ISO date format
|
400
|
-
"dd-MM-yyyy",
|
401
|
-
"MM-dd-yyyy",
|
402
|
-
"dd/MM/yyyy",
|
403
|
-
"MM/dd/yyyy",
|
404
|
-
"dd.MM.yyyy",
|
405
|
-
"MM.dd.yyyy",
|
406
|
-
"yyyy.MM.dd",
|
407
|
-
"yyyy/MM/dd",
|
408
|
-
"yyyy/MM/dd HH:mm",
|
409
|
-
"yyyy-MM-dd HH:mm",
|
410
|
-
"M/d/yyyy h:mm:ss tt", // U.S. style with 12-hour clock
|
411
|
-
"d/M/yyyy h:mm:ss tt", // Rest of the world style with 12-hour clock
|
412
|
-
"h:mm tt", // Time only with 12-hour clock
|
413
|
-
"HH:mm:ss", // Time only with 24-hour clock
|
414
|
-
"HH:mm", // Time only without seconds, 24-hour clock
|
415
|
-
"h:mm tt M/d/yyyy", // 12-hour clock time followed by U.S. style date
|
416
|
-
"h:mm tt d/M/yyyy", // 12-hour clock time followed by Rest of the world style date
|
417
|
-
"yyyy-MM-dd'T'HH:mm:ss.SSSZ", // ISO 8601 with timezone offset
|
418
|
-
"yyyy-MM-dd'T'HH:mm:ssZ", // ISO 8601 without milliseconds but with timezone offset
|
419
|
-
"E, dd MMM yyyy HH:mm:ss z", // RFC 2822 format
|
420
|
-
"EEEE, MMMM d, yyyy", // Full textual date
|
421
|
-
"yyyy-MM-dd'T'HH:mm:ss.SSSXXX", // ISO 8601 with extended timezone offset
|
422
|
-
"yyyy-MM-dd'T'HH:mm:ssXXX", // ISO 8601 without milliseconds but with extended timezone offset
|
423
|
-
"dd-MMM-yyyy", // Textual month with day and year
|
424
|
-
];
|
425
|
-
// Attempt to parse as a timestamp first if input is a number
|
426
|
-
if (typeof input === "number") {
|
427
|
-
const dateFromMillis = DateTime.fromMillis(input);
|
428
|
-
if (dateFromMillis.isValid) {
|
429
|
-
return dateFromMillis.toMillis();
|
430
|
-
}
|
431
|
-
}
|
432
|
-
// Attempt to parse as an ISO string or SQL string
|
433
|
-
let date = DateTime.fromISO(String(input));
|
434
|
-
if (!date.isValid)
|
435
|
-
date = DateTime.fromSQL(String(input));
|
436
|
-
// Try each custom format if still not valid
|
437
|
-
for (const format of formats) {
|
438
|
-
if (!date.isValid) {
|
439
|
-
date = DateTime.fromFormat(String(input), format);
|
440
|
-
}
|
441
|
-
}
|
442
|
-
// Return null if no valid date could be parsed
|
443
|
-
if (!date.isValid) {
|
444
|
-
return null;
|
445
|
-
}
|
446
|
-
return date.toMillis();
|
447
|
-
},
|
448
|
-
safeParseDateToYYYYMMDD(input) {
|
449
|
-
const formats = [
|
450
|
-
"M/d/yyyy HH:mm:ss", // U.S. style with time
|
451
|
-
"d/M/yyyy HH:mm:ss", // Rest of the world style with time
|
452
|
-
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", // ISO 8601 format
|
453
|
-
"yyyy-MM-dd'T'HH:mm:ss", // ISO 8601 without milliseconds
|
454
|
-
"yyyy-MM-dd HH:mm:ss", // SQL datetime format (common log format)
|
455
|
-
"M/d/yyyy", // U.S. style without time
|
456
|
-
"d/M/yyyy", // Rest of the world style without time
|
457
|
-
"yyyy-MM-dd", // ISO date format
|
458
|
-
"dd-MM-yyyy",
|
459
|
-
"MM-dd-yyyy",
|
460
|
-
"dd/MM/yyyy",
|
461
|
-
"MM/dd/yyyy",
|
462
|
-
"dd.MM.yyyy",
|
463
|
-
"MM.dd.yyyy",
|
464
|
-
"yyyy.MM.dd",
|
465
|
-
"yyyy/MM/dd",
|
466
|
-
"yyyy/MM/dd HH:mm",
|
467
|
-
"yyyy-MM-dd HH:mm",
|
468
|
-
"M/d/yyyy h:mm:ss tt", // U.S. style with 12-hour clock
|
469
|
-
"d/M/yyyy h:mm:ss tt", // Rest of the world style with 12-hour clock
|
470
|
-
"h:mm tt", // Time only with 12-hour clock
|
471
|
-
"HH:mm:ss", // Time only with 24-hour clock
|
472
|
-
"HH:mm", // Time only without seconds, 24-hour clock
|
473
|
-
"h:mm tt M/d/yyyy", // 12-hour clock time followed by U.S. style date
|
474
|
-
"h:mm tt d/M/yyyy", // 12-hour clock time followed by Rest of the world style date
|
475
|
-
"yyyy-MM-dd'T'HH:mm:ss.SSSZ", // ISO 8601 with timezone offset
|
476
|
-
"yyyy-MM-dd'T'HH:mm:ssZ", // ISO 8601 without milliseconds but with timezone offset
|
477
|
-
"E, dd MMM yyyy HH:mm:ss z", // RFC 2822 format
|
478
|
-
"EEEE, MMMM d, yyyy", // Full textual date
|
479
|
-
"yyyy-MM-dd'T'HH:mm:ss.SSSXXX", // ISO 8601 with extended timezone offset
|
480
|
-
"yyyy-MM-dd'T'HH:mm:ssXXX", // ISO 8601 without milliseconds but with extended timezone offset
|
481
|
-
"dd-MMM-yyyy", // Textual month with day and year
|
482
|
-
];
|
483
|
-
// Attempt to parse as a timestamp first if input is a number
|
484
|
-
if (typeof input === "number") {
|
485
|
-
const dateFromMillis = DateTime.fromMillis(input);
|
486
|
-
if (dateFromMillis.isValid) {
|
487
|
-
return dateFromMillis.toISODate();
|
488
|
-
}
|
489
|
-
}
|
490
|
-
// Attempt to parse as an ISO string or SQL string
|
491
|
-
let date = DateTime.fromISO(String(input));
|
492
|
-
if (!date.isValid)
|
493
|
-
date = DateTime.fromSQL(String(input));
|
494
|
-
// Try each custom format if still not valid
|
495
|
-
for (const format of formats) {
|
496
|
-
if (!date.isValid) {
|
497
|
-
date = DateTime.fromFormat(String(input), format);
|
498
|
-
}
|
499
|
-
}
|
500
|
-
// Return null if no valid date could be parsed
|
501
|
-
if (!date.isValid) {
|
502
|
-
return null;
|
503
|
-
}
|
504
|
-
return date.toISODate(); // Corrected to return the date in YYYY-MM-DD format
|
505
|
-
},
|
506
|
-
};
|
507
4
|
/**
|
508
5
|
* Deeply converts all properties of an object (or array) to strings.
|
509
6
|
* @param data The input data to convert.
|