{"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":{"integrity":"sha512-KMQUrxn/lNb9GzjvRNc7ttms2KkVoDx/HBgorCX1a/wJ/7eBdLQAn1OXjT/CR7cJn3KzT6oYvhPodL0xMqbP1g==","shasum":"ebebe771990a60f62ad0040e88c6c1e422b97dde","tarball":"http://registry-npm.ywwl.com/cycled/download/cycled-0.2.0.tgz","fileCount":4,"unpackedSize":3956,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFz4cutvL7QL9ZabfDMB2EIYqUXbASmg1f48iQ5iZ5ZbAiEA6OVvFaqYcWNCItwbGYAlJ29pNYVOkWo//gOOnmSjj+w="}],"size":2066,"noattachment":false,"key":"/cycled/-/cycled-0.2.0.tgz"},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cycled_0.2.0_1522318976742_0.5206662601475922"},"_hasShrinkwrap":false,"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","publish_time":1522318976822,"_cnpm_publish_time":1522318976822,"dist-tags":{"latest":"2.0.0"}}