{"id":26674189,"url":"https://github.com/rjrudman/tslinq","last_synced_at":"2026-04-12T09:46:31.105Z","repository":{"id":57381567,"uuid":"89836972","full_name":"rjrudman/TSLinq","owner":"rjrudman","description":"ES5 compatible implementation of LINQ and lazily executed enumerables for typescript.","archived":false,"fork":false,"pushed_at":"2017-05-05T13:53:57.000Z","size":163,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-06T11:07:48.799Z","etag":null,"topics":["es5","es6","functional-programming","generators","javascript","linq","typescript"],"latest_commit_sha":null,"homepage":"","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/rjrudman.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":"2017-04-30T07:42:33.000Z","updated_at":"2019-08-16T05:28:20.000Z","dependencies_parsed_at":"2022-09-14T17:53:35.858Z","dependency_job_id":null,"html_url":"https://github.com/rjrudman/TSLinq","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rjrudman/TSLinq","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rjrudman%2FTSLinq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rjrudman%2FTSLinq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rjrudman%2FTSLinq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rjrudman%2FTSLinq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rjrudman","download_url":"https://codeload.github.com/rjrudman/TSLinq/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rjrudman%2FTSLinq/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259311962,"owners_count":22838827,"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":["es5","es6","functional-programming","generators","javascript","linq","typescript"],"created_at":"2025-03-26T02:17:46.246Z","updated_at":"2026-04-12T09:46:31.042Z","avatar_url":"https://github.com/rjrudman.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TSLinq\n\n[![Version](https://img.shields.io/npm/v/tslinq.svg)](https://npmjs.com/packages/tslinq)\n[![Build Status](https://travis-ci.org/rjrudman/TSLinq.svg?branch=master)](https://travis-ci.org/rjrudman/TSLinq)\n[![dependencies Status](https://david-dm.org/rjrudman/tslinq/status.svg)](https://david-dm.org/rjrudman/tslinq)\n[![devDependencies Status](https://david-dm.org/rjrudman/tslinq/dev-status.svg)](https://david-dm.org/rjrudman/tslinq?type=dev)\n[![Downloads](https://img.shields.io/npm/dm/tslinq.svg)](https://npmjs.com/packages/tslinq)\n\n## Details\nTSLinq is an ES5 compatible port of [.NET's LINQ library](https://msdn.microsoft.com/en-us/library/bb308959.aspx) which tries to be as true to the original as possible. \n\nTSLinq utilises lazily evaluated `Enumerable\u003cT\u003e`'s, rather than eager evaluation found in other libraries. In addition, it supports [ES6 generators](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/function*) allowing for powerful data manipulation.\n\nShips with a fully functional implementation of `Dictionary\u003cTKey, TValue\u003e()` which supports collision handling, proper identity hashing by default and custom equality comparers.\n\n## Install\n\n```\nnpm install tslinq\n```\n\n## Usage\n\n```typescript\nimport { Enumerable } from 'tslinq'\n\nlet things = Enumerable.Of([1, 2, 3])\n    .Select(a =\u003e a + 2)\n    .Where(a =\u003e a \u003c 5)\n    .Distinct()\n    .ToArray();\n    \nconsole.log(things);\n\n// Outputs [ 3, 4 ]\n```\n\n## Using ES6 generator functions\n\n```typescript\nfunction* GetNumbers() {\n    let i = 0;\n    while(true) {\n        yield i++;\n    }\n}\n\nlet FirstTenNumbers = Enumerable.Of(GetNumbers)\n    .Take(10)\n    .ToArray();\n    \nconsole.log(FirstTenNumbers);\n\n// Outputs [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]\n```\n\n## Using manually created generator functions\n\n```typescript\nlet i = 0;\nconst generator = () =\u003e {\n    return {\n        next: function () {\n            if (i \u003e= 3) {\n                throw new Error('Generator should not be invoked when the enumerable hasn\\'t been materialized');\n            }\n            return { done: false, value: i++ };\n        }\n    };\n};\n\nconst result =\n    Enumerable.Of(generator)\n        .Take(3)\n        .ToArray();\n\nconsole.log(result);\n\n// Outputs [ 0, 1, 2 ]\n```\n\n### Using Dictionary\u003cTKey, TValue\u003e\n\n#### Basic implementation\n\n```typescript\nconst objectA: any = {};\nconst objectB: any = {};\n\nconst dictionary = new Dictionary\u003cany, number\u003e();\ndictionary.Add(objectA, 5);\ndictionary.Add(objectB, 10);\n\ndictionary.Get(objectA); // Returns 5\ndictionary.Get(objectB); // Returns 10\n```\n\n#### Using a custom equality comparer\n```typescript\nconst objectA: any = {};\nconst objectB: any = {};\n\nconst equalityComparer = {\n    Equals: (left: any, right: any) =\u003e true,\n    GetHashCode: (item: any) =\u003e JSON.stringify(item)\n};\n\nconst dictionary = new Dictionary\u003cany, number\u003e(equalityComparer);\ndictionary.Add(objectA, 5);\ndictionary.Add(objectB, 10); // Throws an exception, key already exists, as the JSON strings match, \n                             // and we always return true when comparing\n```\n\n```typescript\nconst objectA: any = {};\nconst objectB: any = {};\n\nconst equalityComparer = {\n    Equals: (left: any, right: any) =\u003e left === right,\n    GetHashCode: (item: any) =\u003e JSON.stringify(item)\n};\n\nconst dictionary = new Dictionary\u003cany, number\u003e(equalityComparer);\ndictionary.Add(objectA, 5);\ndictionary.Add(objectB, 10); // Does not throw - collisions are properly handled,\n                             // And we then check for identity equality\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frjrudman%2Ftslinq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frjrudman%2Ftslinq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frjrudman%2Ftslinq/lists"}