@hint/hint-performance-budget
Version:
hint that that checks if a page passes a set performance budget
48 lines (47 loc) • 1.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ids = exports.getById = void 0;
const utils_fs_1 = require("@hint/utils-fs");
const parseConnection = (configText) => {
const lines = configText.split('\n');
const config = {
bwIn: 0,
bwOut: 0,
id: '',
label: '',
latency: 0,
plr: 0
};
const numerics = ['bwIn', 'bwOut', 'latency', 'plr'];
lines.forEach((line) => {
const [key, value] = line.trim().split('=');
if (key.startsWith('[')) {
config.id = key.replace(/[[\]]/g, '');
return;
}
config[key] = numerics.includes(key) ?
parseInt(value) :
value;
});
return config;
};
const getConnections = () => {
const configContent = (0, utils_fs_1.readFile)(`${__dirname}/connections.ini`);
const configsText = configContent
.replace(/#.*?\n/g, '')
.replace(/\r\n/g, '\n')
.split(`\n\n`);
const configs = configsText.map(parseConnection);
return configs;
};
const connections = getConnections();
const ids = connections.map((connection) => {
return connection.id;
}, []);
exports.ids = ids;
const getById = (id) => {
return connections.find((connection) => {
return connection.id === id;
}) || null;
};
exports.getById = getById;