npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@cahmoraes93/extended-set

v1.1.3

Published

This package create a Set with extended functionalities

Downloads

13

Readme

Extended Set

Extended Set is a Set Data structure with extended functionalities. It implements map, reduce and filter functions. In addiction, provides methods to handle Set basic operations.

map

Map a new Set with callback function.

property

- callback: (originalSet) => mappedSet

example

const set = new ExtendedSet<number>()
set.add(2).add(3).add(10)

const result = set.map((item) => item * 2)
console.log(result) // Set {4, 6, 20}

filter

Filter a new Set with callback function.

property

- callback: (originalSet) => filteredSet

example:

const set = new ExtendedSet<number>([1, 2, 3, 4, 5])
const evenSet = set.filter((item) => item % 2 === 0)

console.log(evenSet) // Set {2, 4}

reduce

Create a new Set based in a reducer function.

property

- callback: (originalSet) => reducedValue

example

const set = new ExtendedSet<number>()
set.add(2).add(3).add(0).add(5).add(20)

const smallestNumber = set.reduce((acc, item) => (acc > item ? item : acc))
console.log(smallestNumber) // 0

find

Find an item in Set. Returns the item or null.

property

- callback: (item: Type) => boolean

example

const users = [{ name: 'John' }, { name: 'George' }, { name: 'Jackie' }]
const set = ExtendedSet.of(users)

const findGeorge = set.find((item) => item.name === 'George')
console.log(findGeorge) // { name: 'George' }

const findAnnie = set.find((item) => item.name === 'Annie')
console.log(findAnnie) // null

every

Return true when every element in Set is truthy, else return false

property

- callback: (item: Type) => boolean

example

const users = [1, 2, 3]
const set = ExtendedSet.of(users)

const numbersAreGreaterThanZero = set.every((number) => number > 0)
console.log(numbersAreGreaterTahZero) // true

const numbersAreLessThanZero = set.every((number) => number < 0)
console.log(numbersAreLessThanZero) // false

some

Return true when some element in Set is truthy, else return false

property

- callback: (item: Type) => boolean

example

const numbers = [1, -2, 3, 4]
const set = ExtendedSet.of(numbers)

const isThereNumberLessThanZero = set.some((item) => item < 0)
console.log(isThereNumberLessThanZero) // true

const isThereNumberEqualsZero = set.some((item) => item === 0)
console.log(isThereNumberEqualsZero) // false

of

Create a new Set from an array

property

- anArray = []
// Array to convert into Set

example

const set = ExtendedSet.of([1, 2, 3])
console.log(set.toString()) // 1,2,3

toArray

Create a new Array from Set.

example:

const set = new ExtendedSet<number>([1, 2, 3, 4, 5])
const numbers = set.toArray()

console.log(numbers) // [1, 2, 3, 4, 5]

isSuperSetOf

Check if Set is a superset of other set. Returns true if Set is a superset of other set. Else returns false.

property

- other: Set

example

const set_1 = new ExtendedSet<number>([1, 2, 3, 4])
const set_2 = new ExtendedSet<number>([1, 2])
const result = set_1.union(set_2)

console.log(result) // true

isSubSetOf

Check if Set is a subset of other set. Returns true if Set is a subset of other set. Else returns false.

property

- other: Set

example

const set_1 = new ExtendedSet<number>([1, 2])
const set_2 = new ExtendedSet<number>([1, 2, 3, 4])
const result = set_1.isSubSetOf(set_2)

console.log(result) // true

union

Create new Set from an union of Sets.

property

- others: Set[]

example

const set_1 = new ExtendedSet<number>([1, 2, 3, 4])
const set_2 = new ExtendedSet<number>([1, 5])
const set_3 = new ExtendedSet<number>([6, 2])
const result = set_1.union(set_2, set_3)

console.log(result) // Set {1, 2, 3, 4, 5, 6}

intersection

Create an intersection Set from Sets.

property

- other: Set

example

const set_1 = new ExtendedSet<number>([1, 2, 3, 4])
const set_2 = new ExtendedSet<number>([1, 4])
const result = set_1.intersection(set_2)

console.log(result) // Set {1, 4}

difference

Create an intersection Difference from Sets.

property

- other: Set

example

const set_1 = new ExtendedSet<number>([1, 2, 3, 4])
const set_2 = new ExtendedSet<number>([1, 4])
const result = set_2.difference(set_1)

console.log(result) // Set {2, 3}