pax_global_header00006660000000000000000000000064126676370620014531gustar00rootroot0000000000000052 comment=a9235c7a5680aed3d9426cae1164d3c8b835857a natural-sort-1.0.0/000077500000000000000000000000001266763706200141625ustar00rootroot00000000000000natural-sort-1.0.0/License.md000066400000000000000000000021171266763706200160670ustar00rootroot00000000000000The 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.md000066400000000000000000000036651266763706200157130ustar00rootroot00000000000000[![David – status of dependencies ](https://img.shields.io/david/studio-b12/natural-sort.svg?style=flat-square) ](https://david-dm.org/studio-b12/natural-sort)  [![Code style: airbnb ](https://img.shields.io/badge/code%20style-airbnb-777777.svg?style=flat-square) ](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.json000066400000000000000000000007071266763706200161770ustar00rootroot00000000000000{ "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/000077500000000000000000000000001266763706200151255ustar00rootroot00000000000000natural-sort-1.0.0/dist/natural-sort.js000066400000000000000000000056521266763706200201260ustar00rootroot00000000000000/*! * 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.json000066400000000000000000000006701266763706200164530ustar00rootroot00000000000000{ "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" } }