{"id":17549829,"url":"https://github.com/o0101/js-iterators","last_synced_at":"2025-04-12T02:20:16.055Z","repository":{"id":57283256,"uuid":"351400432","full_name":"o0101/js-iterators","owner":"o0101","description":"Ruby style iterators in JS","archived":false,"fork":false,"pushed_at":"2021-09-14T15:36:32.000Z","size":56,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-10T19:19:12.806Z","etag":null,"topics":["intervals","iterator","javascript","range","ruby"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":false,"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/o0101.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":"2021-03-25T10:48:12.000Z","updated_at":"2021-12-19T03:00:46.000Z","dependencies_parsed_at":"2022-09-17T13:52:49.628Z","dependency_job_id":null,"html_url":"https://github.com/o0101/js-iterators","commit_stats":null,"previous_names":["i5ik/js-iterators","o0101/js-iterators"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/o0101%2Fjs-iterators","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/o0101%2Fjs-iterators/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/o0101%2Fjs-iterators/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/o0101%2Fjs-iterators/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/o0101","download_url":"https://codeload.github.com/o0101/js-iterators/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248505921,"owners_count":21115354,"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":["intervals","iterator","javascript","range","ruby"],"created_at":"2024-10-21T03:04:41.550Z","updated_at":"2025-04-12T02:20:16.032Z","avatar_url":"https://github.com/o0101.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# js-iterators (zero dependencies) ![npm](https://img.shields.io/npm/dt/js-iterators)\n\nRuby style iterators in JS. Ruby style ranges in JS\n\n```js\n\n[...1.._10];              // [1, 2, 3, 4, 5, 6, 7, 8, 9]\n[...1.._-10];             // [1, 0, -1, -2, ..., -9]\n[...Math.PI._9];          // [3.141592653589793, 4.141592653589793, 5.141592653589793, 6.141592653589793, 7.141592653589793, 8.141592653589793]\n[...(-1e3)._1e3];         // [-1000, -999, ..., 998, 999]\n[...1e3._2e3];            // [1000, 1001, ..., 1999]\n[...1..$10];              // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n[...1..__1_213e3];        // [1, 0, -1, ..., -1213]\n[...1..__1_213e_3];       // [1, 0]\n\nfor( let i of 1.._10 ) {\n  console.log(i+1);       // 2, 3, 4, ..., 10\n}\n\nArray.from(1..$10);       // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n\n[...(-10)._$10];          // [-10, -9, ..., 9, 10]\n[...4..times];            // [0, 1, 2, 3]\n[...5..upto(10)];          // [5, 6, 7, 8, 9, 10]\n[...10..downto(5)];        // [10, 9, 8, 7, 6, 5]\n[...4..step(10,2)];        // [4, 6, 8, 10]\n\n```\n\n# get\n\n```console\n$ npm i --save js-iterators@latest\n```\n\n# contribute\n\nPRs only thanks! :)\n\n# why not just use Ruby?\n\nI'm on web\n\n# why not use this other library?\n\nSyntax\n\n# why this?\n\nCool\n\n# Guide\n\n- `\u003cleft_part\u003e\u003c1 or 2 dots\u003e\u003cright_part\u003e`\n- Left part must be a Number\n- Right part must start with _ or $ then be followed by a number\n- Negative numbers on left wrap in ()\n- Negative numbers on right prefix with extra _\n- Right-closed (inclusive end, e.g., [1,3] === 1, 2, 3) intervals use $\n- Right-open (non-inclusive end, e.g., [1,3) === 1, 2) intervals use _\n- Only 1 dot separating left and right parts when left part is:\n  - a negative number (which must be wrapped in `(` and `)`), e.g. Array.from((-10)._20)\n  - a floating point number with decimal places, e.g. [...3.1415._10]\n  - a variable, e.g. [...Math.PI._10]\n  - an octal, e.g. [...0701._500]\n  - a binary, e.g. [...0b101011._500]\n  - a hexadecimal, e.g. [...0xfa._500]\n  - a scientific-notation, e.g. [...1e3._1010]\n- Otherwise, two dots separating left and right parts\n\n\n- Ruby API\n  - `\u003crange\u003e.to_a` send range to an array, e.g. 1.._10.to_a\n  - `\u003cnumber\u003e.upto(high)` count up from number to high inclusive by 1s (or -1s)\n  - `\u003cnumber\u003e.downto(low)` count down from number to low inclusive by 1s (or -1s)\n  - `\u003cnumber\u003e.step(to, by)` count from number to `to` inclusive by `by`s (or -`by`s)\n  - `\u003cnumber\u003e.times` iterate number times (and return integers 0..number-1)\n  - Ruby API is based on [Ruby range](https://ruby-doc.org/core-2.5.1/Range.html) and [Ruby number iterators](https://www.dotnetperls.com/iterator-ruby)\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fo0101%2Fjs-iterators","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fo0101%2Fjs-iterators","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fo0101%2Fjs-iterators/lists"}