MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / jsValueToExpression

Function jsValueToExpression

src/math-json/utils.ts:530–558  ·  view source on GitHub ↗
(v: any)

Source from the content-addressed store, hash-verified

528}
529
530function 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
560function expressionToDictionaryValue(
561 expr: MathJsonExpression | null | undefined

Callers 1

dictionaryFromEntriesFunction · 0.85

Calls 7

isFunctionObjectFunction · 0.85
isSymbolObjectFunction · 0.85
isNumberObjectFunction · 0.85
isStringObjectFunction · 0.85
isDictionaryObjectFunction · 0.85
toStringMethod · 0.65
mapMethod · 0.65

Tested by

no test coverage detected