@kurozero/collection
    TypeScript icon, indicating that this package has built-in type declarations

    0.5.1 • Public • Published

    Collection

    Docs

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

    Browser

    https://unpkg.com/collection@{VERSION}/lib/index.min.js

    <!DOCTYPE html>
    
    <html lang="en">
        <head>
            <meta charset="UTF-8">
            <meta name="description" content="Cars">
            <meta name="keywords" content="HTML,JavaScript,Cars">
            <meta name="author" content="KurozeroPB">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <title>Cars</title>
        </head>
        <body>
            <script src="https://unpkg.com/collection@{VERSION}/lib/index.min.js"></script>
            <script lang="javascript">
                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' }
                // ]
            </script>
        </body>
    </html>



    Node

    yarn add @kurozero/collection or npm i --save @kurozero/collection

    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>(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' }
    // ]

    Install

    npm i @kurozero/collection

    DownloadsWeekly Downloads

    1

    Version

    0.5.1

    License

    MIT

    Unpacked Size

    51.5 kB

    Total Files

    7

    Last publish

    Collaborators

    • kurozero