renew ua's part 2

This commit is contained in:
Ray Lothian 2020-08-04 08:03:50 +02:00
parent 285f3722ca
commit a6c4a92ba8

View file

@ -21,6 +21,18 @@ const write = ({name, content}, callback) => fs.writeFile('./browsers/' + name,
console.log(name); console.log(name);
}); });
// reduce total number to < 400 entries
const reduce = (arr, length = 400) => {
let pos = 1;
while (arr.length > length) {
arr.splice(pos, 1);
pos += 1;
pos = pos % (arr.length - Math.round(length / 10));
}
return arr;
};
fs.readdir('./browsers/', async (err, files) => { fs.readdir('./browsers/', async (err, files) => {
if (err) throw err; if (err) throw err;
for (const file of files) { for (const file of files) {
@ -64,7 +76,8 @@ fs.readdir('./browsers/', async (err, files) => {
for (const browser of Object.keys(cache)) { for (const browser of Object.keys(cache)) {
for (const os of Object.keys(cache[browser])) { for (const os of Object.keys(cache[browser])) {
const name = browser + '-' + os.replace(/\//g, '-') + '.json'; const name = browser + '-' + os.replace(/\//g, '-') + '.json';
const content = JSON.stringify(cache[browser][os]); const uas = cache[browser][os];
const content = JSON.stringify(reduce(uas));
contents.push({ contents.push({
name, name,
content content