UNPKG

playwright-elements

Version:
23 lines (22 loc) 992 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.buildPageObject = buildPageObject; const defaultSuffix = 'Page'; function buildPageObject(mod, options = { suffix: defaultSuffix, lowerCaseFirst: true }) { const { suffix = defaultSuffix, lowerCaseFirst = true } = options; // Initialize pages object with the correct type const pages = {}; Object.keys(mod).forEach((key) => { if (!suffix || key.endsWith(suffix)) { // Remove the suffix from the key to get the base property name - THIS SHOULD BE OPTIONAL const baseName = suffix ? key.slice(0, -suffix.length) : key; const propName = lowerCaseFirst ? baseName.charAt(0).toLowerCase() + baseName.slice(1) : baseName; if (typeof mod[key] === 'function' && /^class\s/.test(mod[key].toString())) { pages[propName] = new mod[key](); } } }); return { ...pages }; }