nowjs-core
Version:
NowCanDo Javascript Core [nowjs-core] is a library written by TypeScript code maintains under Apache 2.0 licence
85 lines (84 loc) • 2.07 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const index_1 = require("../linq/index");
const index_2 = require("./index");
class ReadonlyCollection {
constructor(enumerable) {
this.arr = [];
if (enumerable && enumerable[Symbol.iterator]) {
for (const x of enumerable) {
this.arr.push(x);
}
}
}
clear() {
this.arr.splice(0, this.arr.length);
return true;
}
contains(item) {
return this.arr.includes(item);
}
get size() {
return this.arr.length;
}
get(index) {
return this.arr[index];
}
indexOf(item) {
return this.arr.indexOf(item);
}
lastIndexOf(item) {
return this.arr.lastIndexOf(item);
}
clone() {
return new index_2.Collection(this);
}
join(seperator) {
let res = '';
const that = this;
seperator = seperator !== undefined ? seperator : ' , ';
if (that.size === 0) {
return '';
}
else if (that.size === 1) {
return that[Symbol.iterator]().next().value.toString();
}
else {
const itr = that[Symbol.iterator]();
res = itr.next().value.toString();
for (const item of itr) {
res = res + seperator + item.toString();
}
}
return res;
}
isEmpty() {
return this.size === 0;
}
toArray() {
const arr = [];
for (const item of this) {
arr.push(item);
}
return arr;
}
toCollection() {
return new index_2.Collection(this);
}
toList() {
return new index_2.List(this);
}
toSet() {
return new Set(this);
}
linq() {
return new index_1.Enumerable(this);
}
plinq() {
return new index_1.ParallelEnumerable(this);
}
[Symbol.iterator]() {
return this.arr[Symbol.iterator]();
}
}
exports.ReadonlyCollection = ReadonlyCollection;