{"id":13739947,"url":"https://github.com/vihanb/babel-plugin-loop-optimizer","last_synced_at":"2025-07-27T20:04:57.466Z","repository":{"id":57188855,"uuid":"75040643","full_name":"vihanb/babel-plugin-loop-optimizer","owner":"vihanb","description":"Optimizes statements such as `forEach` and `map` to for loops.","archived":false,"fork":false,"pushed_at":"2020-07-19T06:03:08.000Z","size":93,"stargazers_count":74,"open_issues_count":9,"forks_count":7,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-30T10:31:53.321Z","etag":null,"topics":["babel-plugin"],"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/vihanb.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":"2016-11-29T03:47:08.000Z","updated_at":"2023-10-05T17:56:11.000Z","dependencies_parsed_at":"2022-08-28T12:51:36.542Z","dependency_job_id":null,"html_url":"https://github.com/vihanb/babel-plugin-loop-optimizer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/vihanb/babel-plugin-loop-optimizer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vihanb%2Fbabel-plugin-loop-optimizer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vihanb%2Fbabel-plugin-loop-optimizer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vihanb%2Fbabel-plugin-loop-optimizer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vihanb%2Fbabel-plugin-loop-optimizer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vihanb","download_url":"https://codeload.github.com/vihanb/babel-plugin-loop-optimizer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vihanb%2Fbabel-plugin-loop-optimizer/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267417664,"owners_count":24083839,"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","status":"online","status_checked_at":"2025-07-27T02:00:11.917Z","response_time":82,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["babel-plugin"],"created_at":"2024-08-03T04:00:40.034Z","updated_at":"2025-07-27T20:04:57.439Z","avatar_url":"https://github.com/vihanb.png","language":"JavaScript","readme":"# babel-plugin-loop-optimizer\n\n**WARNING:** This package is **unmaintained**. It probably still works but I am not able to maintain it. If anyone wishes to pick this up leave an issue and I can give access.\n\nAlso, that package aren't working with newest Babel (that have @babel namespace) right now.\n\nOptimizes `.forEach`, `.every`, `.find`, `.map`, `.filter` statements to `for` stements\n\n## Installation\n\n```sh\n$ npm install babel-plugin-loop-optimizer\n```\n\n## Usage\n\n### Via `.babelrc` (Recommended)\n\n**.babelrc**\n\n```json\n{\n  \"plugins\": [\"babel-plugin-loop-optimizer\"]\n}\n```\n\n### Via CLI\n\n```sh\n$ babel --plugins loop-optimizer script.js\n```\n\n### Via Node API\n\n```js\nrequire('babel').transform('code', {\n  plugins: ['loop-optimizer']\n});\n```\n\n## Bugs?\n\nNow you may say \"wait, wait, wait!\" This optimizes on things that aren't just arrays! My `map#forEach` is optimized too! To fix this, add a comment that says `// O: KEEP` right before the line on which you use some optimized function. Examples:\n\n```js\nvar m = new Map();\n// loop-optimizer: KEEP\nm.forEach(f)\n```\n\nor:\n\n```js\nvar s = new Set();\n// loop-optimizer: KEEP\nfor (var i = 0; i \u003c 5; s.forEach(f)) {\n    // ...\n}\n```\n\nThis is required since it is not possible to determine an object's type at compile-time.\n\nAlso, if you don't want reverse order, you can disable this (optimization) behavior by adding comment `// loop-optimizer: FORWARD` right before the line on which you use some optimized function. Example:\n```js\nlet ar = [1, 2, 3]\n// loop-optimizer: FORWARD\nar.forEach(console.log)\n```\n\n## Example\n\n```js\nfunction timesTwo(arr) {\n\treturn arr.map(n =\u003e n * 2);\n}\n```\nto:\n```js\nfunction timesTwo(arr) {\n    let _a = arr;\n    let _f = n =\u003e n * 2;\n    let _r = [];\n\n    for (let _i = _a.length; _i--;)\n        _r.push(_f(_a[_i], _i, _a));\n\n    return _r;\n}\n```\n\n---\n\nIf you need any other help, don't hesitate to leave an issue\n","funding_links":[],"categories":["Plugins"],"sub_categories":["Optimization"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvihanb%2Fbabel-plugin-loop-optimizer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvihanb%2Fbabel-plugin-loop-optimizer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvihanb%2Fbabel-plugin-loop-optimizer/lists"}