forked from steven4547466/Rovird-Website
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
49 lines (42 loc) · 1.12 KB
/
Copy pathutils.js
File metadata and controls
49 lines (42 loc) · 1.12 KB
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
const https = require("https")
function bufferToString(buffer) {
if (buffer instanceof ArrayBuffer) { buffer = new Uint8Array(buffer) }
const result = []
for (let i = 0; i < buffer.length; i += 0x8000) {
result.push(String.fromCharCode.apply(null, buffer.subarray(i, i + 0x8000)))
}
return result.join("")
}
function resolveLine(str) {
return str.replace(/\\(\d+)/g, (match, g1) => {
return String.fromCharCode(g1)
})
}
function countSpacesInARow(str) {
let lastChar = ""
let maxInRow = 0
let inRow = 1
for (let char of str) {
if (lastChar == " " && char == " ") {
inRow++
} else {
if (inRow > maxInRow) {
maxInRow = inRow
inRow = 1
}
}
lastChar = char
}
if (inRow > maxInRow) {
maxInRow = inRow
}
return maxInRow >= 8 ? maxInRow : 0
}
function validateAsset(id) {
return new Promise((resolve, reject) => {
https.get(`https://www.roblox.com/library/${id}`, (res) => {
resolve(res.statusCode >= 200 && res.statusCode < 400)
}).on("error", reject)
})
}
module.exports = { bufferToString, resolveLine, countSpacesInARow, validateAsset }