( expr: MathJsonExpression | null | undefined )
| 96 | * **U+0027 APOSTROPHE** : **`'`** or an object literal with a `str` key. |
| 97 | */ |
| 98 | export function stringValue( |
| 99 | expr: MathJsonExpression | null | undefined |
| 100 | ): string | null { |
| 101 | if (expr === null || expr === undefined) return null; |
| 102 | if (typeof expr === 'object' && 'str' in expr) return expr.str; |
| 103 | if (typeof expr !== 'string') return null; |
| 104 | if (expr.length >= 2 && expr.at(0) === "'" && expr.at(-1) === "'") |
| 105 | return expr.substring(1, expr.length - 1); |
| 106 | if (matchesNumber(expr) || matchesSymbol(expr)) return null; |
| 107 | return expr; |
| 108 | } |
| 109 | |
| 110 | export function stripText( |
| 111 | expr: MathJsonExpression | null | undefined |
no test coverage detected