🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

@js-commons/super-set

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@js-commons/super-set

SuperSet class extends Set and add some methods, such as higher-order function.

1.0.1
latest
Source
npm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

npm version JavaScript Style Guide

SuperSet

SuperSet class extends Set and add some methods, such as higher-order function.

Installation

$ npm i @js-commons/super-set

or

$ yarn add @js-commons/super-set

Use in your script

const SuperSet = require('@js-commons/super-set')

or

import SuperSet from '@js-commons/super-set'

API

You can use Set's self methods and below additional methods.

Creation

SuperSet.empty()

const set = SuperSet.empty()
console.log(set) // {}

SuperSet.of(...values)

const set = SuperSet.of('foo', 'bar')
console.log(set) // { 'foo', 'bar' }

SuperSet.from(iterable)

const set = new Set(['foo', 'bar'])
const superSet = SuperSet.from(set)
console.log(superSet) // { 'foo', 'bar' }

Intermediate operation

SuperSet.peek(callback)

const set = SuperSet.of('foo', 'bar')
const tmpArray = []
const peekedSet = set.peek(v => tmpArray.push(v))
console.log(peekedSet) // { 'foo', 'bar' }
console.log(tmpArray) // [ 'foo', 'bar' ]

SuperSet.peek(callback, thisArg)

const set = SuperSet.of('foo', 'bar')
const thisArg = 'baz'
const tmpArray = []
const peekedSet = set.peek(function (v) {
  tmpArray.push(v + this)
}, thisArg)
console.log(peekedSet) // { 'foo', 'bar' }
console.log(tmpArray) // [ 'foobaz', 'barbaz' ]

SuperSet.filter(callback)

const set = SuperSet.of('foo', 'bar')
const filteredSet = set.filter(v => v.startsWith('f'))
console.log(filteredSet) // { 'foo' }

SuperSet.map(callback)

const set = SuperSet.of('foo', 'bar')
const mappedSet = set.map(v => v + '_')
console.log(mappedSet) // { 'foo_', 'bar_' }

Terminal operation

SuperSet.find(callback)

const set = SuperSet.of('foo', 'bar')
const value = set.find(v => v.startsWith('f'))
console.log(value) // foo
onst set = SuperSet.empty()
const value = set.find(v => v.startsWith('f'))
console.log(value) // undefined

SuperSet.some(callback)

const set = SuperSet.of('foo', 'bar')
console.log(set.some(v => v.startsWith('f'))) // true
const set = SuperSet.empty()
console.log(set.some(v => v.startsWith('f'))) // false

SuperSet.every(callback)

const set = SuperSet.of('foo', 'bar')
console.log(set.every(v => v.length === 3)) // true
const set = SuperSet.of('foo', 'bar')
console.log(set.every(v => v.startsWith('f'))) // false

SuperSet.isEmpty()

const set = SuperSet.of('foo', 'bar')
console.log(set.isEmpty()) // false
const set = SuperSet.empty()
console.log(set.isEmpty()) // true

SuperSet.isNotEmpty()

const set = SuperSet.of('foo', 'bar')
console.log(set.isNotEmpty()) // true
const set = SuperSet.empty()
console.log(set.isNotEmpty()) // false

SuperSet.toArray()

const set = SuperSet.of('foo', 'bar')
const values = set.toArray()
console.log(values) // [ 'foo', 'bar' ]

SuperSet.toSet()

const superSet = SuperSet.of('foo', 'bar')
const set = superSet.toSet()
console.log(set) // { 'foo', 'bar' }

FAQs

Package last updated on 27 Jul 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts