natural-sort
Sorting with support for numbers, dates, unicode and more.
Last updated 10 years ago by tomekwi .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install natural-sort 
SYNC missed versions from official npm registry.

David – status of dependencies Code style: airbnb

natural-sort.js

Sorting with support for numbers, dates, unicode and more.

 

Default features

  • Numbers are handled properly (“2” is before “10”)
  • Dates are detected and sorted as well
  • Empty strings are after “z”
 

Usage

['10. tenth', 'odd', 1, '', '2. second'].sort(naturalSort())
// [1, '2. second', '10. tenth', 'odd', '']

[3, 4, 1, 5, 2].sort(naturalSort({direction: 'desc'}))
// [5, 4, 3, 2, 1]

['a', 'B'].sort(naturalSort())
// ['a', 'B']
['a', 'B'].sort(naturalSort({caseSensitive: true}))
// ['B', 'a']
 

Installation

  1. Download the script. You can use npm or bower:
npm install natural-sort
bower install natural-sort
  1. Include the script before yours:
<script src="/bower_components/natural-sort/dist/natural-sort.js"></script>
 

Credits

The original version of this algorithm was published by Jim Palmer in this blog post.

 

License

MIT © Studio B12 GmbH

Current Tags

  • 1.0.0                                ...           latest (10 years ago)

2 Versions

  • 1.0.0                                ...           10 years ago
  • 0.1.0                                ...           11 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |