open-index/open-npm huggingface dataset:
npm package: @sigao/sort-factory
Description: This library is used for generating a sort function for array values. It can be used to sort on primitive array values as well as both object properties and sub-properties.
Latest version: 1.0.2

# SortFactory

This library is used for generating a sort function for array values. It can be used to sort on primitive array values as well as both object properties and sub-properties.


## Basic Usage

#### Primitive Sort
To do a basic ascending or descending sort on an array just call the `sortAscending()` or `sortDescending()` function. The output will be a sorted array based on your criteria. 

Ascending: `yourArray.sort(SortFactory.sortAscending());`

Descending: `yourArray.sort(SortFactory.sortDescending());`

#### Sort On An Object Property
To perform a sort on an object property use the `sortAscendingBy()` or `sortDescendingBy()` function. Simply pass the property name you want to sort on into the function.

Ascending: `yourArray.sort(SortFactory.sortAscendingBy('propName'));`

Descending: `yourArray.sort(SortFactory.sortDescendingBy('propName'));`

#### Sort On Nested Object Properties

You are also able to sort on nested properties. There is no limit to how many levels you are able to sort on.
For instance, both of the examples below are valid.

`yourArray.sort(SortFactory.sortAscendingBy('prop1.prop2'))`
`yourArray.sort(SortFactory.sortAscendingBy('prop1.prop2.prop3'))` 

#### Null Values

No errors will be thrown when sorting null values and you can expect null values to be at the beginning of the array when ascending and at the end of the array when descending. 


### Install the package

Run `npm install @sigao/sort-factory` 

## Powered By [Sigao](http://www.sigao.io/)

This package is designed to be used within our tech stack to support our development efforts.  While significant effort has been made to ensure that these packages are tested and maintained, mistakes happen, and there is a good possibility the bug won't be addressed unless it directly impacts our specific use case.   

If you encounter a bug that you'd like addressed, feel free to reach out to us and we'll see what we can do!