@types/sort-array
TypeScript icon, indicating that this package has built-in type declarations

4.1.2 • Public • Published

Installation

npm install --save @types/sort-array

Summary

This package contains type definitions for sort-array (https://github.com/75lb/sort-array#readme).

Details

Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/sort-array.

index.d.ts

type Primitive = number | string | boolean | bigint | symbol | null | undefined;
interface SortOptions<Computed> {
    /**
     * One or more property names or computed fields to sort by.
     * Specifying property names is only relevant when sorting an array of
     * objects.
     */
    by?: string | string[];
    /**
     * One or more sort orders. Specify 'asc', 'desc' or a property name from
     * the options.customOrders object.
     */
    order?: string | string[];
    /**
     * A dictionary object containing one or more custom orders. Each custom
     * order value must be an array defining the order expected values must be
     * sorted in.
     */
    customOrders?: {
        [key: string]: any;
    };
    /**
     * A dictionary object containing one or more computed field functions. The
     * function will be invoked once per item in the array. Each invocation
     * will receive the array item as input and must return a primitive value
     * by which the array can be sorted.
     */
    computed?: {
        [key: string]: (item: Computed) => Primitive;
    };
    /**
     * Configures whether null values will be sorted before or after defined
     * values. Set to -1 for before, 1 for after. Defaults to 1.
     * @default 1
     */
    nullRank?: -1 | 1;
    /**
     * Configures whether undefined values will be sorted before or after
     * defined values. Set to -1 for before, 1 for after. Defaults to 1.
     * @default 1
     */
    undefinedRank?: -1 | 1;
}

/**
 * Isomorphic, load-anywhere function to sort an array by scalar, deep or
 * computed values in any standard or custom order. Returns the array
 * passed in.
 * @param array The input array to sort. It is sorted in place.
 * @param options Sort options.
 */
declare function sortArray<T>(array: T[], options?: SortOptions<T>): T[];
export = sortArray;

Additional Details

  • Last updated: Tue, 07 Nov 2023 15:11:36 GMT
  • Dependencies: none

Credits

These definitions were written by mrmlnc.

Readme

Keywords

none

Package Sidebar

Install

npm i @types/sort-array

Weekly Downloads

2,360

Version

4.1.2

License

MIT

Unpacked Size

6.25 kB

Total Files

5

Last publish

Collaborators

  • types