Skip to content

Latest commit

 

History

History
640 lines (353 loc) · 10.1 KB

File metadata and controls

640 lines (353 loc) · 10.1 KB

Class: Collection<Type>

Defined in: collection.ts:7

Type Parameters

Type

Type

Constructors

Constructor

new Collection<Type>(items?: Type[]): Collection<Type>;

Defined in: collection.ts:10

Parameters

items?

Type[]

Returns

Collection<Type>

Methods

add()

add(data: Type): this;

Defined in: collection.ts:38

Adds a new element to the end of the collection

Parameters

data

Type

Returns

this


all()

all(): Type[];

Defined in: collection.ts:205

Returns the underlying array represented by the collection

Returns

Type[]


clone()

clone(): Collection<Type>;

Defined in: collection.ts:198

Creates a shallow copy of collection

Returns

Collection<Type>


concat()

concat(collection: Collection<Type>): this;

Defined in: collection.ts:128

Combines elements from both collections into one

Parameters

collection

Collection<Type>

Returns

this


count()

count(): number;

Defined in: collection.ts:78

Returns the number of items in the collection

Returns

number


filter()

filter(iterator: CollectionIterator): Collection<Type>;

Defined in: collection.ts:107

Iterates over elements of collection, returning a collection of all elements that meets the requirements

Parameters

iterator

CollectionIterator

Returns

Collection<Type>


find()

find(iterator: CollectionIterator): Type;

Defined in: collection.ts:33

Return the first element of the collection that meets the requirements

Parameters

iterator

CollectionIterator

Returns

Type


first()

first(iterator?: CollectionIterator): Type;

Defined in: collection.ts:15

Gets the first element of collection

Parameters

iterator?

CollectionIterator

Returns

Type


forEach()

forEach(callback: (item: Type, index?: number) => void | Promise<void>): this;

Defined in: collection.ts:114

Iterates over elements of collection and invokes callback for each element

Parameters

callback

(item: Type, index?: number) => void | Promise<void>

Returns

this


groupBy()

groupBy(iterator: CollectionIterator): Dictionary<Type[]>;

Defined in: collection.ts:184

Creates a Dictionary composed of keys generated from the results of running each element of collection thru iterator

Parameters

iterator

CollectionIterator

Returns

Dictionary<Type[]>


includes()

includes(value: CollectionIterator): boolean;

Defined in: collection.ts:167

Checks if value is in collection

Parameters

value

CollectionIterator

Returns

boolean


indexOf()

indexOf(item: Type): number;

Defined in: collection.ts:88

Gets the index at which the first occurrence of value is found in collection

Parameters

item

Type

Returns

number


intersects()

intersects(collection: Collection<Type>): Collection<Type>;

Defined in: collection.ts:50

Returns a new collection with all unique elements that are in both collections

Parameters

collection

Collection<Type>

Returns

Collection<Type>


intersectsBy()

intersectsBy(collection: Collection<Type>, iterator: string | CollectionIterator): Collection<Type>;

Defined in: collection.ts:59

Returns a new collection with all unique elements that are in both collections, taking into account the specified requirements

Parameters

collection

Collection<Type>

iterator

string | CollectionIterator

Returns

Collection<Type>


isEmpty()

isEmpty(): boolean;

Defined in: collection.ts:137

Returns true if the collection is empty

Returns

boolean


isNotEmpty()

isNotEmpty(): boolean;

Defined in: collection.ts:142

Returns true if the collection is not empty

Returns

boolean


join()

join(separator: string): string;

Defined in: collection.ts:83

Converts all elements in collection into a string separated by separator

Parameters

separator

string

Returns

string


keyBy()

keyBy(iterator: CollectionIterator): Dictionary<Type>;

Defined in: collection.ts:177

Creates a Dictionary composed of keys generated from the results of running each element of collection thru iterator

Parameters

iterator

CollectionIterator

Returns

Dictionary<Type>


last()

last(predicate?: CollectionIterator): Type;

Defined in: collection.ts:24

Gets the last element of collection

Parameters

predicate?

CollectionIterator

Returns

Type


map()

map<Type>(iterator: (item: any) => Type): Collection<Type>;

Defined in: collection.ts:191

Creates a new Collection of values by running each element in collection thru iterator

Type Parameters

Type

Type

Parameters

iterator

(item: any) => Type

Returns

Collection<Type>


missing()

missing(value: CollectionIterator): boolean;

Defined in: collection.ts:172

Checks whether a value is missing from the collection

Parameters

value

CollectionIterator

Returns

boolean


remove()

remove(iterator: CollectionIterator): Collection<Type>;

Defined in: collection.ts:121

Removes all elements from collection that meets the requirements

Parameters

iterator

CollectionIterator

Returns

Collection<Type>


sample()

sample(): Type;

Defined in: collection.ts:45

Gets a random element from collection

Returns

Type


slice()

slice(start?: number, end?: number): Collection<Type>;

Defined in: collection.ts:71

Creates a slice of collection from start up to, but not including, end

Parameters

start?

number

end?

number

Returns

Collection<Type>


sort()

sort(): Collection<Type>;

Defined in: collection.ts:147

Sorts the items in the collection alphabetically

Returns

Collection<Type>


sortBy()

sortBy(
   iterators: 
  | CollectionIterator
  | CollectionIterator[], 
   orders: string[] | "desc" | "asc", 
   natural: boolean): this;

Defined in: collection.ts:154

Sorts collection items according to requirements

Parameters

iterators

CollectionIterator | CollectionIterator[]

orders

string[] | "desc" | "asc"

natural

boolean = true

Returns

this


toJSON()

toJSON(): string;

Defined in: collection.ts:210

Converts the collection into a JSON serialized string

Returns

string


uniq()

uniq(): Collection<Type>;

Defined in: collection.ts:93

Creates a duplicate-free version of a collection

Returns

Collection<Type>


uniqBy()

uniqBy(iterator: CollectionIterator): Collection<Type>;

Defined in: collection.ts:100

Creates a duplicate-free version of a collection according to requirements

Parameters

iterator

CollectionIterator

Returns

Collection<Type>