{"id":19050482,"url":"https://github.com/blakek/range","last_synced_at":"2026-05-02T22:33:57.158Z","repository":{"id":38266755,"uuid":"272332779","full_name":"blakek/range","owner":"blakek","description":"🔢 Generate a range of numbers","archived":false,"fork":false,"pushed_at":"2023-01-06T08:55:00.000Z","size":1642,"stargazers_count":1,"open_issues_count":7,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-09-24T09:10:55.643Z","etag":null,"topics":["javascript","numbers","range","typescript"],"latest_commit_sha":null,"homepage":"","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/blakek.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":"2020-06-15T03:25:14.000Z","updated_at":"2021-10-21T12:29:03.000Z","dependencies_parsed_at":"2023-02-05T18:16:25.173Z","dependency_job_id":null,"html_url":"https://github.com/blakek/range","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/blakek%2Frange","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blakek%2Frange/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blakek%2Frange/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blakek%2Frange/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/blakek","download_url":"https://codeload.github.com/blakek/range/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240107127,"owners_count":19748758,"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":["javascript","numbers","range","typescript"],"created_at":"2024-11-08T23:15:04.286Z","updated_at":"2026-05-02T22:33:57.110Z","avatar_url":"https://github.com/blakek.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# range\n\n\u003e 🔢 Generate a range of numbers\n\nUtilities for creating and sizing a range of numbers.\n\n## Install\n\nUsing [Yarn]:\n\n```bash\n$ yarn add @blakek/range\n```\n\n…or using [npm]:\n\n```bash\n$ npm i --save @blakek/range\n```\n\n## Usage\n\n```js\nimport { range, rangeG, rangeSize } from '@blakek/range';\n\n// Create a list of numbers\nrange(1, 3); //» [ 1, 2, 3 ]\nrange(10, 20, 5); //» [ 10, 15, 20 ]\n\n// Iterate over a range\nfor (const i of rangeG(1, 10, 4)) {\n  console.log(i);\n}\n//» 1\n//» 5\n//» 9\n\n// Get how many steps a range would contain\nrangeSize(1, 20); //» 20\nrangeSize(1, 20, 5); //» 4\n```\n\n## API\n\n### `range`\n\n```ts\nfunction range(from: number, to: number, step?: number = 1): number[];\n```\n\nCreates an array of numbers from a number to another, stepping in increments of\n`step`.\n\n```js\nrange(1, 5); //» [ 1, 2, 3, 4, 5 ]\n\nrange(0, 20, 5); //» [ 0, 5, 10, 15, 20 ]\n\nrange(10, 0, -2); //» [ 10, 8, 6, 4, 2, 0 ]\n\nrange(5, 0, 1);\n//» RangeError: would create infinte range due to stepping in the wrong direction\n```\n\n### `rangeG`\n\n```ts\nfunction rangeG(\n  from: number,\n  to: number,\n  step?: number = 1\n): Generator\u003cnumber, void, number\u003e;\n```\n\nGenerates numbers from a number to another, stepping in increments of `step`.\n\n```js\n[...rangeG(1, 3)]; //» [ 1, 2, 3 ]\n\n[...rangeG(5, 1, -1)]; //» [ 5, 4, 3, 2, 1 ]\n\n[...rangeG(5, 1, 1)]; //» RangeError: would create infinte range due to stepping in the wrong direction\n\nfor (const i of rangeG(0, -Infinity, -2)) {\n  if (i \u003c -20) break;\n  console.log(i);\n}\n//» 0, -2, -4, -6, -8, -10, -12, -14, -16, -18, -20\n```\n\n### `rangeSize`\n\n```ts\nfunction rangeSize(from: number, to: number, step?: number = 1): number;\n```\n\nReturns the number of steps necessary to go from one number to another, stepping\nin increments of `step`.\n\n```js\nrangeSize(1, 100); //» 100\n\nrangeSize(2, 1024, 2); //» 512\n\nrangeSize(100, 1, -5); //» 20\n\nrangeSize(1, 10, -1); //» Infinity\n```\n\n## Contributing\n\n[Node.js] and [Yarn] are required to work with this project.\n\nTo install all dependencies, run:\n\n```bash\nyarn\n```\n\n### Useful Commands\n\n|                     |                                                 |\n| ------------------- | ----------------------------------------------- |\n| `yarn build`        | Builds the project to `./dist`                  |\n| `yarn format`       | Format the source following the Prettier styles |\n| `yarn test`         | Run project tests                               |\n| `yarn test --watch` | Run project tests, watching for file changes    |\n\n## License\n\nMIT\n\n[blakek/deep]: https://github.com/blakek/deep\n[node.js]: https://nodejs.org/\n[npm]: https://npmjs.com/\n[yarn]: https://yarnpkg.com/en/docs/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblakek%2Frange","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblakek%2Frange","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblakek%2Frange/lists"}