
Company News
Socket Joins New OpenJS Program to Fund Node.js Security Work
Socket is joining the OpenJS Security Stewardship Program to fund Node.js vulnerability research, maintainer remediation, and security releases.
@ellescript/collecty
Advanced tools
allows iterating an array of elements with an easy-to-read syntax and gives functionality to the collection and the elements it iterates.
This is an amazing library that allows you to create collections and iterate over them, allowing you to create functionality for the collections and the elements it iterates over.
npm install @ellescript/collecty
for example, maybe you could have an array of authors as a json format:
const authorsArray = [
{
"name": "Arthur",
"gender": "male",
"age": 15
},
{
"name": "Veronica",
"gender": "female",
"age": 40
},
{
"name": "Johnson",
"gender": "male",
"age": 33
}
]
import the Collection
If you are using ECMAScript Modules:
import { Collection } from '@ellescript/collecty';
If you are using CommonJS:
const Collection = require('@ellescript/collecty').Collection;
If you are using the web browser:
<script src="https://unpkg.com/@ellescript/collecty/dist/umd/index.umd.cjs"></script>
<script>
const Collection = Collecty.Collection
// ...
</script>
in the next code, as you can see, you can create your own collection, allowing you to transform each element that it has from an object to your custom Author class
class AuthorCollection extends Collection {
/**
* each iteration will return an Author
*
**/
public item(item:any): Author {
return new Author(item)
}
/**
* You can create your custom filters for your own collection
*
**/
public malePeople(): AuthorCollection{
// ... code
}
public femalePeople(): AuthorCollection {
// ... code
}
}
class Author {
public item;
constructor(item:any) {
this.item = item
}
public gender(): boolean {
// ... code
}
public isLegalAge(): boolean {
// .. code
}
}
const authors = new AuthorCollection(authorsArray)
In the code above, you can easily get the male or female people with an easy-to-read-syntax:
authors.malePeople()
and you can know if each person is legal age or not:
for (const author of authors) {
console.log(author.isLegalAge())
}
const collection = new AuthorCollection([
{
"name": "Arthur",
"gender": "male",
"age": 15
},
{
"name": "Veronica",
"gender": "female",
"age": 40
},
{
"name": "Johnson",
"gender": "male",
"age": 33
}
])
collection.concat([{
"name": "Carl",
"gender": "male",
"age": 56
}])
console.log(collection.toArray())
// output
> [{
"name": "Arthur",
"gender": "male",
"age": 15
},
{
"name": "Veronica",
"gender": "female",
"age": 40
},
{
"name": "Johnson",
"gender": "male",
"age": 33
}, {
"name": "Carl",
"gender": "male",
"age": 56
}]
checks if the collection contains at least one item which matches with the callback
const collection = new AuthorCollection([{
"name": "Johnson",
"gender": "male",
"age": 33
}, {
"name": "Carl",
"gender": "male",
"age": 56
}])
collection.contains( (author: Author) => author.age() > 50 )
// output
> true
collection.contains((author: Author) => {
return author.age() < 30
})
// output
> false
gets total items in the collection
const collection = new AuthorCollection([{
"name": "Johnson",
"gender": "male",
"age": 33
}, {
"name": "Carl",
"gender": "male",
"age": 56
}]);
console.log("total", collection.count())
// output
> total 3
returns a new collection with the items that match with the callback given
let collection = new Collection([1, 2, 3])
let newCollection = collection.filter((item: number) => {
return item <= 2
})
console.log(newCollection.toArray())
// output
> [1,2]
gets the first item in the collection
const collection = new Collection([1,2,3])
console.log("first element", collection.first())
// output
> first element 1
gets the first item which match with the callback condition
let persons = new PersonCollection([{
'name': 'rix'
}, {
'name': 'roger'
}])
const person = persons.firstWhere((person: Person) => {
return person.name() == "roger"
})
// output
> Person { item { name: "roger" } }
creates a new collection from a json
collection = Collection.fromJson("[1,2,3]")
gets the item acording to the given index
const collection = new Collection([1, 2, 3])
console.log(collection.get(1))
\\ output
> 2
checks if the collection has at least one item
const collection = new Collection([1,2,3])
console.log(collection.isEmpty())
// output
> false
const collection = new Collection([])
console.log(collection.isEmpty())
// output
> true
returns a collection with the data mapped for each element
class PersonCollection extends Collection {
item(item: any): Person {
return new Person(item)
}
}
class Person {
private item;
constructor(item: any) {
this.item = item
}
public name() {
return this.item.name
}
}
let persons = new PersonCollection([{
'name': 'rix'
}, {
'name': 'roger'
}])
const names = persons.map((person: Person) => {
return person.name()
})
let collection = new Collection([1,2,3])
console.log(collection.pop())
// output
> 3
console.log(collection.torray())
// output
> [1,2]
push new item to the collection
let collection = new Collection([1,2,3])
collection.push(4)
collection.toArray()
// output
> [1,2,3,4]
gets a random item
collection = new Collection([1,2,3])
console.log(collection.random())
//output
> 3 (obtained randomly)
Transforms the collection to a javascript native array
collection = new Collection([1,2,3])
console.log(collection.toArray())
// output
> [1,2,3]
if you whish to collaborate to Collecty, you can pull request to the repository: click here to go to the repository
git commit -am <message>
npm version <patch | minor | major>
npm login
npm publish
FAQs
allows iterating an array of elements with an easy-to-read syntax and gives functionality to the collection and the elements it iterates.
The npm package @ellescript/collecty receives a total of 12 weekly downloads. As such, @ellescript/collecty popularity was classified as not popular.
We found that @ellescript/collecty demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.

Company News
Socket is joining the OpenJS Security Stewardship Program to fund Node.js vulnerability research, maintainer remediation, and security releases.

Security News
Two compromised GitHub Actions were re-enabled with malicious tags intact, exposing thousands of downstream repositories to Mini Shai-Hulud.

Research
/Security News
A malicious Firefox extension fetches its payload after installation to evade detection, steal Google session cookies, and automate account takeover.