natural_sort alternatives and similar packages
Based on the "Algorithms and Data structures" category.
Alternatively, view natural_sort alternatives based on common mentions on social networks and blogs.
-
exconstructor
An Elixir library for generating struct constructors that handle external data with ease. -
aja
Extension of the Elixir standard library focused on data stuctures, data manipulation and performance -
remodel
:necktie: An Elixir presenter package used to transform map structures. "ActiveModel::Serializer for Elixir" -
MapDiff
Calculates the difference between two (nested) maps, and returns a map representing the patch of changes. -
the_fuzz
String metrics and phonetic algorithms for Elixir (e.g. Dice/Sorensen, Hamming, Jaccard, Jaro, Jaro-Winkler, Levenshtein, Metaphone, N-Gram, NYSIIS, Overlap, Ratcliff/Obershelp, Refined NYSIIS, Refined Soundex, Soundex, Weighted Levenshtein) -
exmatrix
Elixir library implementing a parallel matrix multiplication algorithm and other utilities for working with matrices. Used for benchmarking computationally intensive concurrent code. -
bitmap
Bitmap implementation in Elixir using binaries and integers. Fast space efficient data structure for lookups -
Closure Table
Closure Table for Elixir - a simple solution for storing and manipulating complex hierarchies.
CodeRabbit: AI Code Reviews for Developers

* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of natural_sort or a related project?
README
NaturalSort
NOTE v0.2 used an explicit second argument (case_sensitive
).
This has been removed and replaced with an options keyword list,
this is a breaking change.
Sort a list of strings containing numbers in a natural manner.
Sort functions will not [generally] sort strings containing numbers the same way a human would.
Given a list:
["a10", "a05c", "a1", "a", "a2", "a1a", "a0", "a1b", "a20"]
Applying standard sort will produce:
["a", "a0", "a05c", "a1", "a10", "a1a", "a1b", "a2", "a20"]
But applying a natural sort will give:
["a", "a0", "a1", "a1a", "a1b", "a2", "a05c", "a10", "a20"]
Functions
Just the one:
NaturalSort.sort(list, options \\ [])
Sorts a list of strings (ascending).
This works by leveraging Elixir's
Enum.sort_by/3
function (which takes as the second argument
a mapping function). The mapping operation converts each string
into a list of strings and integers. Once in this form, applying
the sort function results in a correctly sorted list.
Options
There are currently two available options (passed as a
keyword list), :direction
and case_sensitive
.
:direction
may have a value of:asc
or:desc
, and defaults to:asc
.:case_sensitive
may betrue
orfalse
, and defaults tofalse
.
Examples
iex> NaturalSort.sort(["x2-y7", "x8-y8", "x2-y08", "x2-g8" ])
["x2-g8", "x2-y7", "x2-y08", "x8-y8" ]
iex> NaturalSort.sort(["a5", "a400", "a1"], direction: :desc)
["a400", "a5", "a1"]
iex> NaturalSort.sort(["foo03.z", "foo45.D", "foo06.a", "foo06.A", "foo"], case_sensitive: :true)
["foo", "foo03.z", "foo06.A", "foo06.a", "foo45.D"]
iex> NaturalSort.sort(["foo03.z", "foo45.D", "foo06.a", "foo06.A", "foo"], [case_sensitive: :true, direction: :desc])
["foo45.D", "foo06.a", "foo06.A", "foo03.z", "foo"]
Prior art:
VersionEye's naturalsorter gem was the inspiration, with that being based on Martin Pool's natural sorting algorithm, and making direct use of the Ruby implementation of the original C version.
Elixir's Version module does a similar thing.
Todo/Review
- REVIEW: Benchmark further.
- ENHANCEMENT: Add options: choice to use unicode, choice to strip whitespace from result.
- ENHANCEMENT: Stream rather than map - this was designed to aid me in organising vast amounts of files by name; mapping over large lists seems inefficient.