nhb-toolbox
Version:
A versatile collection of smart, efficient, and reusable utility functions, classes and types for everyday development needs.
40 lines (39 loc) • 1.78 kB
TypeScript
import type { GenericObject } from '../object/types';
import type { BasicPrimitive } from '../types/index';
import type { OrderOption, SortByOption, SortNature } from './types';
/**
* Compare two strings using natural sorting (e.g., `"file2"` < `"file10"`).
* - Optionally supports case-insensitive and locale-aware string chunk comparisons.
*
* @param a - The first string to compare.
* @param b - The second string to compare.
* @param options - Optional settings to configure comparison behavior.
* @returns A negative number if `a` comes before `b`, a positive number if `a` comes after `b`, or 0 if equal.
*/
export declare function naturalSort(a: string, b: string, options?: SortNature): number;
/**
* * Sorts an array of objects based on the provided options.
*
* @remarks
* - Sorts array by the specified field in the options `sortByField`.
* - Uses {@link naturalSort} for sorting string values.
*
* @param array - The array of objects to sort.
* @param options - Sorting options for objects.
* @returns The sorted array.
*/
export declare function sortAnArray<T extends GenericObject>(array: T[], options: SortByOption<T>): T[];
/**
* * Sorts an array of `strings`, `numbers` or `boolean` based on the provided options.
*
* @remarks
* - If the array contains strings, it sorts them alphabetically.
* - If the array contains numbers, it sorts them numerically.
* - If the array contains booleans, it sorts them by their boolean value.
* - Uses {@link naturalSort} for sorting string values.
*
* @param array - The array of `strings`, `numbers` or `boolean` to sort.
* @param options - Sorting options.
* @returns The sorted array.
*/
export declare function sortAnArray<T extends BasicPrimitive>(array: T[], options?: OrderOption): T[];