New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

sort-object-array

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sort-object-array

A tiny library to sort array of objects based on multiple properties

latest
Source
npmnpm
Version
1.0.1
Version published
Weekly downloads
22
57.14%
Maintainers
1
Weekly downloads
 
Created
Source

sort Build Status

A tiny library to sort array of objects based on multiple properties.
Ultra small, just 0.50KB [minified+gzipped] and 2.25KB [uncompressed source].

Getting Started

If you are using npm

$ npm install --save sort-object-array

or include index.js manually as

<script src="index.js" charset="utf-8"></script>

Usage

const sort = require('objectarray-sort');

sort([{a:{b:2}},{a:{b:6}},{a:{b:1}}], 'a.b');

sort(test, ['a.b', 'a.c.d', 'a.e.f.g'], ['desc', 'asc', 'desc']);

For browser environments, the library exports a global arraySort, which can be used in a similar fashion,

arraySort(test, ['a.b', 'a.c', 'a.d'], ['desc', 'asc', 'desc']);
// returns the sorted 'test' array

API

sort(array, sortBy, [order])

Sorts and returns an array.

array

Type: Array
Default: none

Array to be sorted

sortBy

Type: String | Array
Default: none

The property against which sorting is to be performed. A single string value or array of strings.
If an array is passed, the priority of sort is in decreases from left to right.
Say, if you pass ['a.b', 'a.c'] as the argument, the function will sort the array based on 'a.b' first, then for same values of 'a.b', it will sort those values by 'a.c' and so on.
By default, all orders are ascending. For changing order, see order.

order

Type: String | Array
Default: 'asc'

The order which sorting is to be performed. A single string value or array of strings. Values are 'asc' or 'desc'.
If it is an array, it maps one to one to the arguments of sortBy.
In the example sort(test, ['a.b', 'a.c.d', 'a.e.f.g'], ['desc', 'asc', 'desc']), 'a.b' is sorted in descending order, 'a.c.d' in ascending order and 'a.e.f.g' in descending order.

Defaults to 'asc'.

Keywords

array

FAQs

Package last updated on 21 Oct 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts