feat: enhanced lookup behaviour (#270)

Co-authored-by: Jef LeCompte <jeffreylec@gmail.com>
This commit is contained in:
Andrew Mackrodt
2020-09-25 23:29:10 +01:00
committed by GitHub
parent 7ef9d935c6
commit b868d1a483
17 changed files with 789 additions and 71 deletions
+48
View File
@@ -0,0 +1,48 @@
export interface Card {
brand: string;
model: string;
}
export function parseCard(name: string): Card | null {
name = name.replace(/[^\w ]+/g, '').trim();
name = name.replace(/\bgraphics card\b/gi, '').trim();
name = name.replace(/\b\w+ fan\b/gi, '').trim();
name = name.replace(/\s{2,}/g, ' ');
let model = name.split(' ');
const brand = model.shift();
if (!brand) {
return null;
}
// Some vendors have oc at the beginning of the product name,
// store whether the card contains the term "oc" and remove
// it during filtering, then add it to the end of the name.
let isOC = false;
/* eslint-disable @typescript-eslint/prefer-regexp-exec */
model = model.filter(word => {
if (word.toLowerCase() === 'oc') {
isOC = true;
return false;
}
return !word.match(/^(nvidia|geforce|rtx|amp[ae]re|graphics|card|gpu|pci-?e(xpress)?|ray-?tracing|ray|tracing|core|boost)$/i) &&
!word.match(/^(\d+(?:gb?|mhz)?|gb|mhz|g?ddr(\d+x?)?)$/i);
});
/* eslint-enable @typescript-eslint/prefer-regexp-exec */
if (isOC) {
model.push('OC');
}
if (model.length === 0) {
return null;
}
return {
brand: brand.toLowerCase(),
model: model.join(' ').toLowerCase().replace(/ gaming\b/g, '').trim()
};
}