{"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":{"integrity":"sha512-/BOOCEohSBflVHHtY/wUc1F6YDYPqyVs/A837gDoq4H1pm72nU/yChyGt91V4ML+MbbAmHs8uo2l1yJkkTIUdg==","shasum":"dde6d9d58b0b14d02c8138c8f55be416a6595baf","tarball":"http://registry-npm.ywwl.com/cycled/download/cycled-1.2.0.tgz","fileCount":5,"unpackedSize":7406,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfEYqwCRA9TVsSAnZWagAAw+8P/RVD9TCiB8BXEiL85lWX\n1O0nQSuwD1LcMYVycGR3/iw62DY2uYgeTeJ3TcNkl3fBF0p9d9RH470brd8T\nefRLKk7xNLxsM1tfASjpNOPKL8EgZSiDlAW+POm6DE/TMYFH3KenvXIKXZMQ\nd1e8hAsKoj9RW2L4RBofpzYOwVCRvpqcG0GKSxkAQsIT3AvOAHlSHygzS1A4\ns6c7hEoFZ3mlD6IyXkfUUKXY0pBHioesHqKuOhVlO9pE4to4LMzEY8IU3T3y\nw4sPZ6PZ8bj+lSlkJQxkFxJie+781m3iEW1AeoU+io7Rh5NyU8UsmBN9cSPB\n79R5ROF4YmMvDFwTRoLJ0wx2E7eWNGndHHdKWR+bX3rUuHRYW8wSV8cFipuS\nnMJ8UvHU4AoaLCp3VL9rXk7OqnnQWY8j/3YsTsJRrn1oz2UGSbWhtlHhVu28\nrE3mwF8uR2spEPD7U6f8CrITv1vqAE+xOKkc3NLRbO+y24urEdog4cqPuxDj\nnj3yIXDTdKyT/bi0JPShznUIk75YoR9U6nr5NSIvcn3wvtbIuEAbYzUN7YpD\n3gjVpqERZQi/rjAuITS26QrAWmEzQdDEXcTQf3uNpStYOspP3NxnocGya2+O\nUkSuqIjRK+h4svRyFRbbmf+a8MAF9GdSfgIqcI1F70enlvJw+dloUsqzxkwq\nxWwm\r\n=Oa4t\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGSfaO/a9g4oaokPrrbFAT+ReGSfIOdtaAzXymYi0PZpAiAyT/VlbKUYg11zmOV+zD7HtSMJF6vq9rlSaqmSR2UlrQ=="}],"size":2735,"noattachment":false,"key":"/cycled/-/cycled-1.2.0.tgz"},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cycled_1.2.0_1594985136048_0.28044967686708233"},"_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":1594985136243,"_cnpm_publish_time":1594985136243,"dist-tags":{"latest":"2.0.0"}}