{"id":13507313,"url":"https://github.com/DanCouper/natural_sort","last_synced_at":"2025-03-30T07:32:44.854Z","repository":{"id":32095394,"uuid":"35667578","full_name":"DanCouper/natural_sort","owner":"DanCouper","description":"Elixir natural sort implementation for lists of strings.","archived":false,"fork":false,"pushed_at":"2021-04-14T07:00:55.000Z","size":232,"stargazers_count":14,"open_issues_count":1,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-08T19:52:24.579Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DanCouper.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-15T10:12:15.000Z","updated_at":"2023-03-08T04:28:24.000Z","dependencies_parsed_at":"2022-08-22T21:50:30.652Z","dependency_job_id":null,"html_url":"https://github.com/DanCouper/natural_sort","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanCouper%2Fnatural_sort","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanCouper%2Fnatural_sort/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanCouper%2Fnatural_sort/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanCouper%2Fnatural_sort/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DanCouper","download_url":"https://codeload.github.com/DanCouper/natural_sort/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222535177,"owners_count":16999233,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T02:00:30.960Z","updated_at":"2024-11-01T06:31:42.673Z","avatar_url":"https://github.com/DanCouper.png","language":"Elixir","funding_links":[],"categories":["Algorithms and Data structures"],"sub_categories":[],"readme":"NaturalSort\n===========\n\n**NOTE v0.2 used an explicit second argument (`case_sensitive`).\nThis has been removed and replaced with an options keyword list,\nthis is a breaking change.**\n\nSort a list of strings containing numbers in a natural manner.\n\nSort functions will not [generally] sort strings containing\nnumbers the same way a human would.\n\nGiven a list:\n\n```\n[\"a10\",  \"a05c\",  \"a1\",  \"a\",  \"a2\",  \"a1a\",  \"a0\",  \"a1b\",  \"a20\"]\n```\n\nApplying standard sort will produce:\n\n```\n[\"a\", \"a0\", \"a05c\", \"a1\", \"a10\", \"a1a\", \"a1b\", \"a2\", \"a20\"]\n```\n\nBut applying a natural sort will give:\n\n```\n[\"a\", \"a0\", \"a1\", \"a1a\", \"a1b\", \"a2\", \"a05c\", \"a10\", \"a20\"]\n```\n\n## Functions\n\nJust the one:\n\n### `NaturalSort.sort(list, options \\\\ [])`\n\nSorts a list of strings (ascending).\nThis works by leveraging Elixir's\n`Enum.sort_by/3` function (which takes as the second argument\na mapping function). The mapping operation converts each string\ninto a list of strings and integers. Once in this form, applying\nthe sort function results in a correctly sorted list.\n\n#### Options\n\nThere are currently two available options (passed as a\nkeyword list), `:direction` and `case_sensitive`.\n\n* `:direction` may have a value of `:asc` or `:desc`, and\n  defaults to `:asc`.\n* `:case_sensitive` may be `true` or `false`, and defaults\n  to `false`.\n\n\n#### Examples\n\n      iex\u003e NaturalSort.sort([\"x2-y7\", \"x8-y8\", \"x2-y08\", \"x2-g8\" ])\n      [\"x2-g8\", \"x2-y7\", \"x2-y08\", \"x8-y8\" ]\n\n      iex\u003e NaturalSort.sort([\"a5\", \"a400\", \"a1\"], direction: :desc)\n      [\"a400\", \"a5\", \"a1\"]\n\n      iex\u003e NaturalSort.sort([\"foo03.z\", \"foo45.D\", \"foo06.a\", \"foo06.A\", \"foo\"], case_sensitive: :true)\n      [\"foo\", \"foo03.z\", \"foo06.A\", \"foo06.a\", \"foo45.D\"]\n\n      iex\u003e NaturalSort.sort([\"foo03.z\", \"foo45.D\", \"foo06.a\", \"foo06.A\", \"foo\"], [case_sensitive: :true, direction: :desc])\n      [\"foo45.D\", \"foo06.a\", \"foo06.A\", \"foo03.z\", \"foo\"]\n\n## Prior art:\n\n[VersionEye's naturalsorter gem](https://github.com/versioneye/naturalsorter)\nwas the inspiration, with that being based on\n[Martin Pool's natural sorting algorithm](http://sourcefrog.net/projects/natsort/), and making direct use of the Ruby implementation of the original\nC version.\n\nElixir's [Version](https://github.com/elixir-lang/elixir/blob/v1.0.4/lib/elixir/lib/version.ex#L1) module does a similar thing.\n\n## Todo/Review\n\n- REVIEW: Benchmark further.\n- ENHANCEMENT: Add options: choice to use unicode, choice to strip whitespace from result.\n- 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.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDanCouper%2Fnatural_sort","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FDanCouper%2Fnatural_sort","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDanCouper%2Fnatural_sort/lists"}