This package has been deprecated

Author message:

This package have a name which does not describe its usage. Please use the new and actively maintained package at @jitesoft/group-by.

@jitesoft/order-by

1.0.3 • Public • Published

Order By

Simple method to order an array by a given key in the array. The method uses a callback function to choose the value to order the items by and returns an object which have all the ordered values in an array under the given key name.

Example:

import orderBy from '@jitesoft/order-by';

let array = [ { "id": "abc", "value": "abc" },
              { "id": "abc", "value": "def" },
              { "id": "abc", "value": "ghi" },
              { "id": "def", "value": "abc" },
              { "id": "def", "value": "def" },
              { "id": "ghi", "value": "abc" } ];

let result = orderBy(array, (obj) => obj.id);

// Output:
let obj = {
       abc: [
         { "id": "abc", "value": "abc" },
         { "id": "abc", "value": "def" },
         { "id": "abc", "value": "ghi" }
       ],
       def: [
         { "id": "def", "value": "abc" },
         { "id": "def", "value": "def" }
       ],
       ghi: [
         { "id": "ghi", "value": "abc" }
       ]
};

Package Sidebar

Install

npm i @jitesoft/order-by

Weekly Downloads

1

Version

1.0.3

License

MIT

Unpacked Size

3.17 kB

Total Files

4

Last publish

Collaborators

  • jitesoft~
  • johannestegner