pax_global_header 0000666 0000000 0000000 00000000064 12667637062 0014531 g ustar 00root root 0000000 0000000 52 comment=a9235c7a5680aed3d9426cae1164d3c8b835857a
natural-sort-1.0.0/ 0000775 0000000 0000000 00000000000 12667637062 0014162 5 ustar 00root root 0000000 0000000 natural-sort-1.0.0/License.md 0000664 0000000 0000000 00000002117 12667637062 0016067 0 ustar 00root root 0000000 0000000 The MIT License (MIT)
=====================
Copyright © 2014 Studio B12 GmbH
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
natural-sort-1.0.0/Readme.md 0000664 0000000 0000000 00000003665 12667637062 0015713 0 ustar 00root root 0000000 0000000 [
](https://david-dm.org/studio-b12/natural-sort)
[
](https://github.com/airbnb/javascript)
natural-sort.js
===============
**Sorting with support for numbers, dates, unicode and more.**
Default features
----------------
- Numbers are handled properly (“2” is before “10”)
- Dates are detected and sorted as well
- Empty strings are after “z”
Usage
-----
```js
['10. tenth', 'odd', 1, '', '2. second'].sort(naturalSort())
// [1, '2. second', '10. tenth', 'odd', '']
[3, 4, 1, 5, 2].sort(naturalSort({direction: 'desc'}))
// [5, 4, 3, 2, 1]
['a', 'B'].sort(naturalSort())
// ['a', 'B']
['a', 'B'].sort(naturalSort({caseSensitive: true}))
// ['B', 'a']
```
Installation
------------
1. Download the script. You can use npm or bower:
```
npm install natural-sort
```
```
bower install natural-sort
```
2. Include the script before yours:
```html
```
Credits
-------
The original version of this algorithm was published by Jim Palmer in [this blog post][].
[this blog post]: http://www.overset.com/2008/09/01/javascript-natural-sort-algorithm/ "Javascript Natural Sort Algorithm With Unicode Support"
License
-------
[MIT][] © [Studio B12 GmbH][]
[MIT]: ./License.md
[Studio B12 GmbH]: http://studio-b12.de
natural-sort-1.0.0/bower.json 0000664 0000000 0000000 00000000707 12667637062 0016177 0 ustar 00root root 0000000 0000000 { "name": "natural-sort"
, "version": "0.1.0"
, "description": "Sorting with support for numbers, dates, unicode and more."
, "authors":
[ { "name": "Tomek Wiszniewski"
, "email": ""
}
]
, "copyright": "Studio B12 GmbH 2014"
, "license": "MIT"
, "repository":
{ "type": "git"
, "url": "https://github.com/studio-b12/natural-sort.git"
}
, "main": "./dist/natural-sort.js"
, "ignore":
[ "/package.json"
]
}
natural-sort-1.0.0/dist/ 0000775 0000000 0000000 00000000000 12667637062 0015125 5 ustar 00root root 0000000 0000000 natural-sort-1.0.0/dist/natural-sort.js 0000664 0000000 0000000 00000005652 12667637062 0020126 0 ustar 00root root 0000000 0000000 /*!
* natural-sort.js
* ===============
* Sorting with support for numbers, dates, unicode and more.
*
* http://github.com/studio-b12/natural-sort
* MIT License, © Studio B12 GmbH 2014
*
*//*
*
* Idea by Dave Koelle
* Original implementation by Jim Palmer
* Modified by Tomek Wiszniewski
*
*/
var naturalSort = function naturalSort (options) { 'use strict';
if (!options) options = {};
return function(a, b) {
var EQUAL = 0;
var GREATER = (options.direction == 'desc' ?
-1 :
1
);
var SMALLER = -GREATER;
var re = /(^-?[0-9]+(\.?[0-9]*)[df]?e?[0-9]?$|^0x[0-9a-f]+$|[0-9]+)/gi;
var sre = /(^[ ]*|[ ]*$)/g;
var dre = /(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/;
var hre = /^0x[0-9a-f]+$/i;
var ore = /^0/;
var normalize = function normalize (value) {
var string = '' + value;
return (options.caseSensitive ?
string :
string.toLowerCase()
);
};
// Normalize values to strings
var x = normalize(a).replace(sre, '') || '';
var y = normalize(b).replace(sre, '') || '';
// chunk/tokenize
var xN = x.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0');
var yN = y.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0');
// Return immediately if at least one of the values is empty.
if (!x && !y) return EQUAL;
if (!x && y) return GREATER;
if ( x && !y) return SMALLER;
// numeric, hex or date detection
var xD = parseInt(x.match(hre)) || (xN.length != 1 && x.match(dre) && Date.parse(x));
var yD = parseInt(y.match(hre)) || xD && y.match(dre) && Date.parse(y) || null;
var oFxNcL, oFyNcL;
// first try and sort Hex codes or Dates
if (yD) {
if ( xD < yD ) return SMALLER;
else if ( xD > yD ) return GREATER;
}
// natural sorting through split numeric strings and default strings
for (var cLoc=0, numS=Math.max(xN.length, yN.length); cLoc < numS; cLoc++) {
// find floats not starting with '0', string or 0 if not defined (Clint Priest)
oFxNcL = !(xN[cLoc] || '').match(ore) && parseFloat(xN[cLoc]) || xN[cLoc] || 0;
oFyNcL = !(yN[cLoc] || '').match(ore) && parseFloat(yN[cLoc]) || yN[cLoc] || 0;
// handle numeric vs string comparison - number < string - (Kyle Adams)
if (isNaN(oFxNcL) !== isNaN(oFyNcL)) return (isNaN(oFxNcL)) ? GREATER : SMALLER;
// rely on string comparison if different types - i.e. '02' < 2 != '02' < '2'
else if (typeof oFxNcL !== typeof oFyNcL) {
oFxNcL += '';
oFyNcL += '';
}
if (oFxNcL < oFyNcL) return SMALLER;
if (oFxNcL > oFyNcL) return GREATER;
}
return EQUAL;
};
};
(function (root, factory) {
if (typeof exports === 'object') {
module.exports = factory();
} else {
root.naturalSort = factory();
}
}(this, function () {
return naturalSort;
}));
natural-sort-1.0.0/package.json 0000664 0000000 0000000 00000000670 12667637062 0016453 0 ustar 00root root 0000000 0000000 {
"name": "natural-sort",
"version": "1.0.0",
"description": "Sorting with support for numbers, dates, unicode and more.",
"contributors": [
{
"name": "Tomek Wiszniewski",
"email": ""
}
],
"copyright": "Studio B12 GmbH 2014",
"license": "MIT",
"main": "dist/natural-sort.js",
"repository": {
"type": "git",
"url": "https://github.com/studio-b12/natural-sort.git"
}
}