UNPKG

@contentstack/cli-variants

Version:

Variants plugin

28 lines (27 loc) 886 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.formatErrors = formatErrors; /** * Formats the errors into a single string. * @param errors - The errors to be formatted. * @returns The formatted errors as a string. */ function formatErrors(errors) { const errorMessages = []; for (const errorKey in errors) { const errorValue = errors[errorKey]; if (Array.isArray(errorValue)) { errorMessages.push(...errorValue.map((error) => formatError(errorKey, error))); } else { errorMessages.push(formatError(errorKey, errorValue)); } } return errorMessages.join(' '); } function formatError(errorKey, error) { if (typeof error === 'object' && error !== null) { return `${errorKey}: ${Object.values(error).join(' ')}`; } return `${errorKey}: ${error}`; }