# tslinq

> ES5 compatable implementation of LINQ and lazily executed enumerables for typescript.

Latest version **1.0.24** (published 2017-05-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install tslinq
pnpm add tslinq
yarn add tslinq
bun add tslinq
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.24 |
| Published | 2017-05-05 |
| First published | 2017-05-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Robert Rudman |
| Maintainers | rjrudman |
| Keywords | linq, typescript, es6, es5, generators |

## Links

- npm: https://www.npmjs.com/package/tslinq
- Repository: https://github.com/rjrudman/TSLinq
- Homepage: https://github.com/rjrudman/TSLinq#readme
- Issues: https://github.com/rjrudman/TSLinq/issues
- npm.io page: https://npm.io/package/tslinq

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.0.24 (latest) — 2017-05-05
- 1.0.22 — 2017-05-05
- 1.0.21 — 2017-05-05
- 1.0.20 — 2017-05-05
- 1.0.19 — 2017-05-05
- 1.0.18 — 2017-05-04
- 1.0.17 — 2017-05-04
- 1.0.16 — 2017-05-04
- 1.0.15 — 2017-05-03
- 1.0.14 — 2017-05-02
- 1.0.13 — 2017-05-02
- 1.0.12 — 2017-05-02
- 1.0.11 — 2017-05-02
- 1.0.10 — 2017-05-02
- 1.0.9 — 2017-05-02
- … 9 more at https://npm.io/package/tslinq/versions

## README

# TSLinq

[![Version](https://img.shields.io/npm/v/tslinq.svg)](https://npmjs.com/packages/tslinq)
[![Build Status](https://travis-ci.org/rjrudman/TSLinq.svg?branch=master)](https://travis-ci.org/rjrudman/TSLinq)
[![dependencies Status](https://david-dm.org/rjrudman/tslinq/status.svg)](https://david-dm.org/rjrudman/tslinq)
[![devDependencies Status](https://david-dm.org/rjrudman/tslinq/dev-status.svg)](https://david-dm.org/rjrudman/tslinq?type=dev)
[![Downloads](https://img.shields.io/npm/dm/tslinq.svg)](https://npmjs.com/packages/tslinq)

## Details
TSLinq 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. 

TSLinq utilises lazily evaluated `Enumerable<T>`'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.

Ships with a fully functional implementation of `Dictionary<TKey, TValue>()` which supports collision handling, proper identity hashing by default and custom equality comparers.

## Install

```
npm install tslinq
```

## Usage

```typescript
import { Enumerable } from 'tslinq'

let things = Enumerable.Of([1, 2, 3])
    .Select(a => a + 2)
    .Where(a => a < 5)
    .Distinct()
    .ToArray();
    
console.log(things);

// Outputs [ 3, 4 ]
```

## Using ES6 generator functions

```typescript
function* GetNumbers() {
    let i = 0;
    while(true) {
        yield i++;
    }
}

let FirstTenNumbers = Enumerable.Of(GetNumbers)
    .Take(10)
    .ToArray();
    
console.log(FirstTenNumbers);

// Outputs [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
```

## Using manually created generator functions

```typescript
let i = 0;
const generator = () => {
    return {
        next: function () {
            if (i >= 3) {
                throw new Error('Generator should not be invoked when the enumerable hasn\'t been materialized');
            }
            return { done: false, value: i++ };
        }
    };
};

const result =
    Enumerable.Of(generator)
        .Take(3)
        .ToArray();

console.log(result);

// Outputs [ 0, 1, 2 ]
```

### Using Dictionary<TKey, TValue>

#### Basic implementation

```typescript
const objectA: any = {};
const objectB: any = {};

const dictionary = new Dictionary<any, number>();
dictionary.Add(objectA, 5);
dictionary.Add(objectB, 10);

dictionary.Get(objectA); // Returns 5
dictionary.Get(objectB); // Returns 10
```

#### Using a custom equality comparer
```typescript
const objectA: any = {};
const objectB: any = {};

const equalityComparer = {
    Equals: (left: any, right: any) => true,
    GetHashCode: (item: any) => JSON.stringify(item)
};

const dictionary = new Dictionary<any, number>(equalityComparer);
dictionary.Add(objectA, 5);
dictionary.Add(objectB, 10); // Throws an exception, key already exists, as the JSON strings match, 
                             // and we always return true when comparing
```

```typescript
const objectA: any = {};
const objectB: any = {};

const equalityComparer = {
    Equals: (left: any, right: any) => left === right,
    GetHashCode: (item: any) => JSON.stringify(item)
};

const dictionary = new Dictionary<any, number>(equalityComparer);
dictionary.Add(objectA, 5);
dictionary.Add(objectB, 10); // Does not throw - collisions are properly handled,
                             // And we then check for identity equality
```

---
_Source: https://npm.io/package/tslinq · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
