{"_id":"cycled","_rev":"4109177","name":"cycled","description":"Cycle through the items of an array","dist-tags":{"latest":"2.0.0"},"maintainers":[{"name":"sindresorhus","email":""}],"time":{"modified":"2026-01-23T00:52:44.000Z","created":"2018-03-28T10:12:46.318Z","2.0.0":"2021-04-07T18:32:20.961Z","1.2.0":"2020-07-17T11:25:36.243Z","1.1.0":"2019-04-09T19:44:35.345Z","1.0.0":"2018-05-27T08:35:46.751Z","0.2.0":"2018-03-29T10:22:56.822Z","0.1.1":"2018-03-29T04:16:28.946Z","0.1.0":"2018-03-28T10:12:46.318Z"},"users":{},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"repository":{"type":"git","url":"git+https://github.com/sindresorhus/cycled.git"},"versions":{"2.0.0":{"name":"cycled","version":"2.0.0","description":"Cycle through the items of an array","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/cycled.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":"./index.js","engines":{"node":">=12"},"scripts":{"//test":"xo && ava && tsd","test":"ava && tsd"},"keywords":["cycle","cycled","iterable","iterables","array","item","next","previous","loop","repeat","value","values","iterator"],"devDependencies":{"ava":"^3.15.0","tsd":"^0.14.0","xo":"^0.38.2"},"gitHead":"f32f521e9f23f246261aa293b07724155eb3360c","bugs":{"url":"https://github.com/sindresorhus/cycled/issues"},"homepage":"https://github.com/sindresorhus/cycled#readme","_id":"cycled@2.0.0","_nodeVersion":"12.20.1","_npmVersion":"6.14.10","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"6b67ff948eab5c3667dfe9f99797e2a8a857cb1e","size":2706,"noattachment":false,"key":"/cycled/-/cycled-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/cycled/download/cycled-2.0.0.tgz"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cycled_2.0.0_1617820340767_0.6551534485705253"},"_hasShrinkwrap":false,"publish_time":1617820340961,"_cnpm_publish_time":1617820340961,"_cnpmcore_publish_time":"2021-12-17T13:22:36.994Z"},"1.2.0":{"name":"cycled","version":"1.2.0","description":"Cycle through the items of an array","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/cycled.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"engines":{"node":">=6"},"scripts":{"test":"xo && ava && tsd"},"keywords":["cycle","cycled","iterable","iterables","array","item","next","previous","loop","repeat","value","values","iterator"],"devDependencies":{"ava":"^1.4.1","tsd":"^0.7.2","xo":"^0.24.0"},"gitHead":"997bdbd7c163be8682846686c4802943e9833e74","bugs":{"url":"https://github.com/sindresorhus/cycled/issues"},"homepage":"https://github.com/sindresorhus/cycled#readme","_id":"cycled@1.2.0","_nodeVersion":"14.5.0","_npmVersion":"6.14.5","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"dde6d9d58b0b14d02c8138c8f55be416a6595baf","size":2735,"noattachment":false,"key":"/cycled/-/cycled-1.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/cycled/download/cycled-1.2.0.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cycled_1.2.0_1594985136048_0.28044967686708233"},"_hasShrinkwrap":false,"publish_time":1594985136243,"_cnpm_publish_time":1594985136243,"_cnpmcore_publish_time":"2021-12-17T13:22:37.250Z"},"1.1.0":{"name":"cycled","version":"1.1.0","description":"Cycle through the items of an array","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/cycled.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=6"},"scripts":{"test":"xo && ava && tsd"},"keywords":["cycle","cycled","iterable","iterables","array","item","next","previous","loop","repeat","value","values","iterator"],"devDependencies":{"ava":"^1.4.1","tsd":"^0.7.2","xo":"^0.24.0"},"gitHead":"74cda09ca861b7246e220db76eaf526e58423ab6","bugs":{"url":"https://github.com/sindresorhus/cycled/issues"},"homepage":"https://github.com/sindresorhus/cycled#readme","_id":"cycled@1.1.0","_npmVersion":"6.4.1","_nodeVersion":"10.15.1","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"b74038abe28b4ae2342ee23a87ace9ea75300cf7","size":2710,"noattachment":false,"key":"/cycled/-/cycled-1.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/cycled/download/cycled-1.1.0.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cycled_1.1.0_1554839075195_0.7007555362005888"},"_hasShrinkwrap":false,"publish_time":1554839075345,"_cnpm_publish_time":1554839075345,"_cnpmcore_publish_time":"2021-12-17T13:22:37.495Z"},"1.0.0":{"name":"cycled","version":"1.0.0","description":"Cycle through the items of an array","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/cycled.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=6"},"scripts":{"test":"xo && ava"},"files":["index.js"],"keywords":["cycle","cycled","iterable","iterables","array","item","next","previous","loop","repeat","value","values","iterator"],"devDependencies":{"ava":"*","xo":"*"},"gitHead":"e595875f890101af12ef139921b11efeb54a1cea","bugs":{"url":"https://github.com/sindresorhus/cycled/issues"},"homepage":"https://github.com/sindresorhus/cycled#readme","_id":"cycled@1.0.0","_npmVersion":"5.6.0","_nodeVersion":"10.2.1","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"f6559613cb634c3605b16aff58aa2d5f74e5ea5b","size":2392,"noattachment":false,"key":"/cycled/-/cycled-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/cycled/download/cycled-1.0.0.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cycled_1.0.0_1527410146704_0.9346515317249244"},"_hasShrinkwrap":false,"publish_time":1527410146751,"_cnpm_publish_time":1527410146751,"_cnpmcore_publish_time":"2021-12-17T13:22:37.728Z"},"0.2.0":{"name":"cycled","version":"0.2.0","description":"Cycle through the items of an array","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/cycled.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=6"},"scripts":{"test":"xo && ava"},"files":["index.js"],"keywords":["cycle","cycled","iterable","iterables","array","item","next","previous","loop","repeat","value","values","iterator"],"devDependencies":{"ava":"*","xo":"*"},"gitHead":"20d263ffa0af2b209affc0faff3d07663c6b9e4f","bugs":{"url":"https://github.com/sindresorhus/cycled/issues"},"homepage":"https://github.com/sindresorhus/cycled#readme","_id":"cycled@0.2.0","_npmVersion":"5.6.0","_nodeVersion":"8.10.0","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"ebebe771990a60f62ad0040e88c6c1e422b97dde","size":2066,"noattachment":false,"key":"/cycled/-/cycled-0.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/cycled/download/cycled-0.2.0.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cycled_0.2.0_1522318976742_0.5206662601475922"},"_hasShrinkwrap":false,"publish_time":1522318976822,"_cnpm_publish_time":1522318976822,"_cnpmcore_publish_time":"2021-12-17T13:22:37.941Z"},"0.1.1":{"name":"cycled","version":"0.1.1","description":"Cycle through the items of an array","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/cycled.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=6"},"scripts":{"test":"xo && ava"},"files":["index.js"],"keywords":["cycle","cycled","iterable","iterables","array","item","next","previous","loop","repeat","value","values","iterator"],"devDependencies":{"ava":"*","xo":"*"},"gitHead":"7108e1b6c1e24633fd7c0ac290a4af56b1d93ab3","bugs":{"url":"https://github.com/sindresorhus/cycled/issues"},"homepage":"https://github.com/sindresorhus/cycled#readme","_id":"cycled@0.1.1","_npmVersion":"5.6.0","_nodeVersion":"8.10.0","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"9401c81698be285d2b0c102b250bc123d11369e5","size":2063,"noattachment":false,"key":"/cycled/-/cycled-0.1.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/cycled/download/cycled-0.1.1.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cycled_0.1.1_1522296988890_0.9736557142405271"},"_hasShrinkwrap":false,"publish_time":1522296988946,"_cnpm_publish_time":1522296988946,"_cnpmcore_publish_time":"2021-12-17T13:22:38.148Z"},"0.1.0":{"name":"cycled","version":"0.1.0","description":"Cycle through the items of an array","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/cycled.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=6"},"scripts":{"test":"xo && ava"},"files":["index.js"],"keywords":["cycle","cycled","iterable","iterables","array","item","next","previous","loop","repeat","value","values","iterator"],"devDependencies":{"ava":"*","xo":"*"},"gitHead":"af25fe20bc9e97ad9b52b792e89043efc9675835","bugs":{"url":"https://github.com/sindresorhus/cycled/issues"},"homepage":"https://github.com/sindresorhus/cycled#readme","_id":"cycled@0.1.0","_npmVersion":"5.6.0","_nodeVersion":"8.10.0","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"9d65bfcb34b386dfe951ff3e56a9b3fc2b028c79","size":2066,"noattachment":false,"key":"/cycled/-/cycled-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/cycled/download/cycled-0.1.0.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cycled_0.1.0_1522231966234_0.4337834544760244"},"_hasShrinkwrap":false,"publish_time":1522231966318,"_cnpm_publish_time":1522231966318,"_cnpmcore_publish_time":"2021-12-17T13:22:38.392Z"}},"readme":"# cycled\n\n> Cycle through the items of an array\n\nThis package can be useful for cycling through tabs, images of slideshows, etc.\n\n## Install\n\n```\n$ npm install cycled\n```\n\n## Usage\n\n```js\nimport Cycled from 'cycled';\n\nconst cycled = new Cycled([1, 2, 3]);\n\ncycled.current();\n//=> 1\n\ncycled.next();\n//=> 2\n\ncycled.next();\n//=> 3\n\ncycled.next();\n//=> 1\n\ncycled.previous();\n//=> 3\n```\n\n## API\n\n### `cycled = new Cycled(array)`\n\nInitiates an array subclass with the methods documented below. Since it's an array, you can use all the normal array methods on it.\n\n#### array\n\nType: `Array`\n\nThe array to wrap.\n\n### cycled\n\nThe instance is an iterable that will cycle through the array. It will cycle through the number of elements equaling the length of the array from the current index.\n\n```js\nimport Cycled from 'cycled';\n\nconst numberCycle = new Cycled([1, 2, 3, 4, 5]);\n\nconsole.log(...numberCycle);\n//=> 1 2 3 4 5\n```\n\n#### current()\n\nReturns the current item.\n\n#### next()\n\nReturns the next item.\n\n#### previous()\n\nReturns the previous item.\n\n#### step(steps)\n\nReturns the item by going the given amount of `steps` through the array. For example, calling `step(2)` is like calling `next()` twice. You go backward by specifying a negative number.\n\n#### peek(steps)\n\nReturns the item that is located in the given amount of `steps` through the array. For example, calling `peek(2)` would get the item 2 items after the current one. You go backward by specifying a negative number.\n\nThis method is similar to `.step()` but without changing the current item.\n\n#### index\n\nGet or set the current index.\n\n#### indefinitely()\n\nReturns an iterable that will cycle through the array indefinitely.\n\n#### indefinitelyReversed()\n\nReturns an iterable that will cycle through the array backward indefinitely.\n\n## Example\n\nHere we create a simple tab component that can have the active view set or go forward/backward through the tabs.\n\n```js\nimport Cycled from 'cycled';\n\nclass TabComponent {\n\t#activeView;\n\t#views;\n\n\tconstructor(views) {\n\t\tthis.#activeView = views[0];\n\t\tthis.#views = new Cycled(views);\n\t}\n\n\tsetActiveView(view) {\n\t\tthis.#activeView = view;\n\t\tthis.#views.index = this.views.indexOf(view);\n\t}\n\n\tnextView() {\n\t\tsetActiveView(this.#views.next());\n\t}\n\n\tpreviousView() {\n\t\tsetActiveView(this.#views.previous());\n\t}\n}\n\nconst tabs = new TabComponent([\n\t'Homepage',\n\t'Blog',\n\t'Projects',\n\t'Contact'\n]);\n\n// …\n\nnextButton.addEventListener('click', () => {\n\ttabs.nextView();\n});\n```\n","_attachments":{},"homepage":"https://github.com/sindresorhus/cycled#readme","bugs":{"url":"https://github.com/sindresorhus/cycled/issues"},"license":"MIT"}