-
Notifications
You must be signed in to change notification settings - Fork 0
/
packagedata.js
71 lines (51 loc) · 1.55 KB
/
packagedata.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
/*
LiveG APT Repository
Copyright (C) LiveG. All Rights Reserved.
https://opensource.liveg.tech/liveg-apt
Licensed by the LiveG Open-Source Licence, which can be found at LICENCE.md.
*/
export var packages = [];
export var loaded = false;
export function parsePackageData(text) {
var lastProperty = null;
var currentPackage = {};
var parsedPackages = [];
text.split("\n").forEach(function(line) {
if (line.trim().startsWith("#")) {
return;
}
var match = line.match(/^([\w].*?):(.*)$/);
if (match) {
var property = match[1];
if (property == "Package" && lastProperty != null) {
parsedPackages.push(currentPackage);
currentPackage = {};
}
currentPackage[property] = match[2].trim();
lastProperty = property;
return;
}
if (lastProperty == null) {
return;
}
if (line.trim() == ".") {
currentPackage[lastProperty] += "\n";
return;
}
currentPackage[lastProperty] += "\n" + line.trim();
});
parsedPackages.push(currentPackage);
return parsedPackages;
}
export function load(force = false) {
if (loaded && !force) {
return Promise.resolve(packages);
}
return fetch("Packages").then(function(response) {
return response.text();
}).then(function(text) {
packages = parsePackageData(text);
loaded = true;
return Promise.resolve(packages);
});
}