Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xico2k/multi-sort
This package allows you to sort a multi dimensional array easily.
https://github.com/xico2k/multi-sort
array javascript multidimensional objects sort
Last synced: about 1 month ago
JSON representation
This package allows you to sort a multi dimensional array easily.
- Host: GitHub
- URL: https://github.com/xico2k/multi-sort
- Owner: xiCO2k
- License: mit
- Created: 2017-10-02T11:35:48.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T22:07:47.000Z (almost 2 years ago)
- Last Synced: 2024-09-22T16:09:07.722Z (about 2 months ago)
- Topics: array, javascript, multidimensional, objects, sort
- Language: TypeScript
- Homepage:
- Size: 1.07 MB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
MultiSort
This package allows you to sort a multi dimensional array easily.## Installation
With [npm](https://www.npmjs.com):
```sh
$ npm i multi-sort
```
or with [yarn](https://yarnpkg.com):
```sh
$ yarn add multi-sort
```## Usage
There are multiple ways to use this package, check the example bellow:
```js
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`:
```js
const sortedByFirstName = MultiSort(arr, 'first_name', 'ASC');
```With arguments providing an array of object `keys` and `directions`:
```js
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`:```js
const sortedByFirstAndLast = MultiSort(arr, {
first_name: 'ASC',
last_name: 'DESC',
});
```MultiSort is an open-sourced software licensed under the **[MIT license](https://opensource.org/licenses/MIT)**.