{"id":18027022,"url":"https://github.com/dar5hak/cartwheel","last_synced_at":"2025-04-04T19:48:35.355Z","repository":{"id":150567469,"uuid":"304319956","full_name":"dar5hak/cartwheel","owner":"dar5hak","description":"A circular list you never knew you needed","archived":false,"fork":false,"pushed_at":"2024-09-30T06:16:52.000Z","size":549,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-02T21:54:36.260Z","etag":null,"topics":["array","circular","cyclic","hacktoberfest","iterable","iterator","list","roundrobin"],"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/dar5hak.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}},"created_at":"2020-10-15T12:31:52.000Z","updated_at":"2024-09-30T06:16:52.000Z","dependencies_parsed_at":"2023-04-16T09:04:03.253Z","dependency_job_id":null,"html_url":"https://github.com/dar5hak/cartwheel","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":"rollup/rollup-starter-lib","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dar5hak%2Fcartwheel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dar5hak%2Fcartwheel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dar5hak%2Fcartwheel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dar5hak%2Fcartwheel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dar5hak","download_url":"https://codeload.github.com/dar5hak/cartwheel/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247240906,"owners_count":20906899,"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":["array","circular","cyclic","hacktoberfest","iterable","iterator","list","roundrobin"],"created_at":"2024-10-30T08:08:44.674Z","updated_at":"2025-04-04T19:48:35.332Z","avatar_url":"https://github.com/dar5hak.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cartwheel\n\n\u003e A circular list you never knew you needed\n\ncartwheel takes an array (or any array-like/iterable) and gives you a circular iterator. You can ask for the next or previous value any number of times, and it will keep cycling through the list.\n\n## Install\n\n### As an npm package\n\n```sh\nnpm install cartwheel\n```\n\nThen import it:\n\n```js\nconst cartwheel = require('cartwheel');\n```\n\nOr if you use ES module syntax:\n\n```js\nimport cartwheel from \"cartwheel\";\n```\n\n### As a `\u003cscript\u003e`\n\n```html\n\u003cscript src=\"https://unpkg.com/cartwheel@1.1.0\"\u003e\u003c/script\u003e\n```\n\nOr if you want to host it yourself, go to [releases](https://github.com/dar5hak/cartwheel/releases) and download _cartwheel.umd.min.js_. Then:\n\n```html\n\u003cscript src=\"cartwheel.umd.min.js\"\u003e\u003c/script\u003e\n```\n\n### As an ES Module (modern browsers)\n\n```js\nimport cartwheel from 'https://unpkg.com/cartwheel@1.1.0/dist/cartwheel.esm.min.js';\n```\n\nOr if you want to host it yourself, go to [releases](https://github.com/dar5hak/cartwheel/releases) and download _cartwheel.esm.min.js_. Then:\n\n```js\nimport cartwheel from 'cartwheel.esm.min.js';\n```\n\n**Note:** This should also work with Deno, but I haven‘t tested it.\n\n## Usage\n\n```js\n// Pass an iterable\nconst items = [\"Ed\", \"Edd\", \"Eddy\"];\nconst iterator = cartwheel(items);\n\n// Start iterating\niterator.nextValue();\n// Ed\n\niterator.nextValue();\n// Edd\n\niterator.nextValue();\n// Eddy\n\n// It‘s circular, remember?\niterator.nextValue();\n// Ed\n\n// Standard ES iterator protocol if you like\niterator.next();\n// { value: 'Edd', done: false }\n\n// `done` will always be false though\niterator.next();\n// { value: 'Eddy', done: false }\n\n// Rewind\niterator.previousValue();\n// Edd\n\niterator.previousValue();\n// Ed\n\n// They see me rollin‘, they hatin‘\niterator.previousValue();\n// Eddy\n\n// Iterator protocol again\niterator.previous();\n// { value: 'Edd', done: false }\n```\n\n## Documentation\n\n`cartwheel(iterable)` returns an iterator object with the following methods:\n\n### `next()`\n\nReturns the next item to what you last accessed. If it is the first call, returns the first item in the iterable. `done` is always false.\n\nExample: `{ value: 42, done: false }`\n\n### `nextValue()`\n\nSame as `next()`, but returns the `value` directly.\n\n### `previous()`\n\nReturns the previous item to what you last accessed. If it is the first call, returns the last item in the iterable. `done` is always false.\n\nExample: `{ value: 1337, done: false }`\n\n### `previousValue()`\n\nSame as `previous()`, but returns the `value` directly.\n\n## FAQ\n\n### Where would I need this?\n\nAnywhere you want to iterate a list of items in a circular “round robin” fashion. Think keyboard-navigable menus, tabs, carousels and typeahead suggestions.\n\n### Does it work with maps, sets or node lists?\n\nYes. It works with anything that is compatible with [`Array.from()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from).\n\n### Is it like a circular doubly linked list?\n\nKind of. It does offer a similar API, but the implementation looks nothing like a linked list.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdar5hak%2Fcartwheel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdar5hak%2Fcartwheel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdar5hak%2Fcartwheel/lists"}