index.d.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. declare class Queue<ValueType> implements Iterable<ValueType> {
  2. /**
  3. The size of the queue.
  4. */
  5. readonly size: number;
  6. /**
  7. Tiny queue data structure.
  8. The instance is an [`Iterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols), which means you can iterate over the queue front to back with a “for…of” loop, or use spreading to convert the queue to an array. Don't do this unless you really need to though, since it's slow.
  9. @example
  10. ```
  11. import Queue = require('yocto-queue');
  12. const queue = new Queue();
  13. queue.enqueue('🦄');
  14. queue.enqueue('🌈');
  15. console.log(queue.size);
  16. //=> 2
  17. console.log(...queue);
  18. //=> '🦄 🌈'
  19. console.log(queue.dequeue());
  20. //=> '🦄'
  21. console.log(queue.dequeue());
  22. //=> '🌈'
  23. ```
  24. */
  25. constructor();
  26. [Symbol.iterator](): IterableIterator<ValueType>;
  27. /**
  28. Add a value to the queue.
  29. */
  30. enqueue(value: ValueType): void;
  31. /**
  32. Remove the next value in the queue.
  33. @returns The removed value or `undefined` if the queue is empty.
  34. */
  35. dequeue(): ValueType | undefined;
  36. /**
  37. Clear the queue.
  38. */
  39. clear(): void;
  40. }
  41. export = Queue;