Skip to content

This package allows you to sort a multi dimensional array easily.

License

Notifications You must be signed in to change notification settings

xiCO2k/multi-sort

Repository files navigation

MultiSort

GitHub Workflow Status (master) Total Downloads License

This package allows you to sort a multi dimensional array easily.

Installation

With npm:

$ npm i multi-sort

or with yarn:

$ yarn add multi-sort

Usage

There are multiple ways to use this package, check the example bellow:

import MultiSort from 'multi-sort';

const arr = [
    { first_name: 'John', last_name: 'Doe' },
    { first_name: 'Anthony', last_name: 'Zipher' },
    { first_name: 'Anthony', last_name: 'Carlos' },
];

With arguments providing the object key and the direction:

const sortedByFirstName = MultiSort(arr, 'first_name', 'ASC');

With arguments providing an array of object keys and directions:

const sortedByFirstAndLast = MultiSort(
    arr,
    ['first_name', 'last_name'],
    ['ASC', 'DESC']
);

Or, With an Object where the key represents the object key on the array provided and the value represents the direction:

const sortedByFirstAndLast = MultiSort(arr, {
    first_name: 'ASC',
    last_name: 'DESC',
});

MultiSort is an open-sourced software licensed under the MIT license.