JSPM

  • Created
  • Published
  • Downloads 7
  • Score
    100M100P100Q57548F
  • License ISC

Sort an array by its property

Package Exports

  • property-sort

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (property-sort) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Property Sort

npm

property-sort provides a method that lets you setup sorting in alphabetical, numerical ordering and more. No more hassle sorting your arrays.

Getting started

Install the package...

npm install property-sort

Usage

Plain TypeScript:

import sortByProperty, { SortDirections, SortOptions, SortObject } from 'property-sort';
import LanguageCode from 'language-code';

...
let collection: SortObject<item>[] = ...;
let options: SortOptions = {
  direction: SortDirections.Ascending,
  sortKey: ['adress', 'suite'],
  locale: LanguageCode.en,
  numeric: true
};

collection = sortByProperty(collection, options);

Properties

sortByProperty (method):

sortByProperty(collection: SortObject<UnknownObject[]>, options: SortOptions): any[]
Property Type Description
collection array array to sort
options SortOptions options on sorting

SortOptions (interface):

Property Type Description
sortKey string or string[] array to sort
direction SortDirection Sets sort to ascending/descending order
locale LanguageCode Enum for locale coe (ISO 639-1)
numeric boolean Used when comparing strings using numeric values

SortDirection (interface)

Key Value Description
None 0 Used to reset sorting
Ascending 1 Used to sort in ascending order
Descending 2 Used to sort in descending order