gpt-4.1-2025-04-14· OpenAI LMArena Human Preference 140K
generate a JSDOC: const hasClass = async (locator, classNameOrPattern) => { const…
- User
generate a JSDOC: const hasClass = async (locator, classNameOrPattern) => { const classAttribute = await locator.getAttribute('class');
return classAttribute?.split(' ').some(cls => classNameOrPattern instanceof RegExp ? classNameOrPattern.test(cls) : cls === classNameOrPattern ) ?? false; };
- Assistant
Certainly! Here’s a JSDoc comment for your function:
/** * Checks if the element located by `locator` has a class matching the given string or RegExp pattern. * * @async * @param {Object} locator - An object representing the element locator, expected to have a `getAttribute` method. * @param {string|RegExp} classNameOrPattern - The class name to match (exact string) or a RegExp pattern to test against each class. * @returns {Promise<boolean>} Resolves to `true` if a matching class is found, otherwise `false`. * * @example * // Exact string match * await hasClass(locator, 'active'); // true or false * * // RegExp match * await hasClass(locator, /^btn-/); // true if any class starts with 'btn-' */ const hasClass = async (locator, classNameOrPattern) => { const classAttribute = await locator.getAttribute('class'); return classAttribute?.split(' ').some(cls => classNameOrPattern instanceof RegExp ? classNameOrPattern.test(cls) : cls === classNameOrPattern ) ?? false; };Let me know if you want the types to be more specific (e.g., for Playwright or Selenium locators)!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.