This repository has been archived by the owner on Nov 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.js
71 lines (69 loc) · 1.73 KB
/
init.js
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
67
68
69
70
71
export const Json = new class {
/** 以避免报错形式解析Json。*/
parse(data) {
let rdata
try {
rdata = JSON.parse(data)
} catch (error) {
// console.log("JSON已解析,直接跳过")
rdata = data
}
return rdata
}
/** 如果格式为string,将原样输出。 */
stringify(data) {
if (typeof data == "string") return data
return JSON.stringify(data)
}
}
export const JtC = (c, j) => {
for (const k in j) {
if (c.hasOwnProperty(k)) {
c[k] = j[k]
}
}
return c
}
export class RunList {
time = 500
#list = []
Push(callback) {
this.#list.push(callback)
if (this.#list.length === 1) this.Run()
}
Run() {
if (this.#list.length !== 0) {
this.#list[0]()
setTimeout(() => {
this.#list.splice(0, 1)
this.Run()
}, this.time)
}
}
}
export class RList{
time = 500
#list = -1
snooze = ms => new Promise(resolve => setTimeout(resolve, ms))
async Push(){
this.#list++
await this.snooze(this.#list*this.time)
Promise.resolve().finally(()=>{
setTimeout(()=>{this.#list--},(this.#list+1)*this.time)
})
}
}
export const returnFileType = (file="") => {
let f = file.split(".")
if (f.length > 2) {
let name = f[0]
for (let i = 1; i < f.length - 1; i++) {
name += "." + f[i]
}
return { name, type: f[f.length - 1] }
}
else return { name: f[0], type: f.length === 1 ? "" : f[1] }
}
export const randomizator = (a = 0, b = 0) => {
return Math.floor(Math.random() * b) + a
}