Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Microsoft Playwright StringUtils

From Leeroopedia

Template:Implementation Page

Overview

StringUtils provides string manipulation utilities for escaping, formatting, case conversion, and selector-specific string operations used throughout Playwright.

Description

This module exports a collection of string utility functions:

  • escapeWithQuotes -- escapes a string for safe embedding within single, double, or backtick quotes
  • escapeTemplateString -- escapes characters special to template literals
  • isString -- type guard for string values
  • toTitleCase -- capitalizes the first letter
  • toSnakeCase -- converts camelCase to snake_case (e.g., ignoreHTTPSErrors to ignore_https_errors)
  • formatObject -- formats objects/arrays as readable strings
  • escapeForTextSelector -- escapes text for use in Playwright text selectors
  • escapeForAttributeSelector -- escapes text for use in attribute selectors

Usage

Used throughout the codebase for locator generation, code generation, and string formatting.

Code Reference

Source Location

packages/playwright-core/src/utils/isomorphic/stringUtils.ts (195 lines)

Function Signatures

export function escapeWithQuotes(text: string, char?: string): string;
export function escapeTemplateString(text: string): string;
export function isString(obj: any): obj is string;
export function toTitleCase(name: string): string;
export function toSnakeCase(name: string): string;
export function formatObject(value: any, indent?: string, mode?: 'multiline' | 'oneline'): string;
export function escapeForTextSelector(text: string, exact: boolean): string;
export function escapeForAttributeSelector(value: string, exact: boolean): string;

Import

import { escapeWithQuotes, toSnakeCase, isString } from '../utils/isomorphic/stringUtils';

I/O Contract

Key Behaviors

  • escapeWithQuotes('hello "world"', "'") returns 'hello "world"'
  • toSnakeCase('ignoreHTTPSErrors') returns 'ignore_https_errors'
  • isString works with both primitive strings and String objects

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment