swarms
Version:
The ultimate node.js library for controlling Bitcraze Crazyflie 2.0 drones
49 lines • 1.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
class TOC {
/**
* Table of Contents. Represents an array of TOC items + some useful methods.
*/
constructor(items = []) {
this.items = items;
}
/**
* Add TOC item to the TOC array as long as it isn't a duplicate.
* Returns true if successfully added (no duplicate) otherwise false.
*/
addItem(item) {
// If there's an item already, then don't add
if (this.getItemById(item.id)) {
return false;
}
this.items.push(item);
this.items.sort((a, b) => a.id - b.id);
return true;
}
/**
* Gets an item by its group + name.
* Returns null if no item exists.
*/
getItem(group, name) {
for (const item of this.items) {
if (item.group === group && item.name === name) {
return item;
}
}
return null;
}
/**
* Returns TOC item with a certain id.
* Returns null if no item exists.
*/
getItemById(id) {
for (const item of this.items) {
if (item.id === id) {
return item;
}
}
return null;
}
}
exports.TOC = TOC;
//# sourceMappingURL=toc.js.map