Socket
Socket
Sign inDemoInstall

natural-compare-lite

Package Overview
Dependencies
0
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.1 to 0.1.0

2

min.js

@@ -1,1 +0,1 @@

String.natural_compare=function(d,e){var c,a,b,f=0,g=0;if(d!==e)for(;""!==a;){a=d.charAt(f++);b=e.charAt(g++);if("/"<a&&":">a){for(;c=d.charAt(f),"/"<c&&":">c;f++)a+=c;a|=0}if("/"<b&&":">b){if("number"!==typeof a)return 1;for(;c=e.charAt(g),"/"<c&&":">c;g++)b+=c;b|=0}else if("number"===typeof a)return-1;if(a>b)return 1;if(a<b)return-1}return 0};
String.natural_compare=function(c,d){var e,a=1,f,b,g=0,h=0;c=(""+c).toLowerCase();d=(""+d).toLowerCase();if(c!==d)for(;a;){a=c.charCodeAt(g++)||0;f=d.charCodeAt(h++)||0;b=-1;if(58>a&&47<a){for(b=g-1;e=c.charCodeAt(g),58>e&&47<e;)g++;a=c.slice(b,g)>>0}if(58>f&&47<f){if(-1===b)return 1;for(b=h-1;e=d.charCodeAt(h),58>e&&47<e;)h++;f=d.slice(b,h)>>0}else if(-1<b)return-1;if(a>f)return 1;if(a<f)return-1}return 0};

@@ -5,3 +5,3 @@

/*
* @version 0.0.1
* @version 0.1.0
* @author Lauri Rooden - https://github.com/litejs/natural-compare-lite

@@ -14,23 +14,28 @@ * @license MIT License - http://lauri.rooden.ee/mit-license.txt

String.natural_compare = function(a, b) {
var c, ca, cb, ia = 0, ib = 0
var c, ca = 1, cb, i, ia = 0, ib = 0
if (a !== b) while (ca !== "") {
ca = a.charAt( ia++ )
cb = b.charAt( ib++ )
a = (""+a).toLowerCase()
b = (""+b).toLowerCase()
if (ca > "/" && ca < ":") {
for (;c = a.charAt(ia), c > "/" && c < ":";ia++) ca += c
ca |= 0
}
if (a !== b) while (ca) {
ca = a.charCodeAt( ia++ ) || 0
cb = b.charCodeAt( ib++ ) || 0
if (cb > "/" && cb < ":") {
i = -1
if (ca < 58 && ca > 47) {
for (i=ia-1;c = a.charCodeAt(ia), c < 58 && c > 47;)ia++
ca = a.slice(i, ia)>>0
}
if (cb < 58 && cb > 47) {
// number always comes first
if (typeof ca !== "number") return 1
for (;c = b.charAt(ib), c > "/" && c < ":";ib++) cb += c
cb |= 0
} else if (typeof ca === "number") return -1
if (i === -1) return 1
for (i=ib-1;c = b.charCodeAt(ib), c < 58 && c > 47;)ib++
cb = b.slice(i, ib)>>0
} else if (i > -1) return -1
if (ca > cb) return 1
if (ca < cb) return -1
}
if (ca > cb) return 1
if (ca < cb) return -1
}
return 0

@@ -37,0 +42,0 @@ }

{
"name": "natural-compare-lite",
"version": "0.0.1",
"version": "0.1.0",
"license": "MIT",
"description": "Natural compare",
"description": "Natural Order String Comparison for Sorting",
"main": "natural-compare-lite.js",

@@ -19,3 +19,5 @@ "author": "Lauri Rooden <lauri@rooden.ee>",

"keywords": [
"string",
"natural",
"order",
"sort",

@@ -22,0 +24,0 @@ "compare",

@@ -6,7 +6,7 @@

Natural Compare
===============
Natural Order String Comparison
===============================
Download [compressed][1]
(348 bytes or 229 bytes gzipped)
(412 bytes or 267 bytes gzipped)
or [uncompressed][2] source.

@@ -22,3 +22,8 @@

External links
--------------
- [jsperf test](http://jsperf.com/natural-sort-2/2)
### Licence

@@ -25,0 +30,0 @@

@@ -29,2 +29,6 @@ process.chdir( process.argv[1].replace(/[^/]+$/, "") )

, String.natural_compare("a11", "a1"), 1
, String.natural_compare("a1a", "a1"), 1
, String.natural_compare("a1", "a1a"), -1
, String.natural_compare("a1a", "a11"), -1

@@ -31,0 +35,0 @@ , String.natural_compare("a11", "a1a"), 1

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc