Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/pepijn98/collection
- Owner: Pepijn98
- License: mit
- Created: 2019-06-04T08:50:51.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-07-30T14:36:45.000Z (over 4 years ago)
- Last Synced: 2024-12-26T09:05:02.067Z (12 days ago)
- Topics: collection, map, nodejs, typescript, typescript-library
- Language: TypeScript
- Homepage: https://pepijn98.github.io/Collection/
- Size: 641 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# 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' }
// ]
```