{"id":23092289,"url":"https://github.com/sourcefrog/natsort","last_synced_at":"2025-08-16T10:30:46.007Z","repository":{"id":16238891,"uuid":"18986575","full_name":"sourcefrog/natsort","owner":"sourcefrog","description":"natural sort order string comparison: \"a1\" \u003c \"a12\"","archived":false,"fork":false,"pushed_at":"2024-04-04T16:36:43.000Z","size":74,"stargazers_count":118,"open_issues_count":4,"forks_count":23,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-04-04T17:43:44.357Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sourcefrog.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-04-21T08:16:14.000Z","updated_at":"2024-03-21T19:32:40.000Z","dependencies_parsed_at":"2022-09-14T03:22:52.855Z","dependency_job_id":null,"html_url":"https://github.com/sourcefrog/natsort","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sourcefrog%2Fnatsort","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sourcefrog%2Fnatsort/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sourcefrog%2Fnatsort/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sourcefrog%2Fnatsort/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sourcefrog","download_url":"https://codeload.github.com/sourcefrog/natsort/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230028326,"owners_count":18161887,"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-12-16T21:32:02.447Z","updated_at":"2024-12-16T21:32:02.955Z","avatar_url":"https://github.com/sourcefrog.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Natural Order String Comparison\n\n[![Build](https://github.com/sourcefrog/natsort/actions/workflows/ci.yml/badge.svg)](https://github.com/sourcefrog/natsort/actions/workflows/ci.yml)\n\nMartin Pool \u003chttp://sourcefrog.net\u003e\n\nComputer string sorting algorithms generally don't order strings\ncontaining numbers in the same way that a human would do.  Consider:\n\n        rfc1.txt\n        rfc2086.txt\n        rfc822.txt\n\nIt would be more friendly if the program listed the files as\n\n        rfc1.txt\n        rfc822.txt\n        rfc2086.txt\n\nFilenames sort properly if people insert leading zeros, but they\ndon't always do that.\n\nI've written a subroutine that compares strings according to this\nnatural ordering.  You can use this routine in your own software, or\ndownload a patch to add it to your favourite Unix program.\n\n\n## Sorting\n\nStrings are sorted as usual, except that decimal integer substrings\nare compared on their numeric value.  For example,\n\n\n    a \u003c a0 \u003c a1 \u003c a1a \u003c a1b \u003c a2 \u003c a10 \u003c a20\n\n\nStrings can contain several number parts:\n\n    x2-g8 \u003c x2-y08 \u003c x2-y7 \u003c x8-y8\n\nin which case numeric fields are separated by nonnumeric characters.\nLeading spaces are ignored.  This works very well for IP addresses\nfrom log files, for example.\n\n\nLeading zeros are *not* ignored, which tends to give more\nreasonable results on decimal fractions.\n\n      1.001 \u003c 1.002 \u003c 1.010 \u003c 1.02 \u003c 1.1 \u003c 1.3\n\nSome applications may wish to change this by modifying the test that calls `isspace`.\n\nPerformance is linear: each character of the string is scanned\nat most once, and only as many characters as necessary to decide\nare considered.\n\n\n## Licensing\n\nThis software is copyright by Martin Pool, and made available under\nthe same licence as zlib:\n\n\n\u003e  This software is provided 'as-is', without any express or implied\n\u003e  warranty.  In no event will the authors be held liable for any damages\n\u003e  arising from the use of this software.\n\u003e\n\u003e  Permission is granted to anyone to use this software for any purpose,\n\u003e  including commercial applications, and to alter it and redistribute it\n\u003e  freely, subject to the following restrictions:\n\u003e\n\u003e  1. The origin of this software must not be misrepresented; you must not\n\u003e     claim that you wrote the original software. If you use this software\n\u003e     in a product, an acknowledgment in the product documentation would be\n\u003e     appreciated but is not required.\n\u003e\n\u003e  2. Altered source versions must be plainly marked as such, and must not be\n\u003e     misrepresented as being the original software.\n\u003e\n\u003e  3. This notice may not be removed or altered from any source distribution.\n\n\nThis licence applies only to the C implementation.  You are free to\nreimplement the idea fom scratch in any language.\n\n## Get It!\n\n`strnatcmp.c`, `strnatcmp.h` - the algorithm itself\n\n`natsort.c` - example driver program.\n\n`natcompare.js` - Kristof Coomans wrote a natural sort comparison in Javascript.\n\n`natcmp.rb` -- An implementation by Alan Davies in Ruby.\n\n## Related Work\n\n\n\nPOSIX sort(1) has the -n option to sort numbers, but this doesn't\nwork if there is a non-numeric prefix.\n\n\nGNU ls(1) has the `--sort=version` option, which works\nthe same way.\n\n\n\nThe PHP scripting language now has a\n[strnatcmp](http://us3.php.net/manual/en/function.strnatcmp.php)\nfunction based on this code.\nThe PHP wrapper was done by Andrei Zimievsky.\n\n\n\n[Stuart Cheshire has a Macintosh system extension](http://www.naturalordersort.org/)\nto do natural ordering.\nI indepdendently reinvented the algorithm, but Stuart had it\nfirst.  I borrowed the term natural sort from him.\n\n\n\n\n[`Sort::Versions`](http://search.cpan.org/src/EDAVIS/Sort-Versions-1.4/README)\nin Perl.  \"The code has some special magic to deal with common conventions in program version numbers, like the difference between 'decimal' versions (eg perl 5.005) and the Unix kind (eg perl 5.6.1).\"\n\n[Sort::Naturally](http://www.cpan.org/modules/by-module/Sort/Sort-Naturally-1.01.readme)\nis also in Perl, by  Sean M. Burke.  It uses locale-sensitive character classes to sort words and numeric substrings\nin a way similar to natsort.\n\n\nEd Avis wrote [something similar in Haskell](http://membled.com/work/apps/todo/numsort).\n\n\n\nPierre-Luc Paour wrote a\n[`NaturalOrderComparator`](http://github.com/paour/natorder)\nin Java.\n\n[Numacomp](http://sourceforge.net/projects/numacomp) - similar thing in Python.\n\n[as3natcompare](http://code.google.com/p/as3natcompare/) implementation in Flash ActionScript 3.\n\n## To Do\n\nComparison of characters is purely numeric, without taking\ncharacter set or locale into account.  So it is only correct for\nASCII.  This should probably be a separate function because doing\nthe comparisons will probably introduce a dependency on the OS\nmechanism for finding the locale and comparing characters.\n\nIt might be good to support multibyte character sets too.\n\nIf you fix either of these, please mail me.  They should not be\nvery hard.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsourcefrog%2Fnatsort","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsourcefrog%2Fnatsort","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsourcefrog%2Fnatsort/lists"}