{"id":18064378,"url":"https://github.com/alrik/iterate-javascript","last_synced_at":"2025-04-05T14:13:39.573Z","repository":{"id":57093917,"uuid":"121682321","full_name":"alrik/iterate-javascript","owner":"alrik","description":"A handy function with a unified interface to iterate Strings, Arrays, TypedArrays, Maps, Sets, (any Iterables) \u0026 Objects.","archived":false,"fork":false,"pushed_at":"2018-02-15T22:20:54.000Z","size":18,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-03T18:41:24.925Z","etag":null,"topics":["array-iteration","iterate-js","iterate-js-library","map-iteration","object-iteration","set-iteration","string-iteration","utility-library"],"latest_commit_sha":null,"homepage":null,"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/alrik.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-15T21:01:17.000Z","updated_at":"2024-05-15T08:16:29.000Z","dependencies_parsed_at":"2022-08-22T21:40:38.837Z","dependency_job_id":null,"html_url":"https://github.com/alrik/iterate-javascript","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alrik%2Fiterate-javascript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alrik%2Fiterate-javascript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alrik%2Fiterate-javascript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alrik%2Fiterate-javascript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alrik","download_url":"https://codeload.github.com/alrik/iterate-javascript/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247345842,"owners_count":20924102,"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-iteration","iterate-js","iterate-js-library","map-iteration","object-iteration","set-iteration","string-iteration","utility-library"],"created_at":"2024-10-31T06:06:13.819Z","updated_at":"2025-04-05T14:13:39.555Z","avatar_url":"https://github.com/alrik.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# iterate-javascript\n\n[![Subscribe to Release Notes](https://release-notes.com/badges/v1.svg)](https://release-notes.com/@alrik/iterate-javascript)\n[![NPM Package](https://img.shields.io/npm/v/@a-z/iterate-it.svg)](https://www.npmjs.com/package/@a-z/iterate-it)\n[![MIT license](https://img.shields.io/github/license/alrik/iterate-javascript.svg)](LICENSE)\n\nA handy function with a **unified interface** to iterate Strings, Arrays, TypedArrays, Maps, Sets, (any Iterables) \u0026 Objects.\nThe api is oriented on [Array.prototype.forEach](https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)\nwith the advantage of **iterating almost everything** and **iteration skipping**.\n\n## Installation\n\n```bash\n$ yarn add @a-z/iterate-it\n# or\n$ npm i -S @a-z/iterate-it\n```\n\n## Usage\n\nThe module `@a-z/itarate-it` exports a single function that takes to parameters; an iterable and a callback.\nThe `iterate` function returns a iteration result, that indicates if the iteration was complete of has been skipped.\n\n\n```js\nconst iterate = require('@a-z/iterate-it');\nconst { complete } = iterate(iterable, callback);\n```\n\n### Parameters\n\n#### iterable\nThe iterable or object to iterate over.\nSupported types are String, Array, TypedArray, Map, Set, (any Iterable) \u0026 Object.\n\n#### callback\nA function to be called with every element or value of the iterable.\nThe iteration will stop if the function returns `false`.\n\nThe function takes 3 parameters:\n\n* **value**: The current element being processed.\n* **key**: The corresponding key\n* **iterable**: The iterable passed to iterate\n\n### Return Value\n`iterate()` returns a status object with the following properties:\n\n* **complete**: Will be `true` if all items have been iterated, falthy if the iteration was stoped before.\n\n### Examples\n\n#### Iterating strings\n```js\niterate(\"a1b2c3d4e5\", (char, index, str) =\u003e {}); \n// =\u003e \"12345\"\niterate(new String(\"a1b2c3d4e5\"), (char, index, str) =\u003e {}); \n// =\u003e [String: '12345']\n```\n\n#### Iterating maps\n```js\nconst map = new Map([['a', 1], ['b', 2], ['c', 3]]);\n\niterate(map, (value, key) =\u003e console.log(key, value)); \n// a 1\n// b 2\n// c 3\n```\n\n#### Iterating sets\n```js\nconst set = new Set(['a', 1, 'b']);\n\niterate(set, (value, key) =\u003e console.log(key, value)); \n// a a\n// 1 1\n// b b\n```\n\n#### Iterating arrays\n```js\nconst arr = ['a', 1, 'b'];\n\niterate(arr, (value, index) =\u003e console.log(index, value)); \n// 0 a\n// 1 1\n// 2 b\n```\n\n#### Iterating typed arrays\n```js\nconst typedArr = new Int32Array([1, 2, -3]);\n\niterate(typedArr, (value, index) =\u003e console.log(index, value));\n// 0 1\n// 1 2\n// 2 -3\n```\n\n#### Iterating plain objects\n```js\nconst obj = { a: 1, b: 2, c: 3 };\n\niterate(obj, (value, key) =\u003e console.log(key, value)); \n// a 1\n// b 2\n// c 3\n```\n\n#### Skipping the iteration\n```js\nconst arr = [1, 2, undefined, 3, 4];\n\nconst { complete } = iterate(arr, (value) =\u003e {\n  console.log(value);\n  \n  // skip iteration as soon as there is an invalid item\n  if (typeof value === 'undefined') {\n    return false;\n  }\n});\n\nconsole.log(complete === true)\n\n// 1\n// 2\n// false\n```\n\n---\n\n### LICENSE\n\nThe files in this archive are released under MIT license.\nYou can find a copy of this license in [LICENSE](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falrik%2Fiterate-javascript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falrik%2Fiterate-javascript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falrik%2Fiterate-javascript/lists"}