| 14 | }; |
| 15 | |
| 16 | function errorCode(expr: ErrorExpressionObject): string | undefined { |
| 17 | const code = expr.fn[1]; |
| 18 | if (typeof code === 'string') return code.replace(/^'|'$/g, ''); |
| 19 | if (code && typeof code === 'object' && !Array.isArray(code) && 'str' in code) |
| 20 | return code.str.replace(/^'|'$/g, ''); |
| 21 | if (Array.isArray(code) && code[0] === 'ErrorCode') { |
| 22 | const head = code[1]; |
| 23 | if (typeof head === 'string') return head.replace(/^'|'$/g, ''); |
| 24 | if (head && typeof head === 'object' && 'str' in head) |
| 25 | return head.str.replace(/^'|'$/g, ''); |
| 26 | } |
| 27 | return undefined; |
| 28 | } |
| 29 | |
| 30 | function collectErrors(expr: MathJsonExpression): ErrorExpressionObject[] { |
| 31 | const result: ErrorExpressionObject[] = []; |