@chix/flow
Version:
34 lines • 1.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
function handleIndex(link, data, packet) {
var index = link.source.get('index');
if (/^\d+/.test(index)) {
if (Array.isArray(data)) {
if (index < data.length) {
packet.point(link, index);
}
else {
throw Error("index[] out-of-bounds on array output port " + link.source.port);
}
}
else {
throw Error("Got index[] on array output port " + link.source.port + ", but data is not of the array type");
}
}
else {
if (typeof data === 'object') {
if (data.hasOwnProperty(index)) {
packet.point(link, index);
}
else {
console.log(packet);
throw Error("Property " + index + " not found on object output port " + link.source.port);
}
}
else {
throw Error("Got index[] on non-object output port " + link.source.port);
}
}
}
exports.handleIndex = handleIndex;
//# sourceMappingURL=handleIndex.js.map