{"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":{"integrity":"sha512-k4u9jjMBg7fvkoHFhELx7ozlXGJKC+xEslpe6xdO7cQr2gzduwz6cLm4iK7lSiu3X2sBNYjIS6JdLOhHOt6Qrg==","shasum":"b74038abe28b4ae2342ee23a87ace9ea75300cf7","tarball":"http://registry-npm.ywwl.com/cycled/download/cycled-1.1.0.tgz","fileCount":5,"unpackedSize":6799,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcrPYjCRA9TVsSAnZWagAAcv4QAIj9C85lfjj0HbHlCDwt\n9IpLs5VZMdzpXYKFOwFkMpNpZHRTvyw4DGR8XejMxyDqMoFJLKDzypIxXpys\nkRM/d0hExYqijxOr1ZjB9SsV4PCwQnAwJYBvbb9MfYQu+crT0GAMTggHTpDw\nAIS99nLvU9QZCuOnmNA/NtiTyhG7VI/cDpTmHN3JMs2jjWR1rgk8LIK3RXTI\nmW/T7XdVPFfVqY9n9CnZ1SmSn+zUnV025phi0kSI60f3UJSntfSJD89Hs7MQ\nt09ZgtaunoqTbeBpAw0DWXUclP4UHHlODMDxf18/PgPHSSl0IisK9trSn9Eg\nIWg/pvKkkTLRDHgEExkDiuvNBuctFpBajWBPfSfVGTfEQuG6l29xfFv0MXrj\njgZFKUANpVm3t1fsySCjwswK6RwDTKQ34ih3ZY5JwRoryCm/Mw0n0mE8SjDv\nwn6jRpZR5h1e9Yc4jzmtS03zFTtIkGPLYeAK7+lbP1tsSkErNYbhEIs9n+lh\nH16nywcwgNgvocIwFE4RIiEKpsNRosX7wjgDu+4V40arovR9FcgxOA716nu9\nyYLqpPjlpa+R6FaaSffHNee8E8pgPmqY9RHGC35NJ+MqwN9bcvJFWBezWsXN\nqrBgQKyzTqGvmm/V/iitowIj5ru8YLC9SRHfrD/bWa5e9bHSkUimS6KFqnH/\nnHiz\r\n=L+ha\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFO9SDjHMS/Kds2FQWdI1B5JFV1a+6cb3DOcC0rcreK2AiEAvIvxD6ghVB4oluJlFA5y+lCJTBRT7V+V6/4pf/YtZ0A="}],"size":2710,"noattachment":false,"key":"/cycled/-/cycled-1.1.0.tgz"},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cycled_1.1.0_1554839075195_0.7007555362005888"},"_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":1554839075345,"_cnpm_publish_time":1554839075345,"dist-tags":{"latest":"2.0.0"}}