New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

tablesort

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tablesort - npm Package Compare versions

Comparing version 1.7.0 to 2.0.0

.travis.yml

14

package.json
{
"name": "tablesort",
"description": "A sorting component for HTML tables",
"version": "1.7.0",
"version": "2.0.0",
"author": "tristen <@fallsemo>",

@@ -9,2 +9,5 @@ "ender": "./ender.js",

"homepage": "http://tristen.ca/tablesort/demo",
"scripts": {
"test": "tape test/test.client.js"
},
"repository": {

@@ -15,8 +18,11 @@ "type": "git",

"licenses": [{
"type": "MIT"
"type": "MIT"
}],
"devDependencies": {
"grunt": "~0.4.5",
"grunt-contrib-uglify": "~0.5.0"
"grunt": "~0.4.5",
"grunt-contrib-uglify": "~0.5.0",
"phantomjs": "~1.9.x",
"serve-static": "1.6.x",
"finalhandler": "0.2.x"
}
}

@@ -142,4 +142,8 @@ # tablesort.js

## Tests
npm test
## Bugs?
[Create an issue](https://github.com/tristen/tablesort/issues)

@@ -17,3 +17,2 @@ ;(function () {

this.options = options;
this.options.d = options.descending || false;

@@ -34,12 +33,11 @@ if (el.rows && el.rows.length > 0) {

var onClick = function () {
// Delete sort classes on headers that are not the current one.
var siblings = getParent(cell, 'tr').getElementsByTagName('th');
for (var i = 0; i < siblings.length; i++) {
if (hasClass(siblings[i], 'sort-up') || hasClass(siblings[i], 'sort-down')) {
if (siblings[i] !== this) {
siblings[i].className = siblings[i].className.replace(' sort-down', '')
.replace(' sort-up', '');
}
if (that.current && that.current !== this) {
if (that.current.classList.contains(classSortUp)) {
that.current.classList.remove(classSortUp);
}
else if (that.current.classList.contains(classSortDown)) {
that.current.classList.remove(classSortDown);
}
}
that.current = this;

@@ -54,7 +52,7 @@ that.sortTable(this);

var cell = firstRow.cells[i];
if (!hasClass(cell, 'no-sort')) {
cell.className += ' sort-header';
addEvent(cell, 'click', onClick);
if (!cell.classList.contains('no-sort')) {
cell.classList.add('sort-header');
cell.addEventListener('click', onClick, false);
if (hasClass(cell, 'sort-default')) {
if (cell.classList.contains('sort-default')) {
defaultSort = cell;

@@ -67,3 +65,3 @@ }

that.current = defaultSort;
that.sortTable(defaultSort);
that.sortTable(defaultSort, true);
}

@@ -94,3 +92,3 @@ },

item = getInnerText(t.tBodies[0].rows[i].cells[column]);
item = trim(item);
item = item.trim();
// Exclude cell values where commented out HTML exists

@@ -134,3 +132,3 @@ if (item.substr(0, 4) === '<!--' || item.length === 0) {

item.match(/^-?\d+\s*([,\.]\d{0,2})?[£\x24Û¢´€]/) || // suffixed currency
item.match(/^-?(\d+[,\.]?)+(E[\-+][\d]+)?%?$/) // number
item.match(/^-?(\d)+-?([,\.]){0,1}-?(\d)+([E,e][\-+][\d]+)?%?$/) // number
) {

@@ -153,3 +151,3 @@ sortFunction = sortNumber;

var tr = t.tBodies[i].rows[j];
if (hasClass(tr, 'no-sort')) {
if (tr.classList.contains('no-sort')) {
// keep no-sorts in separate list to be able to insert

@@ -169,20 +167,15 @@ // them back at their original position later

var sortUp = that.options.descending ? classSortDown : classSortUp,
sortDown = that.options.descending ? classSortUp : classSortDown;
if (!update) {
if (that.options.d) {
if (hasClass(header, 'sort-up')) {
header.className = header.className.replace(/ sort-up/, '');
header.className += ' sort-down';
} else {
header.className = header.className.replace(/ sort-down/, '');
header.className += ' sort-up';
}
if (header.classList.contains(sortUp)) {
header.classList.remove(sortUp);
header.classList.add(sortDown);
} else {
if (hasClass(header, 'sort-down')) {
header.className = header.className.replace(/ sort-down/, '');
header.className += ' sort-up';
} else {
header.className = header.className.replace(/ sort-up/, '');
header.className += ' sort-down';
}
header.classList.remove(sortDown);
header.classList.add(sortUp);
}
} else if (!header.classList.contains(sortUp) && !header.classList.contains(sortDown)) {
header.classList.add(sortUp);
}

@@ -217,3 +210,3 @@

// the double negatives cancel out
if (hasClass(header, 'sort-down')) {
if (header.classList.contains(classSortDown)) {
newRows.sort(antiStabilize(sortFunction));

@@ -248,5 +241,8 @@ newRows.reverse();

var week = /(Mon|Tue|Wed|Thu|Fri|Sat|Sun)\.?\,?\s*/i,
var classSortUp = 'sort-up',
classSortDown = 'sort-down';
var week = /(Mon|Tue|Wed|Thu|Fri|Sat|Sun)\.?\,?\s*/i,
commonDate = /\d{1,2}[\/\-]\d{1,2}[\/\-]\d{2,4}/,
month = /(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)/i;
month = /(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)/i;

@@ -324,25 +320,4 @@ var testDate = function(date) {

trim = function (s) {
return s.replace(/^\s+|\s+$/g, '');
},
cleanNumber = function (i) {
return i.replace(/[^\-?0-9.]/g, '');
},
hasClass = function (el, c) {
return (' ' + el.className + ' ').indexOf(' ' + c + ' ') > -1;
},
// http://ejohn.org/apps/jselect/event.html
addEvent = function (object, event, method) {
if (object.attachEvent) {
object['e' + event + method] = method;
object[event + method] = function () {
object['e' + event + method](window.event);
};
object.attachEvent('on' + event, object[event + method]);
} else {
object.addEventListener(event, method, false);
}
};

@@ -349,0 +324,0 @@

/*!
* tablesort v1.6.5 (2014-08-31)
* tablesort v1.7.0 (2014-09-19)
* http://tristen.ca/tablesort/demo
* Copyright (c) 2014 ; Licensed MIT
*/!function(){function a(a,b){if("TABLE"!==a.tagName)throw new Error("Element must be a table");this.init(a,b||{})}a.prototype={init:function(a,b){var c,d=this;if(this.thead=!1,this.options=b,this.options.d=b.descending||!1,a.rows&&a.rows.length>0&&(a.tHead&&a.tHead.rows.length>0?(c=a.tHead.rows[a.tHead.rows.length-1],d.thead=!0):c=a.rows[0]),c){for(var e,f=function(){for(var a=g(i,"tr").getElementsByTagName("th"),b=0;b<a.length;b++)(l(a[b],"sort-up")||l(a[b],"sort-down"))&&a[b]!==this&&(a[b].className=a[b].className.replace(" sort-down","").replace(" sort-up",""));d.current=this,d.sortTable(this)},h=0;h<c.cells.length;h++){var i=c.cells[h];l(i,"no-sort")||(i.className+=" sort-header",m(i,"click",f),l(i,"sort-default")&&(e=i))}e&&(d.current=e,d.sortTable(e))}},getFirstDataRowIndex:function(){return this.thead?0:1},sortTable:function(a,b){var c,d=this,m=a.cellIndex,n=g(a,"table"),o="",p=d.getFirstDataRowIndex();if(!(n.rows.length<=1)){for(;""===o&&p<n.tBodies[0].rows.length;)o=h(n.tBodies[0].rows[p].cells[m]),o=j(o),("<!--"===o.substr(0,4)||0===o.length)&&(o=""),p++;if(""!==o){var q=function(a,b){var c=h(a.cells[d.col]).toLowerCase(),e=h(b.cells[d.col]).toLowerCase();return c===e?0:e>c?1:-1},r=function(a,b){var c=h(a.cells[d.col]),e=h(b.cells[d.col]);return c=k(c),e=k(e),i(e,c)},s=function(a,b){var c=h(a.cells[d.col]).toLowerCase(),e=h(b.cells[d.col]).toLowerCase();return f(e)-f(c)};c=o.match(/^-?[£\x24Û¢´€]?\d+\s*([,\.]\d{0,2})/)||o.match(/^-?\d+\s*([,\.]\d{0,2})?[£\x24Û¢´€]/)||o.match(/^-?(\d+[,\.]?)+(E[\-+][\d]+)?%?$/)?r:e(o)?s:q,this.col=m;var t,u=[],v={},w=0;for(p=0;p<n.tBodies.length;p++)for(t=0;t<n.tBodies[p].rows.length;t++){var x=n.tBodies[p].rows[t];l(x,"no-sort")?v[w]=x:u.push({tr:x,index:w}),w++}b||(d.options.d?l(a,"sort-up")?(a.className=a.className.replace(/ sort-up/,""),a.className+=" sort-down"):(a.className=a.className.replace(/ sort-down/,""),a.className+=" sort-up"):l(a,"sort-down")?(a.className=a.className.replace(/ sort-down/,""),a.className+=" sort-up"):(a.className=a.className.replace(/ sort-up/,""),a.className+=" sort-down"));var y=function(a){return function(b,c){var d=a(b.tr,c.tr);return 0===d?b.index-c.index:d}},z=function(a){return function(b,c){var d=a(b.tr,c.tr);return 0===d?c.index-b.index:d}};l(a,"sort-down")?(u.sort(z(c)),u.reverse()):u.sort(y(c));var A=0;for(p=0;w>p;p++){var B;v[p]?(B=v[p],A++):B=u[p-A].tr,n.tBodies[0].appendChild(B)}}}},refresh:function(){void 0!==this.current&&this.sortTable(this.current,!0)}};var b=/(Mon|Tue|Wed|Thu|Fri|Sat|Sun)\.?\,?\s*/i,c=/\d{1,2}[\/\-]\d{1,2}[\/\-]\d{2,4}/,d=/(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)/i,e=function(a){return-1!==(-1!==a.search(b)||-1!==a.search(c)||a.search(-1!==d))&&!isNaN(f(a))},f=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()},g=function(a,b){return null===a?null:1===a.nodeType&&a.tagName.toLowerCase()===b.toLowerCase()?a:g(a.parentNode,b)},h=function(a){var b=this;if("string"==typeof a||"undefined"==typeof a)return a;var c=a.getAttribute("data-sort")||"";if(c)return c;if(a.textContent)return a.textContent;if(a.innerText)return a.innerText;for(var d=a.childNodes,e=d.length,f=0;e>f;f++)switch(d[f].nodeType){case 1:c+=b.getInnerText(d[f]);break;case 3:c+=d[f].nodeValue}return c},i=function(a,b){var c=parseFloat(a),d=parseFloat(b);return a=isNaN(c)?0:c,b=isNaN(d)?0:d,a-b},j=function(a){return a.replace(/^\s+|\s+$/g,"")},k=function(a){return a.replace(/[^\-?0-9.]/g,"")},l=function(a,b){return(" "+a.className+" ").indexOf(" "+b+" ")>-1},m=function(a,b,c){a.attachEvent?(a["e"+b+c]=c,a[b+c]=function(){a["e"+b+c](window.event)},a.attachEvent("on"+b,a[b+c])):a.addEventListener(b,c,!1)};"undefined"!=typeof module&&module.exports?module.exports=a:window.Tablesort=a}();
*/!function(){function a(a,b){if("TABLE"!==a.tagName)throw new Error("Element must be a table");this.init(a,b||{})}a.prototype={init:function(a,d){var e,f=this;if(this.thead=!1,this.options=d,a.rows&&a.rows.length>0&&(a.tHead&&a.tHead.rows.length>0?(e=a.tHead.rows[a.tHead.rows.length-1],f.thead=!0):e=a.rows[0]),e){for(var g,h=function(){f.current&&f.current!==this&&(f.current.classList.contains(b)?f.current.classList.remove(b):f.current.classList.contains(c)&&f.current.classList.remove(c)),f.current=this,f.sortTable(this)},i=0;i<e.cells.length;i++){var j=e.cells[i];j.classList.contains("no-sort")||(j.classList.add("sort-header"),j.addEventListener("click",h,!1),j.classList.contains("sort-default")&&(g=j))}g&&(f.current=g,f.sortTable(g,!0))}},getFirstDataRowIndex:function(){return this.thead?0:1},sortTable:function(a,d){var e,f=this,m=a.cellIndex,n=i(a,"table"),o="",p=f.getFirstDataRowIndex();if(!(n.rows.length<=1)){for(;""===o&&p<n.tBodies[0].rows.length;)o=j(n.tBodies[0].rows[p].cells[m]),o=o.trim(),("<!--"===o.substr(0,4)||0===o.length)&&(o=""),p++;if(""!==o){var q=function(a,b){var c=j(a.cells[f.col]).toLowerCase(),d=j(b.cells[f.col]).toLowerCase();return c===d?0:d>c?1:-1},r=function(a,b){var c=j(a.cells[f.col]),d=j(b.cells[f.col]);return c=l(c),d=l(d),k(d,c)},s=function(a,b){var c=j(a.cells[f.col]).toLowerCase(),d=j(b.cells[f.col]).toLowerCase();return h(d)-h(c)};e=o.match(/^-?[£\x24Û¢´€]?\d+\s*([,\.]\d{0,2})/)||o.match(/^-?\d+\s*([,\.]\d{0,2})?[£\x24Û¢´€]/)||o.match(/^-?(\d)+-?([,\.]){0,1}-?(\d)+([E,e][\-+][\d]+)?%?$/)?r:g(o)?s:q,this.col=m;var t,u=[],v={},w=0;for(p=0;p<n.tBodies.length;p++)for(t=0;t<n.tBodies[p].rows.length;t++){var x=n.tBodies[p].rows[t];x.classList.contains("no-sort")?v[w]=x:u.push({tr:x,index:w}),w++}var y=f.options.descending?c:b,z=f.options.descending?b:c;d?a.classList.contains(y)||a.classList.contains(z)||a.classList.add(y):a.classList.contains(y)?(a.classList.remove(y),a.classList.add(z)):(a.classList.remove(z),a.classList.add(y));var A=function(a){return function(b,c){var d=a(b.tr,c.tr);return 0===d?b.index-c.index:d}},B=function(a){return function(b,c){var d=a(b.tr,c.tr);return 0===d?c.index-b.index:d}};a.classList.contains(c)?(u.sort(B(e)),u.reverse()):u.sort(A(e));var C=0;for(p=0;w>p;p++){var D;v[p]?(D=v[p],C++):D=u[p-C].tr,n.tBodies[0].appendChild(D)}}}},refresh:function(){void 0!==this.current&&this.sortTable(this.current,!0)}};var b="sort-up",c="sort-down",d=/(Mon|Tue|Wed|Thu|Fri|Sat|Sun)\.?\,?\s*/i,e=/\d{1,2}[\/\-]\d{1,2}[\/\-]\d{2,4}/,f=/(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)/i,g=function(a){return-1!==(-1!==a.search(d)||-1!==a.search(e)||a.search(-1!==f))&&!isNaN(h(a))},h=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()},i=function(a,b){return null===a?null:1===a.nodeType&&a.tagName.toLowerCase()===b.toLowerCase()?a:i(a.parentNode,b)},j=function(a){var b=this;if("string"==typeof a||"undefined"==typeof a)return a;var c=a.getAttribute("data-sort")||"";if(c)return c;if(a.textContent)return a.textContent;if(a.innerText)return a.innerText;for(var d=a.childNodes,e=d.length,f=0;e>f;f++)switch(d[f].nodeType){case 1:c+=b.getInnerText(d[f]);break;case 3:c+=d[f].nodeValue}return c},k=function(a,b){var c=parseFloat(a),d=parseFloat(b);return a=isNaN(c)?0:c,b=isNaN(d)?0:d,a-b},l=function(a){return a.replace(/[^\-?0-9.]/g,"")};"undefined"!=typeof module&&module.exports?module.exports=a:window.Tablesort=a}();
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc