Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fast-sort

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-sort

Blazing fast array sorting.

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
86K
increased by2.72%
Maintainers
1
Weekly downloads
 
Created
Source

fast-sort

Build Status Code quality Codacy Badge Open Source Love MIT Licence

NPM Package

Blazing fast array sorting. ~2x faster than lodash sort. Benchmark results coming soon.

fast-sort is part of js-flock library exported as single module. For source code and bug/issue reporting visit js-flock github page.

Usage

Small wrapper around sort to make sorting more readable and easier to write.

  • Undefined and null values are always sorted to bottom of list no matter if ordering is ascending or descending.
  • Supports sorting by multiple properties
  • Mutates input array in a same way as native Array.prototype.sort().
  import sort from 'fast-sort';

  sort([1,4,2]).asc(); // sort array in ascending order [1, 2, 4]
  sort([1,4,2]).desc(); // sort array in descending order [4, 2, 1]

  // Sort persons [Object] ascending by lowercase firstName
  sort(persons).asc((p) => p.firstName.toLowerCase());

  // Sort persons by multiple properties
  sort(persons).desc([
    (p) => p.firstName, // Sort by first name
    (p) => p.lastName, // Persons that have same firstName will be sorted by lastName
    (p) => p.dob // Persons that have same firstName and lastName will be sorted by dob
  ]);

  // Sorting values that are not sortable will return same value back
  sort(null).asc(); // => null
  sort(33).desc(); // => 33

Including module

  // npm install fast-sort --save
  import sort from 'fast-sort'; // Loads unmodified es6 code
  import sort from 'fast-sort/sort.es5'; // Loads transpiled es5 code
  import sort from 'fast-sort/sort.es5.min'; // Loads transpiled minified es5 code


  // We can import same module through js-flock library

  // npm install js-flock --save
  import sort from 'js-flock/sort'; // === import sort from 'fast-sort';
  import sort from 'js-flock/es5/sort'; // === import sort from 'fast-sort/sort.es5';
  import sort from 'js-flock/es5/sort.min'; // === import sort from 'fast-sort/sort.es5.min';

Keywords

FAQs

Package last updated on 09 Aug 2017

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc