Socket
Socket
Sign inDemoInstall

natural-compare

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.2.2 to 1.4.0

84

index.js

@@ -1,49 +0,57 @@

// Fork of https://github.com/litejs/natural-compare-lite
function naturalCompare(a, b) {
var i, codeA, codeB = 1,
posA = 0,
posB = 0;
function getCode(str, pos, code) {
if (code != null) {
for (i = pos; code = getCode(str, i), code < 76 && code > 65;) ++i;
return +str.slice(pos - (str.charAt(pos - 2) == "-" ? 2 : 1), i);
}
return code > -1 ? code + 76 : ((code = str.charCodeAt(pos) || 0), code < 45 || code > 127) ? code
: code < 46 ? 65 // -
: code < 48 ? code - 1
: code < 58 ? code + 18 // 0-9
: code < 65 ? code - 11
: code < 91 ? code + 11 // A-Z
: code < 97 ? code - 37
: code < 123 ? code + 5 // a-z
: code - 63;
}
if ((a += "") != (b += "")) {
for (; codeB;) {
codeA = getCode(a, posA++);
codeB = getCode(b, posB++);
/*
* @version 1.4.0
* @date 2015-10-26
* @stability 3 - Stable
* @author Lauri Rooden (https://github.com/litejs/natural-compare-lite)
* @license MIT License
*/
if (!i && codeA < 76 && codeB < 76 && codeA > 66 && codeB > 66) {
codeA = getCode(a, posA, posA);
codeB = getCode(b, posB, posA = i);
posB = i;
}
i = codeA == 66 || codeB == 66;
if (codeA != codeB) return (codeA < codeB) ? -1 : 1;
}
}
return 0;
}
var naturalCompare = function(a, b) {
var i, codeA
, codeB = 1
, posA = 0
, posB = 0
, alphabet = String.alphabet
function getCode(str, pos, code) {
if (code) {
for (i = pos; code = getCode(str, i), code < 76 && code > 65;) ++i;
return +str.slice(pos - 1, i)
}
code = alphabet && alphabet.indexOf(str.charAt(pos))
return code > -1 ? code + 76 : ((code = str.charCodeAt(pos) || 0), code < 45 || code > 127) ? code
: code < 46 ? 65 // -
: code < 48 ? code - 1
: code < 58 ? code + 18 // 0-9
: code < 65 ? code - 11
: code < 91 ? code + 11 // A-Z
: code < 97 ? code - 37
: code < 123 ? code + 5 // a-z
: code - 63
}
if ((a+="") != (b+="")) for (;codeB;) {
codeA = getCode(a, posA++)
codeB = getCode(b, posB++)
if (codeA < 76 && codeB < 76 && codeA > 66 && codeB > 66) {
codeA = getCode(a, posA, posA)
codeB = getCode(b, posB, posA = i)
posB = i
}
module.exports = naturalCompare;
if (codeA != codeB) return (codeA < codeB) ? -1 : 1
}
return 0
}
try {
module.exports = naturalCompare;
} catch (e) {
String.naturalCompare = naturalCompare;
}
{
"name": "natural-compare",
"version": "1.2.2",
"version": "1.4.0",
"stability": 3,
"author": "Lauri Rooden (https://github.com/litejs/natural-compare-lite)",
"license": "MIT",
"author": "Graeme Yeates (https://github.com/megawac/natural-compare)",
"description": "Compare strings containing a mix of letters and numbers in the way a human being would in sort order.",

@@ -15,16 +16,28 @@ "keywords": [

"compare",
"alphanum"
"alphanum",
"litejs"
],
"main": "index.js",
"readmeFilename": "README.md",
"files": [
"index.js"
],
"scripts": {
"travis-test": "istanbul cover ./tests/run.js && (coveralls < coverage/lcov.info || exit 0)",
"test": "node tests/run.js"
"build": "node node_modules/buildman/index.js --all",
"test": "node tests/index.js"
},
"repository": "git://github.com/litejs/natural-compare.git",
"repository": "git://github.com/litejs/natural-compare-lite.git",
"bugs": {
"url": "https://github.com/litejs/natural-compare/issues"
"url": "https://github.com/litejs/natural-compare-lite/issues"
},
"devDependencies": {
"buildman": "*",
"testman": "*"
},
"buildman": {
"dist/index-min.js": {
"banner": "/*! litejs.com/MIT-LICENSE.txt */",
"input": "index.js"
}
}
}
[Build]: http://img.shields.io/travis/megawac/natural-compare.png
[Coverage]: http://img.shields.io/coveralls/megawac/natural-compare.png
[1]: https://travis-ci.org/megawac/natural-compare
[2]: https://coveralls.io/r/megawac/natural-compare
[Build]: http://img.shields.io/travis/litejs/natural-compare-lite.png
[Coverage]: http://img.shields.io/coveralls/litejs/natural-compare-lite.png
[1]: https://travis-ci.org/litejs/natural-compare-lite
[2]: https://coveralls.io/r/litejs/natural-compare-lite
[npm package]: https://npmjs.org/package/natural-compare-lite
[GitHub repo]: https://github.com/litejs/natural-compare-lite
@version 1.4.0
@date 2015-10-26
@stability 3 - Stable
Natural Compare &ndash; [![Build][]][1] [![Coverage][]][2]

@@ -15,3 +23,3 @@ ===============

```plain
```text
Standard sorting: Natural order sorting:

@@ -39,3 +47,3 @@ img1.png img1.png

- In node.js: `npm install natural-compare`
- In node.js: `npm install natural-compare-lite`

@@ -70,3 +78,3 @@ ```javascript

// it is best for performance to keep
// transformed key in that object.
// transformed key in that object.
// There are no need to do text transformation

@@ -110,4 +118,3 @@ // on each comparision when sorting.

- [Source-code on Github](https://github.com/litejs/natural-compare-lite)
- [Package on npm](https://npmjs.org/package/natural-compare-lite)
- [GitHub repo][https://github.com/litejs/natural-compare-lite]
- [jsperf test](http://jsperf.com/natural-sort-2/12)

@@ -119,5 +126,5 @@

Copyright (c) 2012, 2014 Lauri Rooden &lt;lauri@rooden.ee&gt;
Copyright (c) 2012-2015 Lauri Rooden &lt;lauri@rooden.ee&gt;
[The MIT License](http://lauri.rooden.ee/mit-license.txt)
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