https://github.com/github/version_sorter
Fast sorting of version numbers
https://github.com/github/version_sorter
Last synced: 10 months ago
JSON representation
Fast sorting of version numbers
- Host: GitHub
- URL: https://github.com/github/version_sorter
- Owner: github
- License: mit
- Created: 2009-04-25T00:05:19.000Z (almost 17 years ago)
- Default Branch: master
- Last Pushed: 2024-04-02T17:38:10.000Z (almost 2 years ago)
- Last Synced: 2025-05-05T04:03:40.935Z (10 months ago)
- Language: C
- Homepage:
- Size: 706 KB
- Stars: 126
- Watchers: 319
- Forks: 34
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Version sorter
Fast sorting of strings representing version numbers.
```rb
require 'version_sorter'
versions = ["1.0.9", "2.0", "1.0.10", "1.0.3", "2.0.pre"]
VersionSorter.sort(versions)
#=> 1.0.3
#=> 1.0.9
#=> 1.0.10
#=> 2.0.pre
#=> 2.0
```
You can also sort arrays of arbitrary objects by providing a block.
```rb
VersionSorter.sort(tags) { |tag| tag.name }
```
Library API:
```rb
VersionSorter.sort(versions) #=> sorted array
VersionSorter.rsort(versions) #=> reverse sorted array
VersionSorter.sort!(versions) # sort array in place
VersionSorter.rsort!(versions) # reverse sort array in place
VersionSorter.compare(version_a, version_b) #=> positive or negative number depending on which way to sort
```