-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathangellib.ts
66 lines (49 loc) · 1.76 KB
/
angellib.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import http from "http";
export const ShinoaScript_VERSION = "beta 0.1.2";
export const Months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
export function GetDate(date : any, tzString : any = "Asia/Seoul") {
return new Date((typeof date === "string" ? new Date(date) : date).toLocaleString("en-US", { timeZone: tzString }));
}
export async function ReadRawPost(request : http.IncomingMessage) {
const buffers = [];
for await (const chunk of request) {
buffers.push(chunk);
}
const data = Buffer.concat(buffers).toString();
return data;
}
export async function ReadPostJSON(request : http.IncomingMessage) {
const jsonData = JSON.parse(await ReadRawPost(request));
return jsonData;
}
export function ReplaceAll(str : any, thingtoreplace : any, replacement : any) : string {
let f = str;
while (f.includes(thingtoreplace)) {
f = f.replace(thingtoreplace, replacement);
}
return f;
}
export const ParseCookie = (str : any) =>
str
.split(';')
.map((v : any) => v.split('='))
.reduce((acc : any, v : any) => {
acc[decodeURIComponent(v[0].trim())] = decodeURIComponent(v[1].trim());
return acc;
}, {});
export function RemoveExecutable(thing : string) {
//return thing.replace(/</g, "<").replace(/>/g, ">");
return ReplaceAll(ReplaceAll(thing,"<", "<"),">",">");
}
import fs from "fs";
export class Database {
public bank : any;
public loc : any;
public constructor(location : string) {
this.bank = require("./dbs/" + location);
this.loc = location;
}
public Save() {
fs.writeFileSync("./dbs/" + this.loc, JSON.stringify(this.bank));
}
}