{"_id":"yocto-queue","_rev":"4106779","name":"yocto-queue","description":"Tiny queue data structure","dist-tags":{"latest":"1.2.2"},"maintainers":[{"name":"sindresorhus","email":""}],"time":{"modified":"2026-01-11T18:56:32.000Z","created":"2020-11-24T05:59:48.904Z","1.2.2":"2025-11-11T06:32:08.991Z","1.2.1":"2025-03-22T05:49:38.400Z","1.2.0":"2025-03-06T12:29:40.450Z","1.1.1":"2024-06-29T22:12:50.399Z","1.1.0":"2024-06-28T20:50:10.833Z","1.0.0":"2021-08-12T23:48:33.113Z","0.1.0":"2020-11-24T06:05:35.875Z","0.0.0":"2020-11-24T05:59:48.904Z"},"users":{},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"repository":{"type":"git","url":"git+https://github.com/sindresorhus/yocto-queue.git"},"versions":{"1.2.2":{"name":"yocto-queue","version":"1.2.2","description":"Tiny queue data structure","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/yocto-queue.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":"./index.js","types":"./index.d.ts","sideEffects":false,"engines":{"node":">=12.20"},"scripts":{"//test":"xo && ava && tsd","test":"ava && tsd"},"keywords":["queue","data","structure","algorithm","queues","queuing","list","array","linkedlist","fifo","enqueue","dequeue","data-structure"],"devDependencies":{"ava":"^3.15.0","tsd":"^0.17.0","xo":"^0.44.0"},"gitHead":"b07eac099753833b29d06c614149904445739776","_id":"yocto-queue@1.2.2","bugs":{"url":"https://github.com/sindresorhus/yocto-queue/issues"},"homepage":"https://github.com/sindresorhus/yocto-queue#readme","_nodeVersion":"20.19.5","_npmVersion":"11.6.1","dist":{"shasum":"3e09c95d3f1aa89a58c114c99223edf639152c00","size":3244,"noattachment":false,"key":"/yocto-queue/-/yocto-queue-1.2.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/yocto-queue/download/yocto-queue-1.2.2.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/yocto-queue_1.2.2_1762842728792_0.5515543026142684"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2025-11-11T06:32:08.991Z","publish_time":1762842728991,"_source_registry_name":"default","_cnpm_publish_time":1762842728991},"1.2.1":{"name":"yocto-queue","version":"1.2.1","description":"Tiny queue data structure","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/yocto-queue.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":"./index.js","types":"./index.d.ts","sideEffects":false,"engines":{"node":">=12.20"},"scripts":{"//test":"xo && ava && tsd","test":"ava && tsd"},"keywords":["queue","data","structure","algorithm","queues","queuing","list","array","linkedlist","fifo","enqueue","dequeue","data-structure"],"devDependencies":{"ava":"^3.15.0","tsd":"^0.17.0","xo":"^0.44.0"},"_id":"yocto-queue@1.2.1","gitHead":"ce72d41de87b2a4ec7c50e10480300bee674d845","bugs":{"url":"https://github.com/sindresorhus/yocto-queue/issues"},"homepage":"https://github.com/sindresorhus/yocto-queue#readme","_nodeVersion":"23.6.1","_npmVersion":"10.9.2","dist":{"shasum":"36d7c4739f775b3cbc28e6136e21aa057adec418","size":3197,"noattachment":false,"key":"/yocto-queue/-/yocto-queue-1.2.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/yocto-queue/download/yocto-queue-1.2.1.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/yocto-queue_1.2.1_1742622578234_0.5609364464617448"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2025-03-22T05:49:38.400Z","publish_time":1742622578400,"_source_registry_name":"default","_cnpm_publish_time":1742622578400},"1.2.0":{"name":"yocto-queue","version":"1.2.0","description":"Tiny queue data structure","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/yocto-queue.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":"./index.js","types":"./index.d.ts","sideEffects":false,"engines":{"node":">=12.20"},"scripts":{"//test":"xo && ava && tsd","test":"ava && tsd"},"keywords":["queue","data","structure","algorithm","queues","queuing","list","array","linkedlist","fifo","enqueue","dequeue","data-structure"],"devDependencies":{"ava":"^3.15.0","tsd":"^0.17.0","xo":"^0.44.0"},"_id":"yocto-queue@1.2.0","gitHead":"6f20a6fad9323285e9f7c04dd1232ccc5e931e7e","bugs":{"url":"https://github.com/sindresorhus/yocto-queue/issues"},"homepage":"https://github.com/sindresorhus/yocto-queue#readme","_nodeVersion":"23.6.1","_npmVersion":"10.9.2","dist":{"shasum":"4a29a93e7591328fa31768701e6ea66962401f79","size":3205,"noattachment":false,"key":"/yocto-queue/-/yocto-queue-1.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/yocto-queue/download/yocto-queue-1.2.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/yocto-queue_1.2.0_1741264180240_0.4540003960919774"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2025-03-06T12:29:40.450Z","publish_time":1741264180450,"_source_registry_name":"default","_cnpm_publish_time":1741264180450},"1.1.1":{"name":"yocto-queue","version":"1.1.1","description":"Tiny queue data structure","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/yocto-queue.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":"./index.js","types":"./index.d.ts","sideEffects":false,"engines":{"node":">=12.20"},"scripts":{"//test":"xo && ava && tsd","test":"ava && tsd"},"keywords":["queue","data","structure","algorithm","queues","queuing","list","array","linkedlist","fifo","enqueue","dequeue","data-structure"],"devDependencies":{"ava":"^3.15.0","tsd":"^0.17.0","xo":"^0.44.0"},"_id":"yocto-queue@1.1.1","gitHead":"0ac610dfa4e5cbd929b2e9b8fc34f5417f2f788b","bugs":{"url":"https://github.com/sindresorhus/yocto-queue/issues"},"homepage":"https://github.com/sindresorhus/yocto-queue#readme","_nodeVersion":"18.20.2","_npmVersion":"10.6.0","dist":{"shasum":"fef65ce3ac9f8a32ceac5a634f74e17e5b232110","size":3019,"noattachment":false,"key":"/yocto-queue/-/yocto-queue-1.1.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/yocto-queue/download/yocto-queue-1.1.1.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/yocto-queue_1.1.1_1719699170246_0.38023407968029876"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2024-06-29T22:12:50.399Z","publish_time":1719699170399,"_source_registry_name":"default","maintainers":[{"name":"sindresorhus","email":""}],"_cnpm_publish_time":1719699170399},"1.1.0":{"name":"yocto-queue","version":"1.1.0","description":"Tiny queue data structure","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/yocto-queue.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":"./index.js","types":"./index.d.ts","sideEffects":false,"engines":{"node":">=12.20"},"scripts":{"//test":"xo && ava && tsd","test":"ava && tsd"},"keywords":["queue","data","structure","algorithm","queues","queuing","list","array","linkedlist","fifo","enqueue","dequeue","data-structure"],"devDependencies":{"ava":"^3.15.0","tsd":"^0.17.0","xo":"^0.44.0"},"_id":"yocto-queue@1.1.0","gitHead":"812e5ed7f3334637922f4cd6ac6c2ce8f5c70c75","bugs":{"url":"https://github.com/sindresorhus/yocto-queue/issues"},"homepage":"https://github.com/sindresorhus/yocto-queue#readme","_nodeVersion":"22.2.0","_npmVersion":"10.6.0","dist":{"shasum":"1c567759666a1b3bd4af7897551bacb488f482b9","size":2993,"noattachment":false,"key":"/yocto-queue/-/yocto-queue-1.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/yocto-queue/download/yocto-queue-1.1.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/yocto-queue_1.1.0_1719607810647_0.20351033896965798"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2024-06-28T20:50:10.833Z","publish_time":1719607810833,"_source_registry_name":"default","maintainers":[{"name":"sindresorhus","email":""}],"_cnpm_publish_time":1719607810833},"1.0.0":{"name":"yocto-queue","version":"1.0.0","description":"Tiny queue data structure","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/yocto-queue.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":"./index.js","engines":{"node":">=12.20"},"scripts":{"//test":"xo && ava && tsd","test":"ava && tsd"},"keywords":["queue","data","structure","algorithm","queues","queuing","list","array","linkedlist","fifo","enqueue","dequeue","data-structure"],"devDependencies":{"ava":"^3.15.0","tsd":"^0.17.0","xo":"^0.44.0"},"gitHead":"2e57f8c95e5e1f40379c6f85d18aee962662eb22","bugs":{"url":"https://github.com/sindresorhus/yocto-queue/issues"},"homepage":"https://github.com/sindresorhus/yocto-queue#readme","_id":"yocto-queue@1.0.0","_nodeVersion":"12.22.1","_npmVersion":"7.10.0","dist":{"shasum":"7f816433fb2cbc511ec8bf7d263c3b58a1a3c251","size":2915,"noattachment":false,"key":"/yocto-queue/-/yocto-queue-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/yocto-queue/download/yocto-queue-1.0.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/yocto-queue_1.0.0_1628812112939_0.12892570466581454"},"_hasShrinkwrap":false,"publish_time":1628812113113,"_cnpm_publish_time":1628812113113},"0.1.0":{"name":"yocto-queue","version":"0.1.0","description":"Tiny queue data structure","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/yocto-queue.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"engines":{"node":">=10"},"scripts":{"test":"xo && ava && tsd"},"keywords":["queue","data","structure","algorithm","queues","queuing","list","array","linkedlist","fifo","enqueue","dequeue","data-structure"],"devDependencies":{"ava":"^2.4.0","tsd":"^0.13.1","xo":"^0.35.0"},"gitHead":"af91c37f51aecf607ca2261b907b9d86b6a69e77","bugs":{"url":"https://github.com/sindresorhus/yocto-queue/issues"},"homepage":"https://github.com/sindresorhus/yocto-queue#readme","_id":"yocto-queue@0.1.0","_nodeVersion":"10.22.1","_npmVersion":"6.14.9","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b","size":2765,"noattachment":false,"key":"/yocto-queue/-/yocto-queue-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/yocto-queue/download/yocto-queue-0.1.0.tgz"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/yocto-queue_0.1.0_1606197935700_0.6375493777344527"},"_hasShrinkwrap":false,"publish_time":1606197935875,"_cnpm_publish_time":1606197935875},"0.0.0":{"name":"yocto-queue","version":"0.0.0","description":"Tiny queue data structure","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/nano-queue.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"engines":{"node":">=10"},"scripts":{"test":"xo && ava && tsd"},"keywords":["queue","data","structure","algorithm","queues","queuing","list","array","linkedlist","fifo","enqueue","dequeue","data-structure"],"devDependencies":{"ava":"^2.4.0","tsd":"^0.13.1","xo":"^0.35.0"},"gitHead":"d0c1a94cb05a698f8e2a99555f8cf8585e9869d2","bugs":{"url":"https://github.com/sindresorhus/nano-queue/issues"},"homepage":"https://github.com/sindresorhus/nano-queue#readme","_id":"yocto-queue@0.0.0","_nodeVersion":"10.22.1","_npmVersion":"6.14.9","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"97d0fce807d9e50873aec71074e895788e327cf3","size":2772,"noattachment":false,"key":"/yocto-queue/-/yocto-queue-0.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/yocto-queue/download/yocto-queue-0.0.0.tgz"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/yocto-queue_0.0.0_1606197588704_0.1585882120213571"},"_hasShrinkwrap":false,"publish_time":1606197588904,"_cnpm_publish_time":1606197588904}},"readme":"# yocto-queue [![](https://badgen.net/bundlephobia/minzip/yocto-queue)](https://bundlephobia.com/result?p=yocto-queue)\n\n> Tiny queue data structure\n\nYou should use this package instead of an array if you do a lot of `Array#push()` and `Array#shift()` on large arrays, since `Array#shift()` has [linear time complexity](https://medium.com/@ariel.salem1989/an-easy-to-use-guide-to-big-o-time-complexity-5dcf4be8a444#:~:text=O(N)%E2%80%94Linear%20Time) *O(n)* while `Queue#dequeue()` has [constant time complexity](https://medium.com/@ariel.salem1989/an-easy-to-use-guide-to-big-o-time-complexity-5dcf4be8a444#:~:text=O(1)%20%E2%80%94%20Constant%20Time) *O(1)*. That makes a huge difference for large arrays.\n\n> A [queue](https://en.wikipedia.org/wiki/Queue_(abstract_data_type)) is an ordered list of elements where an element is inserted at the end of the queue and is removed from the front of the queue. A queue works based on the first-in, first-out ([FIFO](https://en.wikipedia.org/wiki/FIFO_(computing_and_electronics))) principle.\n\n## Install\n\n```sh\nnpm install yocto-queue\n```\n\n## Usage\n\n```js\nimport Queue from 'yocto-queue';\n\nconst queue = new Queue();\n\nqueue.enqueue('????');\nqueue.enqueue('????');\n\nconsole.log(queue.size);\n//=> 2\n\nconsole.log(...queue);\n//=> '???? ????'\n\nconsole.log(queue.dequeue());\n//=> '????'\n\nconsole.log(queue.dequeue());\n//=> '????'\n```\n\n## API\n\n### `queue = new Queue()`\n\nThe 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. Using the iterator will not remove the items from the queue. If you want that, use [`drain()`](#drain) instead.\n\nYou can also use spreading to convert the queue to an array. Don't do this unless you really need to though, since it's slow.\n\n#### `.enqueue(value)`\n\nAdd a value to the queue.\n\n#### `.dequeue()`\n\nRemove the next value in the queue.\n\nReturns the removed value or `undefined` if the queue is empty.\n\n#### `.peek()`\n\nGet the next value in the queue without removing it.\n\nReturns the value or `undefined` if the queue is empty.\n\n#### `.drain()`\n\nReturns an iterator that dequeues items as you consume it.\n\nThis allows you to empty the queue while processing its items.\n\nIf you want to not remove items as you consume it, use the `Queue` object as an iterator.\n\n#### `.clear()`\n\nClear the queue.\n\n#### `.size`\n\nThe size of the queue.\n\n## Related\n\n- [quick-lru](https://github.com/sindresorhus/quick-lru) - Simple “Least Recently Used” (LRU) cache\n","_attachments":{},"homepage":"https://github.com/sindresorhus/yocto-queue#readme","bugs":{"url":"https://github.com/sindresorhus/yocto-queue/issues"},"license":"MIT"}