or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

component-utilities.mdcss-utilities.mddom-utilities.mdindex.mdobject-function-utilities.mdproptype-validators.mdreact-hooks.mdslot-props-utilities.mdstring-utilities.md

string-utilities.mddocs/

0

# String and Text Utilities

1

2

Text manipulation and formatting utilities for user interface content. These utilities handle common string operations needed in React applications.

3

4

## Capabilities

5

6

### Text Formatting

7

8

#### capitalize

9

10

Capitalizes the first letter of a string while preserving the rest of the string.

11

12

```typescript { .api }

13

/**

14

* Capitalizes first letter of string

15

* @param string - String to capitalize

16

* @returns String with first letter capitalized

17

*/

18

function unstable_capitalize(string: string): string;

19

```

20

21

**Usage Example:**

22

23

```typescript

24

import { unstable_capitalize as capitalize } from '@mui/utils';

25

26

const capitalized = capitalize('hello world'); // "Hello world"

27

const alreadyCapitalized = capitalize('Hello World'); // "Hello World"

28

const empty = capitalize(''); // ""

29

const singleChar = capitalize('a'); // "A"

30

31

// Usage in component

32

function UserGreeting({ name }) {

33

return <h1>Hello, {capitalize(name)}!</h1>;

34

}

35

```

36

37

### Error Message Formatting

38

39

#### formatMuiErrorMessage

40

41

Formats MUI error messages with error codes for production builds.

42

43

```typescript { .api }

44

/**

45

* Formats MUI error messages with codes

46

* @param code - Error code number

47

* @param args - Additional arguments for error message

48

* @returns Formatted error message string

49

*/

50

function formatMuiErrorMessage(code: number, ...args: any[]): string;

51

```

52

53

**Usage Example:**

54

55

```typescript

56

import { formatMuiErrorMessage } from '@mui/utils';

57

58

// In development: returns full error message

59

// In production: returns formatted message with error code

60

const errorMessage = formatMuiErrorMessage(123, 'ComponentName', 'propName');

61

62

// Usage in component validation

63

function validateProps(props) {

64

if (!props.required) {

65

throw new Error(formatMuiErrorMessage(456, 'MyComponent', 'required'));

66

}

67

}

68

```