@jplorg/jpl
Version:
JPL interpreter
32 lines (25 loc) • 758 B
JavaScript
import { JPLTypeError } from '../../../library';
export default {
/** { optional: boolean } */
op(runtime, input, target, params, scope, next) {
const value = runtime.unwrapValue(target);
const t = runtime.type(value);
switch (t) {
case 'object':
return runtime.muxAll([Object.values(value)], next);
case 'array':
return runtime.muxAll([value], next);
case 'string':
return runtime.muxAll([[...value]], next);
default:
}
if (params.optional) return [];
throw new JPLTypeError('cannot iterate over %s (%*<100v)', t, value);
},
/** { optional: boolean } */
map(runtime, params) {
return {
optional: runtime.assertType(params.optional, 'boolean'),
};
},
};