UNPKG

@instructure/quiz-interactions

Version:

A React UI component Library for quiz interaction types.

33 lines (32 loc) 879 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.normalizeErrors = normalizeErrors; /** * This function converts errors into a format that can be used by InstUI components. * * @param {string[] | import('@instructure/ui-form-field').FormFieldMessage} errors - The errors to normalize * @returns {import('@instructure/ui-form-field').FormFieldMessage[]} The normalized errors */ function normalizeErrors(errors) { if (errors == null) { return []; } return errors.map(function (error) { if (typeof error === 'string') { return { text: error, type: 'newError' }; } if (error.type !== 'error' && error.type !== 'newError') { // This is a fallback for any other type of message return error; } return { text: error.text || '', type: 'newError' }; }); }