MCPcopy Index your code
hub / github.com/aiscript-dev/aiscript / jsToVal

Function jsToVal

src/interpreter/util.ts:152–166  ·  view source on GitHub ↗
(val: unknown)

Source from the content-addressed store, hash-verified

150}
151
152export function jsToVal(val: unknown): Value {
153 if (val === null) return NULL;
154 if (typeof val === 'boolean') return BOOL(val);
155 if (typeof val === 'string') return STR(val);
156 if (typeof val === 'number') return NUM(val);
157 if (Array.isArray(val)) return ARR(val.map(item => jsToVal(item)));
158 if (typeof val === 'object') {
159 const obj: VObj['value'] = new Map();
160 for (const [k, v] of Object.entries(val)) {
161 obj.set(k, jsToVal(v));
162 }
163 return OBJ(obj);
164 }
165 return NULL;
166}
167
168export function getLangVersion(input: string): string | null {
169 const match = /^\s*\/\/\/\s*@\s*([A-Z0-9_.-]+)(?:[\r\n][\s\S]*)?$/i.exec(input);

Callers 2

std.tsFile · 0.85
stringifyMethod · 0.85

Calls 6

BOOLFunction · 0.85
STRFunction · 0.85
NUMFunction · 0.85
ARRFunction · 0.85
OBJFunction · 0.85
setMethod · 0.65

Tested by

no test coverage detected