rspack-chain
Version:
<p> <a href="https://npmjs.com/package/rspack-chain?activeTab=readme"> <img src="https://img.shields.io/npm/v/rspack-chain?style=flat-square&colorA=564341&colorB=EDED91" alt="npm version" /> </a> <a href="https://nodejs.org/en/about/previous-rele
58 lines (48 loc) • 979 B
JavaScript
module.exports = function createSet(superClass) {
return class extends superClass {
constructor(...args) {
super(...args);
this.store = new Set();
}
add(value) {
this.store.add(value);
return this;
}
prepend(value) {
this.store = new Set([value, ...this.store]);
return this;
}
clear() {
this.store.clear();
return this;
}
delete(value) {
this.store.delete(value);
return this;
}
values() {
return [...this.store];
}
has(value) {
return this.store.has(value);
}
merge(arr) {
if (arr !== undefined) {
this.store = new Set([...this.store, ...arr]);
}
return this;
}
when(
condition,
whenTruthy = Function.prototype,
whenFalsy = Function.prototype,
) {
if (condition) {
whenTruthy(this);
} else {
whenFalsy(this);
}
return this;
}
};
};