forked from sashin/sashinexists
run npm install to generate a package lock
This commit is contained in:
81
node_modules/watcher/dist/lazy_map_set.js
generated
vendored
Normal file
81
node_modules/watcher/dist/lazy_map_set.js
generated
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
/* IMPORT */
|
||||
import Utils from './utils.js';
|
||||
/* MAIN */
|
||||
//TODO: Maybe publish this as a standalone module
|
||||
class LazyMapSet {
|
||||
constructor() {
|
||||
/* VARIABLES */
|
||||
this.map = new Map();
|
||||
}
|
||||
/* API */
|
||||
clear() {
|
||||
this.map.clear();
|
||||
}
|
||||
delete(key, value) {
|
||||
if (Utils.lang.isUndefined(value)) {
|
||||
return this.map.delete(key);
|
||||
}
|
||||
else if (this.map.has(key)) {
|
||||
const values = this.map.get(key);
|
||||
if (Utils.lang.isSet(values)) {
|
||||
const deleted = values.delete(value);
|
||||
if (!values.size) {
|
||||
this.map.delete(key);
|
||||
}
|
||||
return deleted;
|
||||
}
|
||||
else if (values === value) {
|
||||
this.map.delete(key);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
find(key, iterator) {
|
||||
if (this.map.has(key)) {
|
||||
const values = this.map.get(key);
|
||||
if (Utils.lang.isSet(values)) {
|
||||
return Array.from(values).find(iterator);
|
||||
}
|
||||
else if (iterator(values)) { //TSC
|
||||
return values;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
get(key) {
|
||||
return this.map.get(key);
|
||||
}
|
||||
has(key, value) {
|
||||
if (Utils.lang.isUndefined(value)) {
|
||||
return this.map.has(key);
|
||||
}
|
||||
else if (this.map.has(key)) {
|
||||
const values = this.map.get(key);
|
||||
if (Utils.lang.isSet(values)) {
|
||||
return values.has(value);
|
||||
}
|
||||
else {
|
||||
return (values === value);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
set(key, value) {
|
||||
if (this.map.has(key)) {
|
||||
const values = this.map.get(key);
|
||||
if (Utils.lang.isSet(values)) {
|
||||
values.add(value);
|
||||
}
|
||||
else if (values !== value) {
|
||||
this.map.set(key, new Set([values, value])); //TSC
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.map.set(key, value);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
/* EXPORT */
|
||||
export default LazyMapSet;
|
||||
Reference in New Issue
Block a user