{"id":24614216,"url":"https://github.com/parzh/xrange","last_synced_at":"2026-05-20T06:07:16.944Z","repository":{"id":36973370,"uuid":"246038997","full_name":"parzh/xrange","owner":"parzh","description":"Python-esque iterator for number ranges","archived":false,"fork":false,"pushed_at":"2023-11-27T05:06:17.000Z","size":1353,"stargazers_count":0,"open_issues_count":24,"forks_count":0,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2024-05-22T11:15:43.148Z","etag":null,"topics":["generator","infinite","iteration","iterator","lists","lists-python","number-ranges","numbers","python","python-esque-iterator","range","xrange"],"latest_commit_sha":null,"homepage":"https://npmjs.org/package/xrange","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/parzh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-03-09T13:11:50.000Z","updated_at":"2023-07-18T09:11:18.000Z","dependencies_parsed_at":"2024-01-13T20:59:13.298Z","dependency_job_id":"2f580846-541a-4545-95a3-7829fa3b3a7f","html_url":"https://github.com/parzh/xrange","commit_stats":{"total_commits":518,"total_committers":6,"mean_commits":86.33333333333333,"dds":0.5482625482625483,"last_synced_commit":"454db32f8f037adb608756712941a0d7fea216a9"},"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parzh%2Fxrange","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parzh%2Fxrange/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parzh%2Fxrange/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parzh%2Fxrange/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/parzh","download_url":"https://codeload.github.com/parzh/xrange/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244273126,"owners_count":20426866,"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":["generator","infinite","iteration","iterator","lists","lists-python","number-ranges","numbers","python","python-esque-iterator","range","xrange"],"created_at":"2025-01-24T21:15:38.322Z","updated_at":"2026-05-20T06:07:16.893Z","avatar_url":"https://github.com/parzh.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/parzh/xrange/actions?query=workflow%3A%22Test+changes%22\"\u003e\n    \u003cimg alt=\"Test changes\" src=\"https://github.com/parzh/xrange/workflows/Test%20changes/badge.svg\" /\u003e\n  \u003c/a\u003e\n\n  \u003ca href=\"https://www.npmjs.com/package/xrange\"\u003e\n    \u003cimg alt=\"npm version\" src=\"https://badge.fury.io/js/xrange.svg\" /\u003e\n  \u003c/a\u003e\n\n  \u003ca href=\"https://www.npmjs.com/package/xrange\"\u003e\n    \u003cimg alt=\"npm size\" src=\"https://img.shields.io/bundlephobia/min/xrange\" /\u003e\n  \u003c/a\u003e\n\n  \u003cimg alt=\"licence MIT\" src=\"https://img.shields.io/npm/l/xrange\" /\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/parzh/xrange\"\u003e\n    \u003cimg alt=\"github\" src=\"https://img.shields.io/badge/GitHub-repository-444D56\" /\u003e\n  \u003c/a\u003e\n\n  \u003ca href=\"https://www.npmjs.com/package/xrange\"\u003e\n    \u003cimg alt=\"npm\" src=\"https://img.shields.io/badge/npm-package-cb3837\" /\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\u003ch1 align=\"center\"\u003e\u003ccode\u003exrange\u003c/code\u003e\u003c/h1\u003e\n\u003ch3 align=\"center\"\u003ePython-esque iterator for number ranges\u003c/h3\u003e\n\n`xrange` is a function based on Python 3's [`range`](https://docs.python.org/3/library/stdtypes.html?highlight=range#ranges) class (or Python 2's [`xrange`](https://docs.python.org/2.7/library/functions.html#xrange) class). Like the one in Python, `xrange` creates virtual arrays (see [Iterators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)) which allows getting values lazily. This prevents over-the-top memory consumption when using large numbers, and opens the possibility to create never-ending, infinite lists.\n\n\u003cp align=\"center\"\u003e\n  \u003csub\u003e\n    Created with \u003ca href=\"https://npmjs.org/package/create-package-typescript\"\u003e\u003ccode\u003ecreate-package-typescript\u003c/code\u003e\u003c/a\u003e\n  \u003c/sub\u003e\n\u003c/p\u003e\n\n## [Examples](https://github.com/parzh/xrange/tree/main/docs/examples)\n\nSimple iteration:\n\n```ts\nfor (const number of xrange(5))\n  console.log(number); // 0, 1, 2, 3, 4\n```\n\n#### Creation of arrays:\n\n```ts\n[ ...xrange(5) ];\n// [ 0, 1, 2, 3, 4 ]\n```\n\n#### Infinite and backward iteration:\n\n```ts\nxrange(0, Infinity);\n// 0, 1, 2, 3, … (never ends)\n```\n\n```ts\nxrange(10, 0, -1);\n// 10, 9, 8, 7, 6, 5, 4, 3, 2, 1\n```\n\n#### Complex number sequences:\n\n```ts\nxrange(1, (next) =\u003e next \u003c 100, ([ last, prelast = 0 ]) =\u003e last + prelast);\n// 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89\n```\n\n```ts\nxrange(0, () =\u003e true, ([ last ]) =\u003e last ? 0 : 1);\n// 0, 1, 0, 1, 0, 1, … (never ends)\n```\n\n#### Iteration with methods (see [#14](https://github.com/parzh/xrange/issues/14)):\n\n```ts\nxrange(17, 42, 5).forEach(number =\u003e {\n  console.log(number); // 17, 22, 27, 32, 37\n});\n```\n\n\u003e See more in [/docs/examples](https://github.com/parzh/xrange/tree/main/docs/examples)\n\n## `range` vs `xrange`\n\n\u003e Looking for less functionality in a smaller bundle? Check out [`@xrange/core`](https://npmjs.org/package/@xrange/core) and [`@xrange/func`](https://npmjs.org/package/@xrange/func)\n\nThe main difference of `xrange` from [`range`](https://npmjs.org/package/range) is that `xrange` is an iterator, not an array constructor, \u0026mdash; it yields numbers on demand, leaving array creation decision to user, which can always be done using the [`...` spread operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax) or [`Array.from`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from).\n\nWhile also having a larger bundle, `xrange` delegates the actual iteration to [`@xrange/core`](https://npmjs.org/package/@xrange/core), which is vastly smaller, and can be used on its own (in some cases the usage is different though).\n\nWhile `@xrange/core` provides numeric iterator, [`@xrange/func`](https://npmjs.org/package/@xrange/func) implements predicated iteration, provided as a separate smaller package. It also has less error correction, but the functionality is quite similar to `xrange`, since `xrange` uses `@xrange/func` under the hood.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparzh%2Fxrange","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fparzh%2Fxrange","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparzh%2Fxrange/lists"}