{"id":26641725,"url":"https://github.com/davidtimms/stack-queue","last_synced_at":"2025-03-24T18:35:01.944Z","repository":{"id":12918865,"uuid":"15596345","full_name":"DavidTimms/stack-queue","owner":"DavidTimms","description":"JavaScript/CoffeeScript implementations of safer stack and queue data structures","archived":false,"fork":false,"pushed_at":"2014-02-03T15:28:54.000Z","size":172,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-06T20:12:27.520Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DavidTimms.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-01-02T23:23:25.000Z","updated_at":"2014-02-03T15:28:54.000Z","dependencies_parsed_at":"2022-08-28T14:50:15.664Z","dependency_job_id":null,"html_url":"https://github.com/DavidTimms/stack-queue","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DavidTimms%2Fstack-queue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DavidTimms%2Fstack-queue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DavidTimms%2Fstack-queue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DavidTimms%2Fstack-queue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DavidTimms","download_url":"https://codeload.github.com/DavidTimms/stack-queue/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245328729,"owners_count":20597482,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-24T18:35:01.391Z","updated_at":"2025-03-24T18:35:01.932Z","avatar_url":"https://github.com/DavidTimms.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Stack-Queue\n================\n\nA JavaScript/CoffeeScript implementation of the basic stack and queue data structures which is safer than using a standard Array, as it only offers the core operations for adding and removing values.\n\nA maximum size can be set for the structure and it will emit an overflow event when this is reached, which can be listened for by a callback function. It also emits an empty event when the last value is removed.\n\nUsage\n----------------\n\nThe new keyword is optional when creating an instance:\n\t\n\tvar stack = Stack();\n\tvar queue = new Queue();\n\nThree alternative syntax conventions are available for the addition and removal operations:\n\n - Traditional JS Array methods:\n\n\t\tstack.push(7968, 123);\n\t\tstack.pop(); // returns 123\n\n\t\tqueue.push(7968);\n\t\tqueue.shift(); // returns 7968\n\n - Uniform add() and get() methods:\n\n\t\tstack.add(7968);\n\t\tstack.get(); // returns 7968\n\n\t\tqueue.add(7968, 123);\n\t\tqueue.get(); // returns 7968\n\n - Calling the structure as a function with arguments adds them. \n   Calling it without arguments removes the top value:\n\n\t\tstack(365);\n\t\tqueue('foo', 'bar');\n\n\t\tstack(); // returns 365\n\t\tqueue(); // returns 'foo'\n\nAll three conventions are interchangeable and semantically identical.\n\nThe top value can also be viewed without removing it using peek():\n\n\tstack.push('foo');\n\tstack.peek(); // returns 'foo'\n\tstack.pop(); // returns 'foo'\n\nGet the number of values in the structure with size() and use maxSize to set an upper limit:\n\n\tstack.size();\n\tstack.maxSize = 10;\n\nAdd and remove listeners for the overflow and empty events with on() and off():\n\n\tvar onOverflow = function(item) {\n\t\tconsole.log('Overflowed trying to add ', item);\n\t};\n\n\t// add listener\n\tstack.on('overflow', onOverflow); \n\n\t// remove listener\n\tstack.off('overflow', onOverflow); \n\n\tqueue.on('emtpy', function() {\n\t\tconsole.log('The queue is empty');\n\t});","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidtimms%2Fstack-queue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavidtimms%2Fstack-queue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidtimms%2Fstack-queue/lists"}