Gathering detailed insights and metrics for natural-compare-lite
Gathering detailed insights and metrics for natural-compare-lite
Gathering detailed insights and metrics for natural-compare-lite
Gathering detailed insights and metrics for natural-compare-lite
Compare strings containing a mix of letters and numbers in the way a human being would in sort order.
npm install natural-compare-lite
Typescript
Module System
Node Version
NPM Version
99.8
Supply Chain
99
Quality
75.9
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
1,223,753,523
Last Day
1,457,833
Last Week
9,001,681
Last Month
37,790,629
Last Year
464,287,235
MIT License
112 Stars
60 Commits
7 Forks
4 Watchers
2 Branches
3 Contributors
Updated on Apr 28, 2025
Minified
Minified + Gzipped
Latest Version
1.4.0
Package Id
natural-compare-lite@1.4.0
Size
2.45 kB
NPM Version
3.3.3
Node Version
4.1.0
Published on
Oct 26, 2015
Cumulative downloads
Total Downloads
Last Day
15.7%
1,457,833
Compared to previous day
Last Week
10.3%
9,001,681
Compared to previous week
Last Month
-7.9%
37,790,629
Compared to previous month
Last Year
-15.1%
464,287,235
Compared to previous year
@version 1.4.0
@date 2015-10-26
@stability 3 - Stable
Compare strings containing a mix of letters and numbers in the way a human being would in sort order. This is described as a "natural ordering".
1Standard sorting: Natural order sorting: 2 img1.png img1.png 3 img10.png img2.png 4 img12.png img10.png 5 img2.png img12.png
String.naturalCompare returns a number indicating whether a reference string comes before or after or is the same as the given string in sort order. Use it with builtin sort() function.
1<script src=min.natural-compare.js></script>
npm install natural-compare-lite
1require("natural-compare-lite")
1// Simple case sensitive example 2var a = ["z1.doc", "z10.doc", "z17.doc", "z2.doc", "z23.doc", "z3.doc"]; 3a.sort(String.naturalCompare); 4// ["z1.doc", "z2.doc", "z3.doc", "z10.doc", "z17.doc", "z23.doc"] 5 6// Use wrapper function for case insensitivity 7a.sort(function(a, b){ 8 return String.naturalCompare(a.toLowerCase(), b.toLowerCase()); 9}) 10 11// In most cases we want to sort an array of objects 12var a = [ {"street":"350 5th Ave", "room":"A-1021"} 13 , {"street":"350 5th Ave", "room":"A-21046-b"} ]; 14 15// sort by street, then by room 16a.sort(function(a, b){ 17 return String.naturalCompare(a.street, b.street) || String.naturalCompare(a.room, b.room); 18}) 19 20// When text transformation is needed (eg toLowerCase()), 21// it is best for performance to keep 22// transformed key in that object. 23// There are no need to do text transformation 24// on each comparision when sorting. 25var a = [ {"make":"Audi", "model":"A6"} 26 , {"make":"Kia", "model":"Rio"} ]; 27 28// sort by make, then by model 29a.map(function(car){ 30 car.sort_key = (car.make + " " + car.model).toLowerCase(); 31}) 32a.sort(function(a, b){ 33 return String.naturalCompare(a.sort_key, b.sort_key); 34})
It is possible to configure a custom alphabet to achieve a desired order.
1// Estonian alphabet 2String.alphabet = "ABDEFGHIJKLMNOPRSŠZŽTUVÕÄÖÜXYabdefghijklmnoprsšzžtuvõäöüxy" 3["t", "z", "x", "õ"].sort(String.naturalCompare) 4// ["z", "t", "õ", "x"] 5 6// Russian alphabet 7String.alphabet = "АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдеёжзийклмнопрстуфхцчшщъыьэюя" 8["Ё", "А", "Б"].sort(String.naturalCompare) 9// ["А", "Б", "Ё"]
Copyright (c) 2012-2015 Lauri Rooden <lauri@rooden.ee>
The MIT License
No vulnerabilities found.
Reason
security policy file detected
Details
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
SAST tool detected but not run on all commits
Details
Reason
0 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 1/30 approved changesets -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-05-05
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More