{"id":46409,"library":"sorted-queue","title":"sorted-queue","description":"A sorted queue implementation based on an array-backed binary heap. Version 0.4.4 is the current stable release, but the package is in maintenance mode with no new features accepted. It is designed for Node.js >= 22 and ships TypeScript types. Key differentiators: items can be removed by reference (via item.pop()), supports custom comparator functions, and operates in O(log n) time for push/pop. It is ESM-only and lightweight with no dependencies.","status":"maintenance","version":"0.4.4","language":"javascript","source_language":"en","source_url":"https://github.com/badrap/sorted-queue","tags":["javascript","typescript"],"install":[{"cmd":"npm install sorted-queue","lang":"bash","label":"npm"},{"cmd":"yarn add sorted-queue","lang":"bash","label":"yarn"},{"cmd":"pnpm add sorted-queue","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Only named export is available; no default export.","wrong":"import SortedQueue from 'sorted-queue'","symbol":"SortedQueue","correct":"import { SortedQueue } from 'sorted-queue'"},{"note":"When only using the type, use type import to avoid runtime overhead.","wrong":"import { SortedQueue } from 'sorted-queue'","symbol":"SortedQueue (type)","correct":"import type { SortedQueue } from 'sorted-queue'"},{"note":"Package is ESM-only; dynamic import is required in CommonJS.","wrong":"const { SortedQueue } = require('sorted-queue')","symbol":"CommonJS require","correct":"const { SortedQueue } = await import('sorted-queue')"}],"quickstart":{"code":"import { SortedQueue } from 'sorted-queue';\n\nconst queue = new SortedQueue<number>();\nqueue.push(3);\nqueue.push(1);\nqueue.push(2);\nconsole.log(queue.pop().value); // 1\nconsole.log(queue.peek().value); // 2\nconsole.log(queue.empty()); // false\nqueue.pop();\nqueue.pop();\nconsole.log(queue.empty()); // true\n\n// Using custom comparator\nconst custom = new SortedQueue<string>((a, b) => b.localeCompare(a));\ncustom.push('c');\ncustom.push('a');\ncustom.push('b');\nconsole.log(custom.pop().value); // 'c'\n\n// Removing specific item\nconst item = queue.push(42);\nitem.pop(); // removes 42\nqueue.pop(); // undefined (queue empty)","lang":"typescript","description":"Shows basic usage: creating a sorted queue, push/pop/peek/empty, custom comparator, and removing items by reference."},"warnings":[{"fix":"Upgrade Node.js to version 22 or later.","message":"Node.js version requirement >= 22","severity":"breaking","affected_versions":">=0.4.0"},{"fix":"Use import syntax or dynamic import in CommonJS.","message":"ESM-only package, no CommonJS support","severity":"breaking","affected_versions":">=0.4.0"},{"fix":"Consider alternative packages if new features are needed.","message":"Package is in maintenance mode; no new features accepted.","severity":"deprecated","affected_versions":">=0.0.0"},{"fix":"Use the returned item object to remove an arbitrary element from the queue.","message":"Removing items by reference via item.pop() is O(1) but not obvious","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Check with empty() or ensure queue is not empty before calling pop/peek.","message":"pop() and peek() return undefined when queue is empty, not throw","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Do not mutate pushed objects expecting re-sort; remove and re-insert.","message":"push() returns an object containing value and pop method; mutating value does not reorder","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'0.4.4':17 '22':40 'accept':34 'array':12 'array-back':11 'back':13 'base':8 'binari':14 'compar':57 'current':20 'custom':56 'depend':77 'design':37 'differenti':46 'esm':71 'esm-on':70 'featur':33 'function':58 'heap':15 'implement':7 'item':47 'item.pop':54 'javascript':78 'key':45 'lightweight':74 'log':63 'mainten':28 'mode':29 'n':64 'new':32 'node.js':39 'o':62 'oper':60 'packag':25 'push/pop':67 'queue':3,6 'refer':52 'releas':22 'remov':50 'ship':42 'sort':2,5 'sorted-queu':1 'stabl':21 'support':55 'time':65 'type':44 'typescript':43,79 'version':16 'via':53","created_at":"2026-06-07T12:59:47.123754+00:00","updated_at":"2026-06-07T12:59:47.123754+00:00","problems":[{"fix":"Use import { SortedQueue } from 'sorted-queue' or dynamic import.","cause":"Using require() on an ESM-only package.","error":"ERR_REQUIRE_ESM"},{"fix":"Use import { SortedQueue } from 'sorted-queue' (curly braces).","cause":"Importing default instead of named export.","error":"TypeError: SortedQueue is not a constructor"},{"fix":"Instantiate: const queue = new SortedQueue();","cause":"Forgot to instantiate SortedQueue or imported incorrectly.","error":"TypeError: queue.push is not a function"},{"fix":"Upgrade Node.js to >=22 or set NODE_OPTIONS=--openssl-legacy-provider (temporary).","cause":"OpenSSL compatibility issue in older Node.js versions (pre-22).","error":"error:0308010C:digital envelope routines::unsupported"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/badrap/sorted-queue#readme","github":"https://github.com/badrap/sorted-queue","docs":null,"changelog":null,"pypi":null,"npm":"sorted-queue","openapi_spec":null,"status_page":null,"smithery":null,"categories":["storage"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}