MCPcopy Create free account
hub / github.com/xerrors/Yuxi / normalizeQuestions

Function normalizeQuestions

web/src/utils/questionUtils.js:50–81  ·  view source on GitHub ↗
(rawQuestions)

Source from the content-addressed store, hash-verified

48 * 规范化问题列表
49 */
50export const normalizeQuestions = (rawQuestions) => {
51 if (!Array.isArray(rawQuestions)) return []
52
53 return rawQuestions
54 .map((item, index) => {
55 if (!item || typeof item !== 'object') return null
56
57 const question = String(item.question || '').trim()
58 if (!question) return null
59
60 const questionId =
61 String(item.questionId || item.question_id || '').trim() || `q-${index + 1}`
62 const operation = String(item.operation || '').trim()
63 const allowOther = Boolean(item.allowOther ?? item.allow_other ?? true)
64 const baseOptions = normalizeOptions(item.options || [])
65 const hasOtherOption = baseOptions.some((option) => isOtherOption(option))
66 const options =
67 allowOther && !hasOtherOption
68 ? [...baseOptions, { label: '其他', value: DEFAULT_OTHER_OPTION_VALUE }]
69 : baseOptions
70
71 return {
72 questionId,
73 question,
74 options,
75 multiSelect: Boolean(item.multiSelect ?? item.multi_select ?? false),
76 allowOther,
77 operation
78 }
79 })
80 .filter(Boolean)
81}
82
83export { DEFAULT_OTHER_OPTION_VALUE }

Callers 1

extractQuestionPayloadFunction · 0.90

Calls 2

normalizeOptionsFunction · 0.85
isOtherOptionFunction · 0.85

Tested by

no test coverage detected