MCPcopy Create free account
hub / github.com/aiscript-dev/aiscript / valToString

Function valToString

src/interpreter/util.ts:110–128  ·  view source on GitHub ↗
(val: Value, simple = false)

Source from the content-addressed store, hash-verified

108}
109
110export function valToString(val: Value, simple = false): string {
111 if (simple) {
112 if (val.type === 'num') return val.value.toString();
113 if (val.type === 'bool') return val.value ? 'true' : 'false';
114 if (val.type === 'str') return `"${val.value}"`;
115 if (val.type === 'arr') return `[${val.value.map(item => valToString(item, true)).join(', ')}]`;
116 if (val.type === 'null') return '(null)';
117 }
118 const label =
119 val.type === 'num' ? val.value :
120 val.type === 'bool' ? val.value :
121 val.type === 'str' ? `"${val.value}"` :
122 val.type === 'fn' ? '...' :
123 val.type === 'obj' ? '...' :
124 val.type === 'null' ? '' :
125 null;
126
127 return `${val.type}<${label}>`;
128}
129
130export type JsValue = { [key: string]: JsValue } | JsValue[] | string | number | boolean | null | undefined;
131

Callers 3

outFunction · 0.85
logFunction · 0.85
outFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected