mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2026-12-01 12:16:08 -06:00
This patch refactors every single CommonJS default export and TypeScript `export =` to use named exports.
56 lines
1.7 KiB
TypeScript
56 lines
1.7 KiB
TypeScript
import _ from 'underscore';
|
|
const options = require('./options').options;
|
|
|
|
export class LibUtils {
|
|
private copyAndFilterLibraries(allLibraries, filter) {
|
|
const filterLibAndVersion = _.map(filter, (lib) => {
|
|
const match = lib.match(/([\w-]*)\.([\w-]*)/i);
|
|
if (match) {
|
|
return {
|
|
id: match[1],
|
|
version: match[2],
|
|
};
|
|
} else {
|
|
return {
|
|
id: lib,
|
|
version: false,
|
|
};
|
|
}
|
|
});
|
|
|
|
const filterLibIds = new Set();
|
|
_.each(filterLibAndVersion, (lib) => {
|
|
filterLibIds.add(lib.id);
|
|
});
|
|
|
|
const copiedLibraries = {};
|
|
_.each(allLibraries, (lib, libid) => {
|
|
if (!filterLibIds.has(libid)) return;
|
|
|
|
const libcopy = Object.assign({}, lib);
|
|
libcopy.versions = _.omit(lib.versions, (version, versionid) => {
|
|
for (const filter of filterLibAndVersion) {
|
|
if (filter.id === libid) {
|
|
if (!filter.version) return false;
|
|
if (filter.version === versionid) return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
});
|
|
|
|
copiedLibraries[libid] = libcopy;
|
|
});
|
|
|
|
return copiedLibraries;
|
|
}
|
|
|
|
public getSupportedLibraries(supportedLibrariesArr, langId) {
|
|
const allLibs = options.libs[langId];
|
|
if (supportedLibrariesArr && supportedLibrariesArr.length > 0) {
|
|
return this.copyAndFilterLibraries(allLibs, supportedLibrariesArr);
|
|
}
|
|
return allLibs;
|
|
}
|
|
}
|