0.0.16 • Published 8 years ago

ts-collections v0.0.16

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

ts-collections

An implementation of collections using TypeScript.

Description

The collections are implements basic functionality such as "find", "sort", "filter", "map", "decorate", etc.

Features

  1. Full compatibility with the Angular2 iterators, therefore you can use them inside the Angular2 templates.
  2. Full compatibility with the lodash.
  3. Full compatibility with the ES6 iterable protocol.
  4. Partial compatibility with the JavaScript Array protocol (find/filter/forEach methods).

Dependencies

Installation

First you need to install the npm module:

npm install ts-collections --save

Use

import * as _ from 'lodash';

const list:_.List<number> = Collections.emptyList<number>().add(100).add(50).add(200);
expect(_(list).min()).toEqual(501);

ProductsStore.ts
You can make the ProductsStore singleton the inheritor of collection and bind them into Angular2 template directly, then use ngFor.

import {Injectable} from '@angular/core';

import {ArrayList} from 'ts-collections/index';
import {Product} from '../../model/Product';

@Injectable()
export class ProductsStore extends ArrayList<Product> {

    constructor() {
        super();
    }
}
*ngFor="let product of productsStore"

App.ts

import {ICollection, Collections} from 'ts-collections/index';

@Component({...})
export class App {
    
    private filteredDecoratedCollection:ICollection<string|number>;

    constructor() {
        const collection:ICollection<string> = Collections.emptyList<string>()
            .add("hello")
            .add("hello world");

        console.log('Collection size:', collection.getSize());                                                  // Collection size: 2

        this.filteredDecoratedCollection = Collections.makeDecoratedList<string, number>(collection, {
            decorate(item:string): number {
                return item.length;
            }
        }).filter({
            check: (wordLength:number) => {
                return wordLength > 5
            }
        });

        console.log('Filtered decorated collection size:', this.filteredDecoratedCollection.getSize());      // Filtered decorated collection size: 1
    }
}

app.html

Angular2 template

<div *ngFor="let decoratedItem of filteredDecoratedCollection">
{{ decoratedItem }}
</div>

Publish

npm deploy

License

Licensed under MIT.

0.0.16

8 years ago

0.0.15

8 years ago

0.0.14

8 years ago

0.0.13

8 years ago

0.0.11

8 years ago

0.0.10

8 years ago

0.0.9

8 years ago

0.0.8

8 years ago

0.0.7

8 years ago

0.0.6

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago