{"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":{"integrity":"sha512-Gje2igZgdUrS5ypLA7Mhi63MOgDBlCQ/2hB0/lLhcEwa8ESIHcNFARalnuoG9u9IRf0YVvIhWVjcpIG08tu/2Q==","shasum":"6b67ff948eab5c3667dfe9f99797e2a8a857cb1e","tarball":"http://registry-npm.ywwl.com/cycled/download/cycled-2.0.0.tgz","fileCount":5,"unpackedSize":7394,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgbfq1CRA9TVsSAnZWagAA7VEP/i2RVkc/qfjfyUDhjRmL\nPKBKDibSmMSoPjLqUd4zsA0eEp2fIGd8h6o2Pq96gxEdZ8dTCs7KE4KOWeJE\nL3xSYDFbjasaUDXC69o9+D1YuJsYquOx6gWk/Fu66yuVXt3xpXqhXBUEF+RJ\noab20HYslJu4asmqiIpd8YHTh3Ty4yafGS5935YXKqVdfOBe3VJ0wIUKMpqD\np5jK+csd+nAnKM5CPQhvNcxZV9cUT6UTPthcBEhpmn7LTvJLN/YiQdLYnAiF\nR3zf8qnk/ePyXAm7WRxLPz+4ky5x6lNjbv0WKmCyE2dlax9ae5Eo6xxXjN7P\nzoLDmJAcgNgXPJRa88tzuuFkDf6z19wumJ7jQuFvhNsNr4wIK59hmz5dOY1n\n7etq/doDcWko9Ko1oN+8VxJQNURYD5NXHJD9HVWLi4nAbEKxFGQdDjM69not\nfogix74/5CnNJ+E4FvzKRd8HDVi3JCXta5XY5IK4ugSi8jhYf8BElVyRMPKO\nhbAvBqznQz0cqhItL4LM/bB3OqpK/YR+bA865XQuw17A1t+DpgBZSy5y169i\n3zBaDz2dEBVpVvvZtdT6LJjik8qnlD24QMwqb8kHhe+HkpNxZ3SM0deUh3OU\nPVCeZMltDeGW5pj7sdWx0f5Ca5FCMG+KwZgFEF1OSHzriEit/+0t9sWSFiib\nK/Co\r\n=xO7d\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHgG0p7tKDpI3G2Nmo1uT/UUJlMHesOdNjNff6O4CTWoAiB//sYCGLnQ3cgb9ltWz/7gJ6Ld/ZgsOrQGC71HtiHSFw=="}],"size":2706,"noattachment":false,"key":"/cycled/-/cycled-2.0.0.tgz"},"directories":{},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cycled_2.0.0_1617820340767_0.6551534485705253"},"_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":1617820340961,"_cnpm_publish_time":1617820340961,"dist-tags":{"latest":"2.0.0"}}