# useCollator

## Usage

Returns the sanctioned locale-aware comparator for custom sorting. The collator is recreated when the provider locale or an option changes.

```ts
import { useCollator } from '@astryx-vue/core/locale'
```

```ts
const collator = useCollator({ numeric: true })

const sorted = computed(() => [...items.value].sort((a, b) => collator.value.compare(a, b)))
```

## Best practices

| Guidance | Practices |
| --- | --- |
| Do | Reuse `collator.value.compare` in custom Table comparators and other user-visible string ordering. |
| Don't | Construct `Intl.Collator` directly or call `localeCompare`; those bypass the provider-backed locale contract. |

## Parameters

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `options` | `MaybeRefOrGetter` | — | Optional collation behavior such as numeric ordering, sensitivity, punctuation handling, and case order. Pass a `ref` or a getter when the options can change; the collator is rebuilt when they do. |

## Returns

| Name | Type | Description |
| --- | --- | --- |
| `collator` | `ComputedRef` | A memoized collator bound to the active `InternationalizationProvider` locale. Read `collator.value` to compare. |
