🕵🏼‍♀️ TPB, Mini-series, GN detection WIP

This commit is contained in:
2021-10-07 12:42:54 -07:00
parent 2a81bfcc2e
commit 478e105e48
4 changed files with 53 additions and 21 deletions

View File

@@ -1,13 +1,29 @@
import { compact } from "lodash";
import { flatten, compact, map, isEmpty } from "lodash";
export const detectTradePaperbacks = (deck): any => {
const paperback = [
/((trade)?\s?(paperback)|(tpb))/gim, // https://regex101.com/r/FhuowT/1
/(hard\s?cover)\s?(collect((ion)|(ed)|(ing)))/gim, //https://regex101.com/r/eFJVRM/1
export const detectIssueTypes = (deck: string): any => {
const issueTypeMatchers = [
{
regex: [
/((trade)?\s?(paperback)|(tpb))/gim, // https://regex101.com/r/FhuowT/1
/(hard\s?cover)\s?(collect((ion)|(ed)|(ing)))/gim, //https://regex101.com/r/eFJVRM/1
],
displayName: "Trade Paperback",
},
{ regex: [/mini\Wseries/gim], displayName: "Mini-Series" },
];
const miniSeries = [/mini\Wseries/gim];
const matches = paperback
const matches = map(issueTypeMatchers, (matcher) => {
return getIssueTypeDisplayName(deck, matcher.regex, matcher.displayName);
});
return compact(matches)[0];
};
const getIssueTypeDisplayName = (
deck: string,
regexPattern: RegExp[],
displayName: string,
) => {
const matches = [...regexPattern]
.map((regex) => {
return deck.match(regex);
})
@@ -16,6 +32,8 @@ export const detectTradePaperbacks = (deck): any => {
return item;
}
});
// console.log(compact(matches));
return compact(matches);
const results = flatten(compact(matches));
if (!isEmpty(results)) {
return { displayName, results };
}
};