{"id":17444673,"url":"https://github.com/kleinfreund/reverse-iterable-array","last_synced_at":"2025-05-13T01:04:18.434Z","repository":{"id":32841768,"uuid":"144186670","full_name":"kleinfreund/reverse-iterable-array","owner":"kleinfreund","description":"A reverse-iterable array implementation based on the built-in Array object. ","archived":false,"fork":false,"pushed_at":"2024-10-20T18:58:16.000Z","size":803,"stargazers_count":3,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-13T01:02:40.560Z","etag":null,"topics":["array","iterable","iterator","reverse-iterable"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/reverse-iterable-array","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kleinfreund.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-09T17:58:47.000Z","updated_at":"2024-10-20T18:58:20.000Z","dependencies_parsed_at":"2024-10-25T18:42:23.883Z","dependency_job_id":"ef4b442f-bd89-43b4-b35e-04983f3bc3f6","html_url":"https://github.com/kleinfreund/reverse-iterable-array","commit_stats":{"total_commits":64,"total_committers":3,"mean_commits":"21.333333333333332","dds":0.234375,"last_synced_commit":"175045928ab862010416a63ac5814a20f2387ce4"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kleinfreund%2Freverse-iterable-array","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kleinfreund%2Freverse-iterable-array/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kleinfreund%2Freverse-iterable-array/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kleinfreund%2Freverse-iterable-array/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kleinfreund","download_url":"https://codeload.github.com/kleinfreund/reverse-iterable-array/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253850874,"owners_count":21973672,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["array","iterable","iterator","reverse-iterable"],"created_at":"2024-10-17T17:53:23.479Z","updated_at":"2025-05-13T01:04:18.393Z","avatar_url":"https://github.com/kleinfreund.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# reverse-iterable-array\n\nThe `ReverseIterableArray` object is a reverse-iterable array implementation based on the built-in [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) object.\n\nLinks:\n\n- [**npmjs.com**/package/reverse-iterable-array](https://www.npmjs.com/package/reverse-iterable-array)\n\t- [on BundlePhobia](https://bundlephobia.com/result?p=reverse-iterable-array)\n- [**github.com**/kleinfreund/reverse-iterable-array](https://github.com/kleinfreund/reverse-iterable-array)\n\nSee also:\n\n- `ReverseIterableMap`: [reverse-iterable-map](https://www.npmjs.com/package/reverse-iterable-map)\n- `ReverseIterableSet`: [reverse-iterable-set](https://www.npmjs.com/package/reverse-iterable-set)\n\n## Table of Contents\n\n- [Installation](#installation)\n- [Usage](#usage)\n- [Examples](#examples)\n- [Tests](#tests)\n- [Documentation](#documentation)\n\t- [Constructor](#constructor)\n\t- [`[Symbol.toStringTag]`](#symboltostringtag)\n\t- [`entries()`](#entries)\n\t- [`forEachReverse()`](#foreachreverse)\n\t- [`iteratorFor()`](#iteratorfor)\n\t- [`keys()`](#keys)\n\t- [`reverseIterator()`](#reverseiterator)\n\t- [`values()`](#values)\n\t- [`[Symbol.iterator]()`](#symboliterator)\n\n\t## Installation\n\n```sh\nnpm install reverse-iterable-array\n```\n\n## Usage\n\n```js\nimport ReverseIterableArray from 'reverse-iterable-array';\n\nconst array = new ReverseIterableArray();\n```\n\n## Examples\n\nFor some live usage examples, clone the repository and run the following:\n\n```sh\nnpm install\nnpm run build\nnpm start\n```\n\nThen, open [localhost:8080/examples](http://127.0.0.1:8080/examples) in a browser.\n\n## Tests\n\nIn order to run the tests, clone the repository and run the following:\n\n```sh\nnpm install\nnpm test\n```\n\n## Documentation\n\nA `ReverseIterableArray` object iterates its elements in insertion or reverse-insertion order — a [`for...of`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of) loop returns the array’s elements for each iteration.\n\n### Constructor\n\n#### Syntax\n\n```\nnew ReverseIterableArray([iterable])\n```\n\n**Parameters**:\n\n- `iterable`: An [iterable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterable_protocol) object.\n\n#### Usage\n\n- Without arguments\n\n\t```js\n\tconst array = new ReverseIterableArray();\n\t//\u003e Array []\n\t```\n\n- With multiple elements\n\n\t```js\n\tconst array = new ReverseIterableArray(1, 2, 3);\n\t//\u003e Array(3) [ 1, 2, 3 ]\n\t```\n\n- With a single length argument\n\n\t```js\n\tconst array = new ReverseIterableArray(7);\n\t//\u003e Array(7) [ \u003c7 empty slots\u003e ]\n\t```\n\n\t### `[Symbol.toStringTag]`\n\nThe `ReverseIterableArray[@@toStringTag]` property has an initial value of “ReverseIterableArray”.\n\n### `entries()`\n\nReturns an iterator containing the `[index, element]` pairs for each element in the `ReverseIterableArray` object in insertion order.\n\nAn iterator containing the same pairs in reverse-insertion order can be obtained with `entries().reverseIterator()`.\n\n#### Syntax\n\n```\narray.entries();\n```\n\n**Return value**:\n\nA new `ReverseIterableArray` iterator object.\n\n#### Usage\n\n```js\nconst array = new ReverseIterableArray(1, 2, 4);\n\nconst iterator = array.entries();\n\niterator.next().value;\n//\u003e [0, 1]\n\niterator.next().value;\n//\u003e [1, 2]\n\niterator.next().value;\n//\u003e [2, 4]\n\niterator.next().value;\n//\u003e undefined\n```\n\n### `forEachReverse()`\n\nThe `forEachReverse()` method executes a provided function once per each `[index, element]` pair in the `ReverseIterableArray` object, in reverse-insertion order.\n\n#### Syntax\n\n```\narray.forEachReverse(callback[, thisArg]);\n```\n\n**Parameters**:\n\n- **callback**: Function to execute for each element.\n- **thisArg**: Value to use as `this` when executing `callback`.\n\n#### Usage\n\n```js\nconst array = new ReverseIterableArray('a', 'b', 'c');\n\narray.forEachReverse(value =\u003e {\n\tconsole.log(value);\n});\n//\u003e c\n//\u003e b\n//\u003e a\n\narray.forEachReverse(function (value, key, arrayReference) {\n\tconsole.log(key, value, arrayReference.size);\n});\n//\u003e 2 c 3\n//\u003e 1 b 3\n//\u003e 0 a 3\n```\n\n### `iteratorFor()`\n\nReturns an iterator containing the `[index, element]` pairs for each element in the `ReverseIterableArray` object in insertion order **starting with the pair specified by the `index` parameter**.\n\nThis allows starting iteration at a specific element in the array.\n\nAn iterator containing the same pairs in reverse-insertion order can be obtained with `iteratorFor(index).reverseIterator()`.\n\n#### Syntax\n\n```\narray.iteratorFor(index);\n```\n\n**Parameters**:\n\n- **index**: Required. The index of the element to start iterating from.\n\n**Return value**:\n\nA new `ReverseIterableArray` iterator object.\n\n#### Usage\n\n```js\nconst array = new ReverseIterableArray('a', 'b', 'c');\n\n// Iterator, starting at the element with key 1.\nconst iterator = array.iteratorFor(1);\n\niterator.next().value;\n//\u003e [1, 'b']\n\niterator.next().value;\n//\u003e [2, 'c']\n\niterator.next().value;\n//\u003e undefined\n\n// Reverse-iterator, starting at the element with key 1.\nconst reverseIterator = array.iteratorFor(1).reverseIterator();\n\nreverseIterator.next().value;\n//\u003e [1, 'c']\n\nreverseIterator.next().value;\n//\u003e [0, 'a']\n\nreverseIterator.next().value;\n//\u003e undefined\n```\n\n### `keys()`\n\nReturns an iterator containing the indices for each element in the `ReverseIterableArray` object in insertion order.\n\nAn iterator containing the same indices in reverse-insertion order can be obtained with `keys().reverseIterator()`.\n\n#### Syntax\n\n```\narray.keys();\n```\n\n**Return value**:\n\nA new `ReverseIterableArray` iterator object.\n\n#### Usage\n\n```js\nconst array = new ReverseIterableArray(1, 2, 4);\n\nconst iterator = array.keys();\n\niterator.next().value;\n//\u003e 0\n\niterator.next().value;\n//\u003e 1\n\niterator.next().value;\n//\u003e 2\n\niterator.next().value;\n//\u003e undefined\n```\n\n### `reverseIterator()`\n\nIn theory, following the semantics of `[Symbol.iterator]()`, this should be `[Symbol.reverseIterator]()`. However, as a developer, I cannot define a well-known symbol myself and make use of it. In the future, the a proposal like [The ReverseIterable Interface, by Lee Byron](https://github.com/leebyron/ecmascript-reverse-iterable) might make it’s way into the specification. For the time being, the `reverseIterator()` function serves the same purpose.\n\n#### Syntax\n\n```\narray.reverseIterator();\n```\n\n**Return value**:\n\nThe array **reverse-iterator** function, which is the `values().reverseIterator()` function by default.\n\n#### Usage\n\n```js\nconst array = new ReverseIterableArray(1, 2, 4);\n\nconst iterator = array.reverseIterator();\n\niterator.next().value;\n//\u003e [2, 4]\n\niterator.next().value;\n//\u003e [1, 2]\n\niterator.next().value;\n//\u003e [0, 1]\n\niterator.next().value;\n//\u003e undefined\n```\n\n### `values()`\n\nReturns an iterator containing the elements in the `ReverseIterableArray` object in insertion order.\n\nAn iterator containing the same elements in reverse-insertion order can be obtained with `values().reverseIterator()`.\n\n#### Syntax\n\n```\narray.values();\n```\n\n**Return value**:\n\nA new `ReverseIterableArray` iterator object.\n\n#### Usage\n\n```js\nconst array = new ReverseIterableArray(1, 2, 4);\n\nconst iterator = array.values();\n\niterator.next().value;\n//\u003e 1\n\niterator.next().value;\n//\u003e 2\n\niterator.next().value;\n//\u003e 4\n\niterator.next().value;\n//\u003e undefined\n```\n\n### `[Symbol.iterator]()`\n\nReturns the array iterator function. By default, this is the `values()` function.\n\n#### Syntax\n\n```\narray[Symbol.iterator]();\n```\n\n**Return value**:\n\nThe array **iterator** function, which is the `entries()` function by default.\n\n#### Usage\n\n```js\nconst array = new ReverseIterableArray(1, 2, 4);\n\nconst iterator = array[Symbol.iterator]();\n\niterator.next().value;\n//\u003e 1\n\niterator.next().value;\n//\u003e 2\n\niterator.next().value;\n//\u003e 4\n\niterator.next().value;\n//\u003e undefined\n```\n\n### `[Symbol.toStringTag]()`\n\nThe well-known symbol `Symbol.toStringTag` is accessed internally when callig `Object.prototype.toString()`.\n\n#### Usage\n\n```js\nconst array = new ReverseIterableArray();\n\nObject.prototype.toString.call(array)\n//\u003e [object ReverseIterableArray]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkleinfreund%2Freverse-iterable-array","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkleinfreund%2Freverse-iterable-array","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkleinfreund%2Freverse-iterable-array/lists"}