Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/pepijn98/collection

A modern Collection implementation in TypeScript
https://github.com/pepijn98/collection

collection map nodejs typescript typescript-library

Last synced: 4 days ago
JSON representation

A modern Collection implementation in TypeScript

Awesome Lists containing this project

README

        






Discord server


NPM version


NPM downloads


Dependencies


Patreon




NPM info


# Collection

## Docs
https://kurozeropb.github.io/Collection/

## Browser
https://unpkg.com/collection@{VERSION}/lib/index.min.js
```html







Cars




class Car {
constructor(details) {
this._key = details.name; // _key will be used as the collection key
this.name = details.name;
this.brand = details.brand;
}
}

const cars = new Collection(Car, [
new Car({ name: "A6", brand: "Audi" }),
new Car({ name: "A1", brand: "Audi" }),
new Car({ name: "A3", brand: "Audi" }),
new Car({ name: "Polo", brand: "Volkswagen" })
]);

const audis = cars.filter((car) => car.brand === "Audi");
console.log(audis);
// [
// Car { name: 'A6', brand: 'Audi' },
// Car { name: 'A1', brand: 'Audi' },
// Car { name: 'A3', brand: 'Audi' }
// ]

```



## Node
`yarn add @kurozero/collection` or `npm i --save @kurozero/collection`
```ts
import Collection from "@kurozero/collection";

interface ICarDetails {
name: string;
brand: string;
}

class Car {
public _key: string;
public name: string;
public brand: string;

public constructor(details: ICarDetails) {
this._key = details.name; // _key will be used as the collection key
this.name = details.name;
this.brand = details.brand;
}
}

const cars = new Collection(Car);
cars.addMany([
new Car({ name: "A6", brand: "Audi" }),
new Car({ name: "A1", brand: "Audi" }),
new Car({ name: "A3", brand: "Audi" }),
new Car({ name: "Polo", brand: "Volkswagen" })
]);

const audis = cars.filter((car) => car.brand === "Audi");
console.log(audis);
// [
// Car { name: 'A6', brand: 'Audi' },
// Car { name: 'A1', brand: 'Audi' },
// Car { name: 'A3', brand: 'Audi' }
// ]
```