{"id":28092649,"url":"https://github.com/shahradelahi/circular-buffer","last_synced_at":"2025-05-16T17:14:37.310Z","repository":{"id":292759435,"uuid":"981823658","full_name":"shahradelahi/circular-buffer","owner":"shahradelahi","description":"♻️ Circular Buffer implementation for JavaScript","archived":false,"fork":false,"pushed_at":"2025-05-15T03:33:50.000Z","size":80,"stargazers_count":7,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-15T16:16:02.451Z","etag":null,"topics":["buffer","circular","typescript"],"latest_commit_sha":null,"homepage":"https://npmjs.com/@se-oss/circular-buffer","language":"TypeScript","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/shahradelahi.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-12T00:19:11.000Z","updated_at":"2025-05-15T03:33:53.000Z","dependencies_parsed_at":"2025-05-15T16:16:05.741Z","dependency_job_id":"9eb2830d-5282-4277-8e1f-7fec80c38404","html_url":"https://github.com/shahradelahi/circular-buffer","commit_stats":null,"previous_names":["shahradelahi/circular-buffer"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shahradelahi%2Fcircular-buffer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shahradelahi%2Fcircular-buffer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shahradelahi%2Fcircular-buffer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shahradelahi%2Fcircular-buffer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shahradelahi","download_url":"https://codeload.github.com/shahradelahi/circular-buffer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254573601,"owners_count":22093732,"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":["buffer","circular","typescript"],"created_at":"2025-05-13T13:26:03.060Z","updated_at":"2025-05-16T17:14:37.293Z","avatar_url":"https://github.com/shahradelahi.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @se-oss/circular-buffer\n\n[![CI](https://github.com/shahradelahi/circular-buffer/actions/workflows/ci.yml/badge.svg)](https://github.com/shahradelahi/circular-buffer/actions/workflows/ci.yml)\n[![NPM Version](https://img.shields.io/npm/v/@se-oss/circular-buffer.svg)](https://www.npmjs.com/package/@se-oss/circular-buffer)\n[![MIT License](https://img.shields.io/badge/License-MIT-blue.svg?style=flat)](/LICENSE)\n[![Install Size](https://packagephobia.com/badge?p=@se-oss/circular-buffer)](https://packagephobia.com/result?p=@se-oss/circular-buffer)\n\nA lightweight TypeScript implementation of a fixed-capacity [circular buffer](https://en.wikipedia.org/wiki/Circular_buffer), perfect for rolling windows, and efficient FIFO queues with automatic overwrite on full capacity.\n\n---\n\n- [Installation](#-installation)\n- [Usage](#-usage)\n- [Documentation](#-documentation)\n- [Contributing](#-contributing)\n- [License](#license)\n\n## 📦 Installation\n\n```bash\nnpm i @se-oss/circular-buffer\n```\n\n## 📖 Usage\n\n```typescript\nimport { CircularBuffer } from '@se-oss/circular-buffer';\n\n// Create a buffer with capacity for 5 items\nconst buf = new CircularBuffer(5);\n\n// Add some numbers\nbuf.put(10);\nbuf.put(20);\nbuf.put(30);\n\n// Check status\nconsole.log(buf.isEmpty()); // false\nconsole.log(buf.isFull()); // false\nconsole.log(buf.size()); // 3\n\n// Random access\nconsole.log(buf.at(0)); // 10\nconsole.log(buf.at(-1)); // 30\n\n// Iterate in FIFO order\nfor (const num of buf) {\n  console.log(num);\n}\n// → 10, 20, 30\n\n// Overwrite when full\nbuf.put(40);\nbuf.put(50);\nbuf.put(60); // now full, this overwrites the oldest entry (10)\n\nconsole.log(buf.toArray());\n// → [20, 30, 40, 50, 60]\n\n// Overwrite at gien index\nbuf.putAt(70, -2);\n// → [20, 30, 40, 70, 60]\n\n// Clear it\nbuf.clear();\nconsole.log(buf.isEmpty()); // true\n```\n\n## 📚 Documentation\n\nFor all configuration options, please see [the API docs](https://www.jsdocs.io/package/@se-oss/circular-buffer).\n\n## 🔗 References\n\n- [Wikipedia: Circular buffer](https://en.wikipedia.org/wiki/Circular_buffer)\n\n## 🤝 Contributing\n\nWant to contribute? Awesome! To show your support is to star the project, or to raise issues on [GitHub](https://github.com/shahradelahi/circular-buffer).\n\nThanks again for your support, it is much appreciated! 🙏\n\n## License\n\n[MIT](/LICENSE) © [Shahrad Elahi](https://github.com/shahradelahi) and [contributors](https://github.com/shahradelahi/circular-buffer/graphs/contributors).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshahradelahi%2Fcircular-buffer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshahradelahi%2Fcircular-buffer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshahradelahi%2Fcircular-buffer/lists"}