Gathering detailed insights and metrics for natural-compare
Gathering detailed insights and metrics for natural-compare
Gathering detailed insights and metrics for natural-compare
Gathering detailed insights and metrics for natural-compare
Compare strings containing a mix of letters and numbers in the way a human being would in sort order.
npm install natural-compare
99.4
Supply Chain
99
Quality
75.1
Maintenance
100
Vulnerability
100
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
109 Stars
60 Commits
8 Forks
6 Watching
2 Branches
4 Contributors
Updated on 20 Nov 2024
Minified
Minified + Gzipped
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-7.8%
7,056,606
Compared to previous day
Last week
0.7%
41,493,335
Compared to previous week
Last month
13.5%
170,706,784
Compared to previous month
Last year
20.2%
1,699,900,354
Compared to previous year
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=natural-compare.js></script>
npm install natural-compare-lite
1var naturalCompare = require("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 comparison 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-2022 Lauri Rooden <lauri@rooden.ee>
The MIT License
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
security policy file detected
Details
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
SAST tool detected but not run on all commits
Details
Reason
1 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 1
Reason
Found 2/29 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
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 2024-11-18
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