{"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":{"integrity":"sha512-DrgKSG2iWOBCTopsunmq19Bx9im5B6mlcyOxDaVAsYXR1tMzK2zoTclLy4Nq0qkRxcDtXJnugDI+gqbBBHkhWQ==","shasum":"f6559613cb634c3605b16aff58aa2d5f74e5ea5b","tarball":"http://registry-npm.ywwl.com/cycled/download/cycled-1.0.0.tgz","fileCount":4,"unpackedSize":4981,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbCm3jCRA9TVsSAnZWagAAL1MP/2OOcWCOuW4oiE6iNZ8u\nkanIOl4bMVN0bYsZD+BTSyiUpv3t0esYwON31xQPIYh6m7u0/qeXPC2p/daJ\n53FImqQ24H+JFpgI+Ld9VMy64sLIJqlQm5nGPwIuer5WkgQamoDyS5+x/R80\nvxPTVI+n8tyT3DJvp6WvXQWuuEbSDFyuuRwlKR/giVc0sK3Xv/QE213dULoi\n6/7nx3FwympD64/on4nWULMOzHDAn7kC55c8GetuvuIbcpOJ9EgCVm+PNHIc\np2GgLeGCWCuv2zpM94bHoU3drQt+MGp2/da/nYOVQZuQojvmi0XpSbRtgueg\nUR/tlQSw4WsV9EBHY74j8vbcQRS7t0BiLSSbJh8hGY7EgC7XQz30IyMhsN6g\ncYfj4Y+vkWEkf++e4Yn9K7GTn6h1xJm2IuOMQnOHporpuYto1A9lDony6RWp\nmk1WPjY6y5VLMkbL7sdRRap2ye65K/LOuPLR1PRohrX1clNf5FFW3JnO/fI9\noS7rqrdiVvW2bK3kApjXFxv+Fc7CgkRhrnLw0d7egtBDLiPhnkDlpSFP5SO2\nd4kZIESI6aKzKnEK/JkzjVFfRziTM5XIC+uOAVhXWBDcjpekekQ6IrubbFgw\n2u7WZJThpH10lElpoU2OCreVkT5HlP0Snl+wm3qFwlI2ucN4VZexJ6bB848l\noB6A\r\n=GR9g\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCqcFLBYPKBL8SBzz4x473HEVxd7beTG80Hwtp42dlaMQIgPYUNJlxCboOwKoaIOMACWtRL3MH8eXdKMEUJ8Y8eFaY="}],"size":2392,"noattachment":false,"key":"/cycled/-/cycled-1.0.0.tgz"},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cycled_1.0.0_1527410146704_0.9346515317249244"},"_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":1527410146751,"_cnpm_publish_time":1527410146751,"dist-tags":{"latest":"2.0.0"}}