4chan-XZ/src/classes/SimpleDict.ts
2023-05-07 18:13:05 +02:00

29 lines
496 B
TypeScript

export default class SimpleDict<T> {
keys: string[]
constructor() {
this.keys = []
}
push(key: string, data: T): T {
key = `${key}`
this[key] = data
this.keys.push(key)
return data
}
rm(key: string) {
key = `${key}`
delete this[key]
this.keys = this.keys.filter(k => k !== key)
}
forEach(fn: (value: T) => void): void {
for (const key of [...Array.from(this.keys)]) { fn(this[key]) }
}
get(key: string): T {
return this[key]
}
}