Is there a way to use the selector parameter inside an arrow function for an if statement without receiving an error stating that the selector is not defined?
static async valuesToArray(selector: string): Promise<void> {
const data: (string | Date)[] = await page.$$eval(selector, cells =>
cells.map(cell => {
if (selector === contractsPo.contractDateCol) {
return new Date(
cell.textContent!.replace(/(\d{2}).(\d{2}).(\d{4})/, '$2/$1/$3'),
);
} else {
return cell.textContent!;
}
}),
);
}
page.$$eval
([aria-colindex="2"])
— 59ms
Evaluation failed: ReferenceError: selector is not defined
at eval (eval at evaluate (:303:29), <anonymous>:2:13)
at Array.map (<anonymous>)
at eval (eval at evaluate (:303:29), <anonymous>:1:16)
at UtilityScript.evaluate (<anonymous>:305:22)
at UtilityScript.<anonymous> (<anonymous>:1:44)