# generaltranslation: General Translation Core SDK: formatListToParts URL: https://generaltranslation.com/en-US/docs/core/functions/formatting/format-list-to-parts.mdx --- title: formatListToParts description: Standalone function to format lists into parts while preserving original types --- ## Overview The standalone `formatListToParts` function formats an array into locale-specific parts without requiring a GT instance. It inserts string separators between items while preserving the original types of each element, returning an `Array`. ```typescript import { formatListToParts } from 'generaltranslation'; const parts = formatListToParts(['red', 'green', 'blue'], { locales: ['es'], type: 'disjunction' }); // Returns: ['red', ', ', 'green', ' o ', 'blue'] ``` ## Reference ### Parameters | Name | Type | Description | |------|------|-------------| | `array` | `Array` | The array of items to format | | `options` | `ListFormatPartsOptions & { locales: string \| string[] }` | Formatting configuration with required locales | ### ListFormatPartsOptions | Name | Type | Description | |------|------|-------------| | `locales` | `string \| string[]` | **Required** - Locales for formatting | | `type?` | `'conjunction' \| 'disjunction' \| 'unit'` | List formatting type (default: `'conjunction'`) | | `style?` | `'long' \| 'short' \| 'narrow'` | List formatting style (default: `'long'`) | ### Returns `Array` - An array of the original items interleaved with locale-specific string separators. --- ## Example ### Basic usage ```typescript copy import { formatListToParts } from 'generaltranslation'; // Conjunction list console.log(formatListToParts(['A', 'B', 'C'], { locales: 'en' })); // Output: ['A', ', ', 'B', ', and ', 'C'] // Disjunction list console.log(formatListToParts(['A', 'B', 'C'], { locales: 'en', type: 'disjunction' })); // Output: ['A', ', ', 'B', ', or ', 'C'] ``` ### Mixed-type arrays ```typescript copy // Numbers and objects are preserved console.log(formatListToParts(['apple', 42, { type: 'fruit' }], { locales: 'en' })); // Output: ['apple', ', ', 42, ', and ', { type: 'fruit' }] ``` ### Locale-specific formatting ```typescript copy // Spanish disjunction console.log(formatListToParts(['red', 'green', 'blue'], { locales: 'es', type: 'disjunction' })); // Output: ['red', ', ', 'green', ' o ', 'blue'] // Short style console.log(formatListToParts(['first', 'second'], { locales: 'en', style: 'short' })); // Output: ['first', ' & ', 'second'] ``` --- ## Notes * Unlike the GT class method, the `locales` parameter is required * Original item types are preserved — only string separators are inserted between elements * This is the key differentiator from `formatList`, which returns a flat `string` * Particularly useful for rendering mixed-type arrays in UI frameworks like React * Uses the same underlying `Intl.ListFormat` as the GT class method ## Next steps * Check out [`Intl.ListFormat` documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat) for more options * See [`formatNum`](/docs/core/functions/formatting/format-num) for standalone number formatting * See [`formatDateTime`](/docs/core/functions/formatting/format-date-time) for standalone date formatting * See GT class [`formatListToParts`](/docs/core/class/methods/formatting/format-list-to-parts) for instance-based usage