add utils: date conversion

This commit is contained in:
Alex
2024-09-29 21:28:54 +02:00
parent f0ed8e3446
commit e56b58bd5f

View File

@@ -68,13 +68,20 @@ export function isEmpty(obj) {
}
return true;
}
/**
* Test whether or not an object is empty.
* @typedef {Object} FormattedError
* @property {string} error - The error message
* @property {number} id - A unique identifier for the error
*/
/**
* Format Error object(s)
* @param {any} obj - The object to test
* @returns `true` or `false`
* @returns @type {FormattedError[]}
*/
export function formatError(obj) {
/** @type {FormattedError[]} */
const errors = [];
if (typeof obj === "object" && obj !== null) {
if (Array.isArray(obj)) {
@@ -103,3 +110,9 @@ export function formatError(obj) {
return errors;
}
export function toRFC3339(dateString) {
if (!dateString) return "";
const date = new Date(dateString);
return date.toISOString();
}