funkyarray in package and in project???
This commit is contained in:
parent
1d9e0d1dd2
commit
5e8285ebf7
3 changed files with 2 additions and 79 deletions
|
@ -27,7 +27,7 @@ import FastifyFormBody from "@fastify/formbody";
|
|||
import FastifyCookie from "@fastify/cookie";
|
||||
import FastifyView from "@fastify/view";
|
||||
import EJS from "ejs";
|
||||
import FunkyArray from "./objects/FunkyArray";
|
||||
import FunkyArray from "funky-array";
|
||||
import RemoteUser from "./objects/RemoteUser";
|
||||
import { MessageType } from "./enums/MessageType";
|
||||
import Database from "./objects/Database";
|
||||
|
|
|
@ -1,77 +0,0 @@
|
|||
export default class FunkyArray<T, TT> {
|
||||
private items:Map<T, TT> = new Map<T, TT>();
|
||||
private itemKeys:Array<T> = new Array<T>();
|
||||
|
||||
private _getKeys() : Array<T> {
|
||||
const keyArray = new Array<T>();
|
||||
let result:IteratorResult<T, T>;
|
||||
const iterator = this.items.keys();
|
||||
while (!(result = iterator.next()).done) {
|
||||
keyArray.push(result.value);
|
||||
}
|
||||
return keyArray;
|
||||
}
|
||||
|
||||
public set(key:T, item:TT, regenerate:boolean = true) : TT {
|
||||
this.items.set(key, item);
|
||||
if (regenerate) {
|
||||
this.itemKeys = this._getKeys();
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
public remove(key:T, regenerate:boolean = true) {
|
||||
const success = this.items.delete(key);
|
||||
if (regenerate) {
|
||||
this.itemKeys = this._getKeys();
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
public removeFirst(regenerate:boolean = true) {
|
||||
const success = this.items.delete(this.items.keys().next().value);
|
||||
if (regenerate) {
|
||||
this.itemKeys = this._getKeys();
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
public first() : TT {
|
||||
return this.items.values().next().value;
|
||||
}
|
||||
|
||||
public get length() : number {
|
||||
return this.items.size;
|
||||
}
|
||||
|
||||
public get(key:T) : TT | undefined {
|
||||
return this.items.get(key);
|
||||
}
|
||||
|
||||
public has(key:T) : boolean {
|
||||
return this.itemKeys.includes(key);
|
||||
}
|
||||
|
||||
public get keys() : Array<T> {
|
||||
return this.itemKeys;
|
||||
}
|
||||
|
||||
public forEach(callback: (value:TT) => void) {
|
||||
return new Promise<boolean>(async (resolve, reject) => {
|
||||
if (this.items.size === 0) {
|
||||
return resolve(true);
|
||||
}
|
||||
|
||||
try {
|
||||
const iterator = this.items.values();
|
||||
let result:IteratorResult<TT, TT>;
|
||||
while (!(result = iterator.next()).done) {
|
||||
await callback(result.value);
|
||||
}
|
||||
resolve(true);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@ import Config from "./Config";
|
|||
import FastifyCookie from "@fastify/cookie";
|
||||
import FunkyArray from "funky-array";
|
||||
import SessionUser from "./SessionUser";
|
||||
import { FastifyReply, FastifyRequest } from "fastify";
|
||||
import { FastifyReply } from "fastify";
|
||||
import User from "../entities/User";
|
||||
import { randomBytes } from "crypto";
|
||||
import Gauge from "simple-prom/lib/objects/Gauge";
|
||||
|
|
Loading…
Reference in a new issue