flipchain
Version:
core chaining library, heavily based on [webpack-chain](https://github.com/mozilla-rpweb/webpack-chain)
78 lines (67 loc) • 1.16 kB
JavaScript
const Chainable = require('./Chainable')
/**
* @type {Set}
*/
class ChainedSet extends Chainable {
/**
* @param {any} parent
*/
constructor(parent) {
super(parent)
this.store = new Set()
}
/**
* @param {any} value
* @return {ChainedSet}
*/
add(value) {
this.store.add(value)
return this
}
/**
* @description inserts the value at the beginning of the Set
* @param {any} value
* @return {ChainedSet}
*/
prepend(value) {
this.store = new Set([value, ...this.store])
return this
}
/**
* @return {ChainedSet}
*/
clear() {
this.store.clear()
return this
}
/**
* @param {any} value
* @return {ChainedSet}
*/
delete(value) {
this.store.delete(value)
return this
}
/**
* @return {Array<any>}
*/
values() {
return [...this.store]
}
/**
* @param {any} value
* @return {boolean}
*/
has(value) {
return this.store.has(value)
}
/**
* @param {Array | Set} arr
* @return {ChainedSet}
*/
merge(arr) {
this.store = new Set([...this.store, ...arr])
return this
}
}
module.exports = ChainedSet