{"id":15498787,"url":"https://github.com/radekmie/ranges-set","last_synced_at":"2025-04-22T22:19:20.719Z","repository":{"id":119200319,"uuid":"333985524","full_name":"radekmie/ranges-set","owner":"radekmie","description":"Set operations on human-friendly ranges.","archived":false,"fork":false,"pushed_at":"2024-04-13T12:02:09.000Z","size":1905,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-29T19:22:23.959Z","etag":null,"topics":["friendly","hacktoberfest","human","range","set","util"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/ranges-set","language":"TypeScript","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/radekmie.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"radekmie"}},"created_at":"2021-01-28T23:41:11.000Z","updated_at":"2022-12-08T06:07:26.000Z","dependencies_parsed_at":null,"dependency_job_id":"5a69f44d-b0b0-4ecd-bd29-e42d35af7e20","html_url":"https://github.com/radekmie/ranges-set","commit_stats":{"total_commits":28,"total_committers":2,"mean_commits":14.0,"dds":0.0357142857142857,"last_synced_commit":"72c5e6ec7436fee54c790e75eabbed8befbc0053"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/radekmie%2Franges-set","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/radekmie%2Franges-set/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/radekmie%2Franges-set/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/radekmie%2Franges-set/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/radekmie","download_url":"https://codeload.github.com/radekmie/ranges-set/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249297800,"owners_count":21246479,"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":["friendly","hacktoberfest","human","range","set","util"],"created_at":"2024-10-02T08:47:41.544Z","updated_at":"2025-04-17T01:32:02.628Z","avatar_url":"https://github.com/radekmie.png","language":"TypeScript","readme":"# ranges-set\n\n\u003e Set operations on human-friendly ranges.\n\n## Features\n\n* **Easy** for the users to understand and developers to use\n* **Fast** even for huge ranges\n* **Small** bundle footprint (less than 1Kb gzipped)\n\n## Motivation\n\nA naive implementation of this package would always expand the sets first and then operate on arrays or native `Set` objects. While this approach works, one can hang your app with a simple input of `1-1000000000`.\n\nThat is why `ranges-set` operates on actual _ranges_, resulting in performance scalable with the number of ranges (i.e., the number of commas). **Caution**: it is not the case for `expand`, as it has to return all elements!\n\n## Usage\n\n```ts\nimport { difference, equal, expand, intersection, normalize, subset, union } from 'ranges-set';\n\ndifference('1-4', '2-3'); // '1,4'\nequal('1-3', '1-2'); // false\nexpand('1-3,5-7'); // ['1', '2', '3', '5', '6', '7']\nintersection('1-10', '5-10'); // '5-10'\nnormalize('1,2,3,5,6-8'); // '1-3,5-8'\nsubset('1-3', '1-2'); // true\nunion('1-60,40-100'); // '1-100'\n```\n\n## API\n\n```ts\nfunction difference(textA: string, textB: string): string;\nfunction equal(textA: string, textB: string): boolean;\nfunction expand(text: string): string[];\nfunction intersection(textA: string, textB: string): string;\nfunction normalize(text: string): string;\nfunction subset(textA: string, textB: string): boolean;\nfunction union(textA: string, textB: string): string;\n```\n\nOn top of that, all internal functions are exported with a prefix (`_`). It allows you to achieve the best performance, as you can operate on the internal representation of the parsed objects instead of strings.\n\n```ts\nfunction _compare(reprA: Repr, reprB: Repr): number;\nfunction _createLiteral(text: string): Repr;\nfunction _createRange(min: number, max: number): Repr;\nfunction _differenceReprs(reprsA: Repr[], reprsB: Repr[]): Repr[];\nfunction _equalReprs(reprsA: Repr[], reprsB: Repr[]): boolean;\nfunction _expandReprs(reprs: Repr[]): string[];\nfunction _intersectionRepr(reprA: Repr, reprB: Repr): Repr | null;\nfunction _intersectionReprs(reprsA: Repr[], reprsB: Repr[]): Repr[];\nfunction _parse(text: string): Repr[];\nfunction _parseOne(text: string): Repr;\nfunction _serialize(reprs: Repr[]): string;\nfunction _serializeOne(repr: Repr): string;\nfunction _subsetReprs(reprsA: Repr[], reprsB: Repr[]): boolean;\nfunction _unionRepr(reprA: Repr, reprB: Repr): boolean;\nfunction _unionReprs(reprs: Repr[], repr: Repr): void;\nfunction _unionReprsAt(reprs: Repr[], repr: Repr, index: number): boolean;\n```\n","funding_links":["https://github.com/sponsors/radekmie"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fradekmie%2Franges-set","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fradekmie%2Franges-set","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fradekmie%2Franges-set/lists"}