Skip to content

Commit

Permalink
fix: use host locale setting instead of static 'en' locale as default (
Browse files Browse the repository at this point in the history
  • Loading branch information
yobacca authored Nov 18, 2024
1 parent f04cd40 commit f62ca6f
Show file tree
Hide file tree
Showing 19 changed files with 429 additions and 452 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,17 +342,17 @@ Creates a compare function that defines the natural sort order and which may be
compare(options?: CompareOptions): CompareFn
```

| Type | Value |
| :--------------- | :----------------------------------------------------------- |
| `CompareOptions` | <code>{ order?: 'asc' &#124; 'desc', locale: string }</code> |
| `CompareFn` | <code>(valueA: unknown, valueB: unknown) => number</code> |
| Type | Value |
| :--------------- | :------------------------------------------------------------ |
| `CompareOptions` | <code>{ order?: 'asc' &#124; 'desc', locale?: string }</code> |
| `CompareFn` | <code>(valueA: unknown, valueB: unknown) => number</code> |

#### Description

`compare()` returns a compare function that defines the natural sort order and which may be passed to [`Array.prototype.sort()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort).

If `options` or its property `order` is unspecified, values are sorted in ascending sort order. Otherwise, specify an order of `'desc'` for descending or `'asc'` for ascending sort order of values.
If unicode strings should be ordered corresponding to a specific locale setting, specify the according value for the options property `locale`. It must be a string with a BCP 47 language tag.
If unicode strings should be ordered corresponding to a specific locale setting, specify the according value for the options property `locale`. It must be a string with a BCP 47 language tag. If the argument is unspecified, the host locale setting will be used.

#### Examples

Expand Down
10 changes: 5 additions & 5 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,17 +342,17 @@ Creates a compare function that defines the natural sort order and which may be
compare(options?: CompareOptions): CompareFn
```

| Type | Value |
| :--------------- | :----------------------------------------------------------- |
| `CompareOptions` | <code>{ order?: 'asc' &#124; 'desc', locale: string }</code> |
| `CompareFn` | <code>(valueA: unknown, valueB: unknown) => number</code> |
| Type | Value |
| :--------------- | :------------------------------------------------------------ |
| `CompareOptions` | <code>{ order?: 'asc' &#124; 'desc', locale?: string }</code> |
| `CompareFn` | <code>(valueA: unknown, valueB: unknown) => number</code> |

#### Description

`compare()` returns a compare function that defines the natural sort order and which may be passed to [`Array.prototype.sort()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort).

If `options` or its property `order` is unspecified, values are sorted in ascending sort order. Otherwise, specify an order of `'desc'` for descending or `'asc'` for ascending sort order of values.
If unicode strings should be ordered corresponding to a specific locale setting, specify the according value for the options property `locale`. It must be a string with a BCP 47 language tag.
If unicode strings should be ordered corresponding to a specific locale setting, specify the according value for the options property `locale`. It must be a string with a BCP 47 language tag. If the option is unspecified, the host locale setting will be used.

#### Examples

Expand Down
2 changes: 1 addition & 1 deletion src/compare/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { compare } from '../index';

const defaultOptions: CompareOptions = {
order: 'asc',
locale: 'en',
locale: undefined,
};

jest.mock('../../utils/baseCompare', () => ({
Expand Down
5 changes: 2 additions & 3 deletions src/orderBy/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ describe('orderBy()', () => {
const collection = ['Fred', 'barney', 'frank', 'Bob'];
const identifiers = undefined;
const orders = undefined;
const locale = undefined;

orderBy(collection, identifiers, orders, locale);
orderBy(collection, identifiers, orders);
expect(baseOrderBy).toHaveBeenCalledTimes(1);
expect(baseOrderBy).toHaveBeenCalledWith(collection, [], [], 'en');
expect(baseOrderBy).toHaveBeenCalledWith(collection, [], [], undefined);
});
it('should call baseOrderBy() with provided collection, identifiers, orders and locale arguments', () => {
const collection = ['Fred', 'barney', 'frank', 'Bob'];
Expand Down
2 changes: 1 addition & 1 deletion src/orderBy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function orderBy<T>(
collection: ReadonlyArray<T>,
identifiers?: ReadonlyArray<Identifier<T>> | Identifier<T> | null,
orders?: ReadonlyArray<Order> | Order | null,
locale: Locale = 'en',
locale?: Locale,
): Array<T> {
if (!collection || !Array.isArray(collection)) {
return [];
Expand Down
2 changes: 1 addition & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type CompareOptions =

export type BaseCompareOptions = {
order: Order;
locale: Locale;
locale?: Locale;
};

export type Locale = string;
Expand Down
Loading

0 comments on commit f62ca6f

Please sign in to comment.