Comparing version 5.0.2 to 5.1.0
@@ -6,3 +6,6 @@ { | ||
"license": "MIT", | ||
"main": "tablesort.min.js", | ||
"main": [ | ||
"dist/tablesort.min.js", | ||
"dist/sorts/tablesort.*.min.js" | ||
], | ||
"authors": [ | ||
@@ -9,0 +12,0 @@ "tristen" |
@@ -16,5 +16,10 @@ module.exports = function(grunt) { | ||
}, | ||
build: { | ||
src: 'src/<%= pkg.name %>.js', | ||
dest: '<%= pkg.name %>.min.js' | ||
files: { | ||
expand: true, | ||
cwd: 'src', | ||
src: ['**/*.js'], | ||
dest: 'dist', | ||
rename: function (dst, src) { | ||
return dst + '/' + src.replace('.js', '.min.js'); | ||
} | ||
} | ||
@@ -21,0 +26,0 @@ } |
{ | ||
"name": "tablesort", | ||
"description": "A sorting component for HTML tables", | ||
"version": "5.0.0", | ||
"version": "5.1.0", | ||
"author": "tristen", | ||
@@ -22,3 +22,3 @@ "license": "MIT", | ||
"grunt-contrib-uglify": "^2.0.0", | ||
"phantomjs": "~1.9.x", | ||
"phantomjs-prebuilt": "~2.1.x", | ||
"serve-static": "1.6.x", | ||
@@ -25,0 +25,0 @@ "tap-spec": "^2.2.0", |
@@ -10,2 +10,10 @@ tablesort | ||
Download the ZIP of this repository or install via command line: | ||
``` cli | ||
npm install tablesort | ||
# Or if you're using Yarn | ||
yarn add tablesort | ||
``` | ||
``` html | ||
@@ -12,0 +20,0 @@ <script src='tablesort.min.js'></script> |
@@ -6,3 +6,3 @@ // Basic dates in dd/mm/yy or dd-mm-yy format. | ||
date = date.replace(/\-/g, '/'); | ||
date = date.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{2})/, '$1/$2/$3'); // format before getTime | ||
date = date.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{2,4})/, '$3-$2-$1'); // format before getTime | ||
@@ -9,0 +9,0 @@ return new Date(date).getTime() || -1; |
@@ -17,5 +17,5 @@ (function(){ | ||
Tablesort.extend('number', function(item) { | ||
return item.match(/^-?[£\x24Û¢´€]?\d+\s*([,\.]\d{0,2})/) || // Prefixed currency | ||
item.match(/^-?\d+\s*([,\.]\d{0,2})?[£\x24Û¢´€]/) || // Suffixed currency | ||
item.match(/^-?(\d)*-?([,\.]){0,1}-?(\d)+([E,e][\-+][\d]+)?%?$/); // Number | ||
return item.match(/^[-+]?[£\x24Û¢´€]?\d+\s*([,\.]\d{0,2})/) || // Prefixed currency | ||
item.match(/^[-+]?\d+\s*([,\.]\d{0,2})?[£\x24Û¢´€]/) || // Suffixed currency | ||
item.match(/^[-+]?(\d)*-?([,\.]){0,1}-?(\d)+([E,e][\-+][\d]+)?%?$/); // Number | ||
}, function(a, b) { | ||
@@ -22,0 +22,0 @@ a = cleanNumber(a); |
@@ -32,4 +32,4 @@ ;(function() { | ||
var caseInsensitiveSort = function(a, b) { | ||
a = a.toLowerCase(); | ||
b = b.toLowerCase(); | ||
a = a.trim().toLowerCase(); | ||
b = b.trim().toLowerCase(); | ||
@@ -150,3 +150,3 @@ if (a === b) return 0; | ||
} else { | ||
sortOrder = that.options.descending ? 'ascending' : 'descending'; | ||
sortOrder = that.options.descending ? 'descending' : 'ascending'; | ||
} | ||
@@ -221,5 +221,5 @@ | ||
newRows.sort(stabilize(sortFunction, true)); | ||
newRows.reverse(); | ||
} else { | ||
newRows.sort(stabilize(sortFunction, false)); | ||
newRows.reverse(); | ||
} | ||
@@ -226,0 +226,0 @@ |
@@ -71,5 +71,5 @@ tape('sorts insensitive', function(t) { | ||
t.equal(table.rows[1].cells[0].innerHTML, '3'); | ||
t.equal(table.rows[1].cells[0].innerHTML, '1'); | ||
t.equal(table.rows[2].cells[0].innerHTML, '2'); | ||
t.equal(table.rows[3].cells[0].innerHTML, '1'); | ||
t.equal(table.rows[3].cells[0].innerHTML, '3'); | ||
@@ -79,5 +79,5 @@ event.initEvent('click', true, false); | ||
t.equal(table.rows[1].cells[0].innerHTML, '1'); | ||
t.equal(table.rows[1].cells[0].innerHTML, '3'); | ||
t.equal(table.rows[2].cells[0].innerHTML, '2'); | ||
t.equal(table.rows[3].cells[0].innerHTML, '3'); | ||
t.equal(table.rows[3].cells[0].innerHTML, '1'); | ||
@@ -87,5 +87,5 @@ event.initEvent('click', true, false); | ||
t.equal(tableDescend.rows[1].cells[0].innerHTML, '1'); | ||
t.equal(tableDescend.rows[1].cells[0].innerHTML, '3'); | ||
t.equal(tableDescend.rows[2].cells[0].innerHTML, '2'); | ||
t.equal(tableDescend.rows[3].cells[0].innerHTML, '3'); | ||
t.equal(tableDescend.rows[3].cells[0].innerHTML, '1'); | ||
@@ -95,5 +95,5 @@ event.initEvent('click', true, false); | ||
t.equal(tableDescend.rows[1].cells[0].innerHTML, '3'); | ||
t.equal(tableDescend.rows[1].cells[0].innerHTML, '1'); | ||
t.equal(tableDescend.rows[2].cells[0].innerHTML, '2'); | ||
t.equal(tableDescend.rows[3].cells[0].innerHTML, '1'); | ||
t.equal(tableDescend.rows[3].cells[0].innerHTML, '3'); | ||
@@ -100,0 +100,0 @@ t.end(); |
@@ -11,3 +11,3 @@ #!/usr/bin/env node | ||
var serveStatic = require('serve-static'); | ||
var phantombin = require('phantomjs').path; | ||
var phantombin = require('phantomjs-prebuilt').path; | ||
@@ -14,0 +14,0 @@ var staticHandler = serveStatic(path.join(__dirname, '/../'), { |
/*! | ||
* tablesort v5.0.2 (2017-11-12) | ||
* tablesort v5.1.0 (2018-09-14) | ||
* http://tristen.ca/tablesort/demo/ | ||
* Copyright (c) 2017 ; Licensed MIT | ||
*/!function(){var a=function(a){return a=a.replace(/\-/g,"/"),a=a.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{2})/,"$1/$2/$3"),new Date(a).getTime()||-1};Tablesort.extend("date",function(b){return(b.search(/(Mon|Tue|Wed|Thu|Fri|Sat|Sun)\.?\,?\s*/i)!==-1||b.search(/\d{1,2}[\/\-]\d{1,2}[\/\-]\d{2,4}/)!==-1||b.search(/(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)/i)!==-1)&&!isNaN(a(b))},function(b,c){return b=b.toLowerCase(),c=c.toLowerCase(),a(c)-a(b)})}(); | ||
* Copyright (c) 2018 ; Licensed MIT | ||
*/ | ||
!function(){var a=function(a){return a=a.replace(/\-/g,"/"),a=a.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{2,4})/,"$3-$2-$1"),new Date(a).getTime()||-1};Tablesort.extend("date",function(b){return(-1!==b.search(/(Mon|Tue|Wed|Thu|Fri|Sat|Sun)\.?\,?\s*/i)||-1!==b.search(/\d{1,2}[\/\-]\d{1,2}[\/\-]\d{2,4}/)||-1!==b.search(/(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)/i))&&!isNaN(a(b))},function(b,c){return b=b.toLowerCase(),c=c.toLowerCase(),a(c)-a(b)})}(); |
/*! | ||
* tablesort v5.0.2 (2017-11-12) | ||
* tablesort v5.1.0 (2018-09-14) | ||
* http://tristen.ca/tablesort/demo/ | ||
* Copyright (c) 2017 ; Licensed MIT | ||
*/Tablesort.extend("dotsep",function(a){return/^(\d+\.)+\d+$/.test(a)},function(a,b){a=a.split("."),b=b.split(".");for(var c,d,e=0,f=a.length;e<f;e++)if(c=parseInt(a[e],10),d=parseInt(b[e],10),c!==d){if(c>d)return-1;if(c<d)return 1}return 0}); | ||
* Copyright (c) 2018 ; Licensed MIT | ||
*/ | ||
Tablesort.extend("dotsep",function(a){return/^(\d+\.)+\d+$/.test(a)},function(a,b){a=a.split("."),b=b.split(".");for(var c,d,e=0,f=a.length;e<f;e++)if(c=parseInt(a[e],10),d=parseInt(b[e],10),c!==d){if(c>d)return-1;if(c<d)return 1}return 0}); |
/*! | ||
* tablesort v5.0.2 (2017-11-12) | ||
* tablesort v5.1.0 (2018-09-14) | ||
* http://tristen.ca/tablesort/demo/ | ||
* Copyright (c) 2017 ; Licensed MIT | ||
*/!function(){var a=function(a,b){return a=parseFloat(a),b=parseFloat(b),a=isNaN(a)?0:a,b=isNaN(b)?0:b,a-b},b=function(a){return a.replace(/[^\-?0-9.]/g,"")},c=function(a){a=a.toLowerCase();var b="i"===a[1]?1024:1e3;switch(a[0]){case"k":return Math.pow(b,2);case"m":return Math.pow(b,3);case"g":return Math.pow(b,4);case"t":return Math.pow(b,5);case"p":return Math.pow(b,6);case"e":return Math.pow(b,7);case"z":return Math.pow(b,8);case"y":return Math.pow(b,9);default:return b}},d=function(a){var d=a.match(/^(\d+(\.\d+)?) ?((K|M|G|T|P|E|Z|Y|B$)i?B?)$/i),e=parseFloat(b(d[1])),f=d[3];return e*c(f)};Tablesort.extend("filesize",function(a){return/^\d+(\.\d+)? ?(K|M|G|T|P|E|Z|Y|B$)i?B?$/i.test(a)},function(b,c){return b=d(b),c=d(c),a(c,b)})}(); | ||
* Copyright (c) 2018 ; Licensed MIT | ||
*/ | ||
!function(){var a=function(a,b){return a=parseFloat(a),b=parseFloat(b),a=isNaN(a)?0:a,b=isNaN(b)?0:b,a-b},b=function(a){return a.replace(/[^\-?0-9.]/g,"")},c=function(a){a=a.toLowerCase();var b="i"===a[1]?1024:1e3;switch(a[0]){case"k":return Math.pow(b,2);case"m":return Math.pow(b,3);case"g":return Math.pow(b,4);case"t":return Math.pow(b,5);case"p":return Math.pow(b,6);case"e":return Math.pow(b,7);case"z":return Math.pow(b,8);case"y":return Math.pow(b,9);default:return b}},d=function(a){var d=a.match(/^(\d+(\.\d+)?) ?((K|M|G|T|P|E|Z|Y|B$)i?B?)$/i),e=parseFloat(b(d[1])),f=d[3];return e*c(f)};Tablesort.extend("filesize",function(a){return/^\d+(\.\d+)? ?(K|M|G|T|P|E|Z|Y|B$)i?B?$/i.test(a)},function(b,c){return b=d(b),c=d(c),a(c,b)})}(); |
/*! | ||
* tablesort v5.0.2 (2017-11-12) | ||
* tablesort v5.1.0 (2018-09-14) | ||
* http://tristen.ca/tablesort/demo/ | ||
* Copyright (c) 2017 ; Licensed MIT | ||
*/!function(){Tablesort.extend("monthname",function(a){return a.search(/(January|February|March|April|May|June|July|August|September|October|November|December)/i)!==-1},function(a,b){var c=["January","February","March","April","May","June","July","August","September","October","November","December"];return c.indexOf(b)-c.indexOf(a)})}(); | ||
* Copyright (c) 2018 ; Licensed MIT | ||
*/ | ||
!function(){Tablesort.extend("monthname",function(a){return-1!==a.search(/(January|February|March|April|May|June|July|August|September|October|November|December)/i)},function(a,b){var c=["January","February","March","April","May","June","July","August","September","October","November","December"];return c.indexOf(b)-c.indexOf(a)})}(); |
/*! | ||
* tablesort v5.0.2 (2017-11-12) | ||
* tablesort v5.1.0 (2018-09-14) | ||
* http://tristen.ca/tablesort/demo/ | ||
* Copyright (c) 2017 ; Licensed MIT | ||
*/!function(){var a=function(a){return a.replace(/[^\-?0-9.]/g,"")},b=function(a,b){return a=parseFloat(a),b=parseFloat(b),a=isNaN(a)?0:a,b=isNaN(b)?0:b,a-b};Tablesort.extend("number",function(a){return a.match(/^[-+]?[£\x24Û¢´€]?\d+\s*([,\.]\d{0,2})/)||a.match(/^[-+]?\d+\s*([,\.]\d{0,2})?[£\x24Û¢´€]/)||a.match(/^[-+]?(\d)*-?([,\.]){0,1}-?(\d)+([E,e][\-+][\d]+)?%?$/)},function(c,d){return c=a(c),d=a(d),b(d,c)})}(); | ||
* Copyright (c) 2018 ; Licensed MIT | ||
*/ | ||
!function(){var a=function(a){return a.replace(/[^\-?0-9.]/g,"")},b=function(a,b){return a=parseFloat(a),b=parseFloat(b),a=isNaN(a)?0:a,b=isNaN(b)?0:b,a-b};Tablesort.extend("number",function(a){return a.match(/^[-+]?[£\x24Û¢´€]?\d+\s*([,\.]\d{0,2})/)||a.match(/^[-+]?\d+\s*([,\.]\d{0,2})?[£\x24Û¢´€]/)||a.match(/^[-+]?(\d)*-?([,\.]){0,1}-?(\d)+([E,e][\-+][\d]+)?%?$/)},function(c,d){return c=a(c),d=a(d),b(d,c)})}(); |
/*! | ||
* tablesort v5.0.2 (2017-11-12) | ||
* tablesort v5.1.0 (2018-09-14) | ||
* http://tristen.ca/tablesort/demo/ | ||
* Copyright (c) 2017 ; Licensed MIT | ||
*/!function(){function a(b,c){if(!(this instanceof a))return new a(b,c);if(!b||"TABLE"!==b.tagName)throw new Error("Element must be a table");this.init(b,c||{})}var b=[],c=function(a){var b;return window.CustomEvent&&"function"==typeof window.CustomEvent?b=new CustomEvent(a):(b=document.createEvent("CustomEvent"),b.initCustomEvent(a,!1,!1,void 0)),b},d=function(a){return a.getAttribute("data-sort")||a.textContent||a.innerText||""},e=function(a,b){return a=a.trim().toLowerCase(),b=b.trim().toLowerCase(),a===b?0:a<b?1:-1},f=function(a,b){return function(c,d){var e=a(c.td,d.td);return 0===e?b?d.index-c.index:c.index-d.index:e}};a.extend=function(a,c,d){if("function"!=typeof c||"function"!=typeof d)throw new Error("Pattern and sort must be a function");b.push({name:a,pattern:c,sort:d})},a.prototype={init:function(a,b){var c,d,e,f,g=this;if(g.table=a,g.thead=!1,g.options=b,a.rows&&a.rows.length>0)if(a.tHead&&a.tHead.rows.length>0){for(e=0;e<a.tHead.rows.length;e++)if("thead"===a.tHead.rows[e].getAttribute("data-sort-method")){c=a.tHead.rows[e];break}c||(c=a.tHead.rows[a.tHead.rows.length-1]),g.thead=!0}else c=a.rows[0];if(c){var h=function(){g.current&&g.current!==this&&g.current.removeAttribute("aria-sort"),g.current=this,g.sortTable(this)};for(e=0;e<c.cells.length;e++)f=c.cells[e],f.setAttribute("role","columnheader"),"none"!==f.getAttribute("data-sort-method")&&(f.tabindex=0,f.addEventListener("click",h,!1),null!==f.getAttribute("data-sort-default")&&(d=f));d&&(g.current=d,g.sortTable(d))}},sortTable:function(a,g){var h=this,i=a.cellIndex,j=e,k="",l=[],m=h.thead?0:1,n=a.getAttribute("data-sort-method"),o=a.getAttribute("aria-sort");if(h.table.dispatchEvent(c("beforeSort")),g||(o="ascending"===o?"descending":"descending"===o?"ascending":h.options.descending?"descending":"ascending",a.setAttribute("aria-sort",o)),!(h.table.rows.length<2)){if(!n){for(;l.length<3&&m<h.table.tBodies[0].rows.length;)k=d(h.table.tBodies[0].rows[m].cells[i]),k=k.trim(),k.length>0&&l.push(k),m++;if(!l)return}for(m=0;m<b.length;m++)if(k=b[m],n){if(k.name===n){j=k.sort;break}}else if(l.every(k.pattern)){j=k.sort;break}for(h.col=i,m=0;m<h.table.tBodies.length;m++){var p,q=[],r={},s=0,t=0;if(!(h.table.tBodies[m].rows.length<2)){for(p=0;p<h.table.tBodies[m].rows.length;p++)k=h.table.tBodies[m].rows[p],"none"===k.getAttribute("data-sort-method")?r[s]=k:q.push({tr:k,td:d(k.cells[h.col]),index:s}),s++;for("descending"===o?q.sort(f(j,!0)):(q.sort(f(j,!1)),q.reverse()),p=0;p<s;p++)r[p]?(k=r[p],t++):k=q[p-t].tr,h.table.tBodies[m].appendChild(k)}}h.table.dispatchEvent(c("afterSort"))}},refresh:function(){void 0!==this.current&&this.sortTable(this.current,!0)}},"undefined"!=typeof module&&module.exports?module.exports=a:window.Tablesort=a}(); | ||
* Copyright (c) 2018 ; Licensed MIT | ||
*/ | ||
!function(){function a(b,c){if(!(this instanceof a))return new a(b,c);if(!b||"TABLE"!==b.tagName)throw new Error("Element must be a table");this.init(b,c||{})}var b=[],c=function(a){var b;return window.CustomEvent&&"function"==typeof window.CustomEvent?b=new CustomEvent(a):(b=document.createEvent("CustomEvent"),b.initCustomEvent(a,!1,!1,void 0)),b},d=function(a){return a.getAttribute("data-sort")||a.textContent||a.innerText||""},e=function(a,b){return a=a.trim().toLowerCase(),b=b.trim().toLowerCase(),a===b?0:a<b?1:-1},f=function(a,b){return function(c,d){var e=a(c.td,d.td);return 0===e?b?d.index-c.index:c.index-d.index:e}};a.extend=function(a,c,d){if("function"!=typeof c||"function"!=typeof d)throw new Error("Pattern and sort must be a function");b.push({name:a,pattern:c,sort:d})},a.prototype={init:function(a,b){var c,d,e,f,g=this;if(g.table=a,g.thead=!1,g.options=b,a.rows&&a.rows.length>0)if(a.tHead&&a.tHead.rows.length>0){for(e=0;e<a.tHead.rows.length;e++)if("thead"===a.tHead.rows[e].getAttribute("data-sort-method")){c=a.tHead.rows[e];break}c||(c=a.tHead.rows[a.tHead.rows.length-1]),g.thead=!0}else c=a.rows[0];if(c){var h=function(){g.current&&g.current!==this&&g.current.removeAttribute("aria-sort"),g.current=this,g.sortTable(this)};for(e=0;e<c.cells.length;e++)f=c.cells[e],f.setAttribute("role","columnheader"),"none"!==f.getAttribute("data-sort-method")&&(f.tabindex=0,f.addEventListener("click",h,!1),null!==f.getAttribute("data-sort-default")&&(d=f));d&&(g.current=d,g.sortTable(d))}},sortTable:function(a,g){var h=this,i=a.cellIndex,j=e,k="",l=[],m=h.thead?0:1,n=a.getAttribute("data-sort-method"),o=a.getAttribute("aria-sort");if(h.table.dispatchEvent(c("beforeSort")),g||(o="ascending"===o?"descending":"descending"===o?"ascending":h.options.descending?"descending":"ascending",a.setAttribute("aria-sort",o)),!(h.table.rows.length<2)){if(!n){for(;l.length<3&&m<h.table.tBodies[0].rows.length;)k=d(h.table.tBodies[0].rows[m].cells[i]),k=k.trim(),k.length>0&&l.push(k),m++;if(!l)return}for(m=0;m<b.length;m++)if(k=b[m],n){if(k.name===n){j=k.sort;break}}else if(l.every(k.pattern)){j=k.sort;break}for(h.col=i,m=0;m<h.table.tBodies.length;m++){var p,q=[],r={},s=0,t=0;if(!(h.table.tBodies[m].rows.length<2)){for(p=0;p<h.table.tBodies[m].rows.length;p++)k=h.table.tBodies[m].rows[p],"none"===k.getAttribute("data-sort-method")?r[s]=k:q.push({tr:k,td:d(k.cells[h.col]),index:s}),s++;for("descending"===o?q.sort(f(j,!0)):(q.sort(f(j,!1)),q.reverse()),p=0;p<s;p++)r[p]?(k=r[p],t++):k=q[p-t].tr,h.table.tBodies[m].appendChild(k)}}h.table.dispatchEvent(c("afterSort"))}},refresh:function(){void 0!==this.current&&this.sortTable(this.current,!0)}},"undefined"!=typeof module&&module.exports?module.exports=a:window.Tablesort=a}(); |
{ | ||
"name": "tablesort", | ||
"description": "A sorting component for HTML tables", | ||
"version": "5.0.2", | ||
"version": "5.1.0", | ||
"author": "tristen", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
@@ -10,2 +10,10 @@ tablesort | ||
Download the ZIP of this repository or install via command line: | ||
``` cli | ||
npm install tablesort | ||
# Or if you're using Yarn | ||
yarn add tablesort | ||
``` | ||
``` html | ||
@@ -12,0 +20,0 @@ <script src='tablesort.min.js'></script> |
@@ -6,3 +6,3 @@ // Basic dates in dd/mm/yy or dd-mm-yy format. | ||
date = date.replace(/\-/g, '/'); | ||
date = date.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{2})/, '$1/$2/$3'); // format before getTime | ||
date = date.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{2,4})/, '$3-$2-$1'); // format before getTime | ||
@@ -9,0 +9,0 @@ return new Date(date).getTime() || -1; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
432211
68
11120
94