{"id":16157977,"url":"https://github.com/can-dy-jack/queue","last_synced_at":"2025-04-07T01:45:12.015Z","repository":{"id":65342933,"uuid":"590270104","full_name":"can-dy-jack/queue","owner":"can-dy-jack","description":"Queue implementation in JavaScript (based on Array)","archived":false,"fork":false,"pushed_at":"2023-01-18T04:08:43.000Z","size":40,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-04-26T06:04:30.488Z","etag":null,"topics":["data-structures","implementation","javascript","queue"],"latest_commit_sha":null,"homepage":"","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/can-dy-jack.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":"2023-01-18T02:33:58.000Z","updated_at":"2023-03-07T03:47:14.000Z","dependencies_parsed_at":"2023-02-10T13:15:15.175Z","dependency_job_id":null,"html_url":"https://github.com/can-dy-jack/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/can-dy-jack%2Fqueue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/can-dy-jack%2Fqueue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/can-dy-jack%2Fqueue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/can-dy-jack%2Fqueue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/can-dy-jack","download_url":"https://codeload.github.com/can-dy-jack/queue/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247578613,"owners_count":20961270,"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":["data-structures","implementation","javascript","queue"],"created_at":"2024-10-10T01:51:45.424Z","updated_at":"2025-04-07T01:45:11.992Z","avatar_url":"https://github.com/can-dy-jack.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# queue\nQueue implementation in JavaScript (based on Array)\n\n\u003e 队列：先入先出  \n## install\n```sh\nnpm i @kartjim/queue\n```\n\n## export\n```js\nconst { Queue } = require('@kartjim/queue');\n```\n\nor ESM :\n```js\nimport { Queue } from \"@kartjim/queue\";\n```\n## Queue API\n```ts\nexport class Queue\u003cA\u003e {\n    constructor(arr?: T[]);\n    isEmpty(): boolean;\n    size(): number;\n    front(): A;\n    end(): A;\n    push(val: A): Queue\u003cA\u003e;\n    pop(): A;\n    toArray(): A[];\n    clear(): void;\n}\n```\n### constructor\ncreate a Queue from an Array.\n\n```js\nconst queue = new Queue();\n// or\n// new Queue([1, 2, 3]);\n```\n\n### isEmpty\nChecks if the Queue is empty.  \n```js\nconsole.log(stack.isEmpty()) // true\nqueue.push(1);\nconsole.log(queue.isEmpty()) // false\n```\n\n### size\nreturn the number of elements in the queue.  \n```js\nconsole.log(queue.size()) // 1\n```\n### push\npush an element to the top of the queue.  \n```js\nqueue.push(2)\nconsole.log(stack.front()) // 1\nconsole.log(stack.end()) // 2\n```\n### front\nreturn the element at the front of the queue.  \n```js\nqueue.push(5);\nconsole.log(stack.front()) // 1\n```\n\n### end \nreturn the element at the end of the queue.  \n```js\nqueue.push(6);\nconsole.log(stack.end()) // 6\nconsole.log(stack.size()) // 4\n```\n\n### pop\nremove and return the top element in the queue.  \n```js\nconsole.log(queue.pop()) // 1\nconsole.log(queue.pop()) // 2\nconsole.log(queue.pop()) // 5\nconsole.log(queue.pop()) // 6\nconsole.log(queue.pop()) // undefined\n```\n### toArray\nreturn an array of elements in the queue.   \n```js\nqueue.push(8).push(9).push(11);\nconsole.log(queue.toArray()) // [8, 9, 11]\n```\n### clear\nremove all elements from the queue.  \n```js\nqueue.clear();\nconsole.log(queue.size()) // 0\nconsole.log(queue.isEmpty()) // true\n```\n## Coverage\n`🚀 grunt coverage`：\n\n```sh\n===================== Coverage summary =====================\nStatements   : 100% ( 80/80 )\nBranches     : 100% ( 6/6 )\nFunctions    : 100% ( 9/9 )\nLines        : 100% ( 80/80 )\n============================================================\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcan-dy-jack%2Fqueue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcan-dy-jack%2Fqueue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcan-dy-jack%2Fqueue/lists"}