import { Meta, Source } from '@storybook/addon-docs/blocks'

<Meta title='@dxtmisha/en/functional-basic/Functions/anyToString - Conversion of a value to a string'/>

# `anyToString`

A utility for safely converting any input data into a string type.

**Parameters:**
- `value: V` — The value for conversion.
- `isArrayString: boolean = true` — If `true`, primitive arrays are joined by commas.
- `trim: boolean = true` — If `true`, trims leading and trailing whitespace (only for strings).

**Conversion Rules:**
- **Strings**: Returned as is (with `trim` if enabled).
- **Arrays**: If `isArrayString: true` and no objects are in the array, elements are joined by commas. Otherwise, JSON stringified.
- **Objects**: Converted to JSON. In case of error (e.g., circular reference), returns standard `toString()`.
- **Boolean**: `true` converts to `'1'`, `false` to `'0'`.
- **Other types**: `null` and `undefined` result in an empty string. Others call `toString()`.

**Returns:**
`string` — The string representation of the value.

## Examples

<Source
  language='typescript'
  code={`
import { anyToString } from '@dxtmisha/functional-basic'

// 1. Strings
anyToString('  Hello  ')               // 'Hello'
anyToString('  Hello  ', true, false)  // '  Hello  '

// 2. Arrays
anyToString([1, 2, 3])                 // '1,2,3'
anyToString([1, 2, 3], false)          // '[1,2,3]'

// 3. Objects
anyToString({ a: 1 })                  // '{"a":1}'

// 4. Boolean values (1/0 conversion)
anyToString(true)                      // '1'
anyToString(false)                     // '0'

// 5. Empty values and types
anyToString(null)                      // ''
anyToString(123)                       // '123'
anyToString(Symbol('test'))            // 'Symbol(test)'
  `}
/>
