(v: any)
| 528 | } |
| 529 | |
| 530 | function jsValueToExpression(v: any): MathJsonExpression | null { |
| 531 | if (typeof v === 'string') { |
| 532 | return { str: v }; |
| 533 | } else if (typeof v === 'number') { |
| 534 | return { num: v.toString() }; |
| 535 | } else if (typeof v === 'boolean') { |
| 536 | return v ? 'True' : 'False'; |
| 537 | } else if (Array.isArray(v)) { |
| 538 | return ['List', ...v.map((x) => jsValueToExpression(x) ?? 'Nothing')]; |
| 539 | } else if (v === null) { |
| 540 | return null; |
| 541 | } else if (typeof v === 'object') { |
| 542 | const dict: Record<string, MathJsonExpression> = {}; |
| 543 | for (const key in v) { |
| 544 | dict[key] = jsValueToExpression(v[key]) ?? 'Nothing'; |
| 545 | } |
| 546 | return { dict }; |
| 547 | } |
| 548 | if ( |
| 549 | isFunctionObject(v) || |
| 550 | isSymbolObject(v) || |
| 551 | isNumberObject(v) || |
| 552 | isStringObject(v) || |
| 553 | isDictionaryObject(v) |
| 554 | ) { |
| 555 | return v as MathJsonExpression; |
| 556 | } |
| 557 | return null; |
| 558 | } |
| 559 | |
| 560 | function expressionToDictionaryValue( |
| 561 | expr: MathJsonExpression | null | undefined |
no test coverage detected