feat: Add folder title matching and parsing (#2067)

This is a breaking change for users of the [experimental 'folder'
functionality](https://card.camera/#/configuration/folders).

Related: #1748
This commit is contained in:
Dermot Duffy
2025-05-27 07:50:51 -07:00
committed by GitHub
parent c4400194f5
commit c077f8bf70
35 changed files with 1038 additions and 378 deletions
+22
View File
@@ -0,0 +1,22 @@
/**
* Extracts a substring from a string using a regular expression pattern, if
* groupName / groupNumber is specified but not found in the result, the full
* match is returned.
*/
export const regexpExtract = (
pattern: string | RegExp,
val: string,
options?: {
groupName?: string;
groupNumber?: number;
},
): string | null => {
const match = val.match(pattern);
if (options?.groupName && match?.groups?.[options.groupName]) {
return match.groups[options.groupName];
}
if (options?.groupNumber !== undefined && match?.[options.groupNumber]) {
return match[options.groupNumber];
}
return match ? match[0] : null;
};