Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

table-sort-js

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

table-sort-js - npm Package Compare versions

Comparing version 1.15.1 to 1.15.2

2

package.json
{
"name": "table-sort-js",
"version": "1.15.1",
"version": "1.15.2",
"description": "A JavaScript client-side HTML table sorting library with no dependencies required.",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -139,12 +139,12 @@ /*

function sortDataAttributes(tableRows, columnData) {
function sortDataAttributes(tableRows, column) {
for (let [i, tr] of tableRows.entries()) {
const dataAttributeTd = tr.querySelectorAll("td").item(columnIndex)
.dataset.sort;
columnData.push(`${dataAttributeTd}#${i}`);
columnIndexAndTableRow[columnData[i]] = tr.outerHTML;
let dataAttributeTd = getColumn(tr, column.spanSum, column.span).dataset
.sort;
column.toBeSorted.push(`${dataAttributeTd}#${i}`);
columnIndexAndTableRow[column.toBeSorted[i]] = tr.outerHTML;
}
}
function sortFileSize(tableRows, columnData) {
function sortFileSize(tableRows, column) {
let unitToMultiplier = {

@@ -171,5 +171,5 @@ b: 1,

let multiplier = unitToMultiplier[unit];
columnData.push(`${number * multiplier}#${i}`);
column.toBeSorted.push(`${number * multiplier}#${i}`);
} else {
columnData.push(`${fillValue}#${i}`);
column.toBeSorted.push(`${fillValue}#${i}`);
}

@@ -179,3 +179,3 @@ }

function sortByRuntime(tableRows, columnData) {
function sortByRuntime(tableRows, column) {
try {

@@ -187,7 +187,5 @@ for (let [i, tr] of tableRows.entries()) {

if (testingTableSortJS) {
columnOfTd = tr
.querySelectorAll("td")
.item(columnIndex).textContent;
columnOfTd = getColumn(tr, column.spanSum, column.span).textContent;
} else {
columnOfTd = tr.querySelectorAll("td").item(columnIndex).innerText;
columnOfTd = getColumn(tr, column.spanSum, column.span).innerText;
}

@@ -212,4 +210,4 @@ let match = columnOfTd.match(regexMinutesAndSeconds);

}
columnData.push(`${timeinSeconds}#${i}`);
columnIndexAndTableRow[columnData[i]] = tr.outerHTML;
column.toBeSorted.push(`${timeinSeconds}#${i}`);
columnIndexAndTableRow[column.toBeSorted[i]] = tr.outerHTML;
}

@@ -221,3 +219,3 @@ } catch (e) {

function sortDates(datesFormat, tableRows, columnData) {
function sortDates(datesFormat, tableRows, column) {
try {

@@ -231,3 +229,3 @@ for (let [i, tr] of tableRows.entries()) {

}
columnOfTd = tr.querySelectorAll("td").item(columnIndex).textContent;
columnOfTd = getColumn(tr, column.spanSum, column.span).textContent;
let match = columnOfTd.match(datesRegex);

@@ -253,4 +251,4 @@ let [years, days, months] = [0, 0, 0];

}
columnData.push(`${numberToSort}#${i}`);
columnIndexAndTableRow[columnData[i]] = tr.outerHTML;
column.toBeSorted.push(`${numberToSort}#${i}`);
columnIndexAndTableRow[column.toBeSorted[i]] = tr.outerHTML;
}

@@ -279,14 +277,24 @@ } catch (e) {

function getColSpanData(sortableTable, colSpanData, colSpanSum) {
function getColSpanData(sortableTable, column) {
sortableTable.querySelectorAll("th").forEach((th, index) => {
colSpanData[index] = th.colSpan;
if (index === 0) colSpanSum[index] = th.colSpan;
else colSpanSum[index] = colSpanSum[index - 1] + th.colSpan;
column.span[index] = th.colSpan;
if (index === 0) column.spanSum[index] = th.colSpan;
else column.spanSum[index] = column.spanSum[index - 1] + th.colSpan;
});
}
function getColumn(tr, colSpanSum, colSpanData) {
return tr
.querySelectorAll("td")
.item(
colSpanData[columnIndex] === 1
? colSpanSum[columnIndex] - 1
: colSpanSum[columnIndex] - colSpanData[columnIndex]
);
}
function getTableData(tableProperties) {
const {
tableRows,
columnData,
column,
isFileSize,

@@ -298,13 +306,9 @@ isTimeSort,

isDataAttribute,
colSpanData,
colSpanSum,
} = tableProperties;
for (let [i, tr] of tableRows.entries()) {
let tdTextContent = tr
.querySelectorAll("td")
.item(
colSpanData[columnIndex] === 1
? colSpanSum[columnIndex] - 1
: colSpanSum[columnIndex] - colSpanData[columnIndex]
).textContent;
let tdTextContent = getColumn(
tr,
column.spanSum,
column.span
).textContent;
if (tdTextContent.length === 0) {

@@ -315,3 +319,3 @@ tdTextContent = "";

if (isFileSize) {
fileSizeColumnTextAndRow[columnData[i]] = tr.outerHTML;
fileSizeColumnTextAndRow[column.toBeSorted[i]] = tr.outerHTML;
}

@@ -327,3 +331,3 @@ // These classes already handle pushing to column and setting the tr html.

) {
columnData.push(`${tdTextContent}#${i}`);
column.toBeSorted.push(`${tdTextContent}#${i}`);
columnIndexAndTableRow[`${tdTextContent}#${i}`] = tr.outerHTML;

@@ -333,3 +337,3 @@ }

// Fill in blank table cells dict key with filler value.
columnData.push(`${fillValue}#${i}`);
column.toBeSorted.push(`${fillValue}#${i}`);
columnIndexAndTableRow[`${fillValue}#${i}`] = tr.outerHTML;

@@ -364,3 +368,3 @@ }

if (columnData[0] === undefined) {
if (column.toBeSorted[0] === undefined) {
return;

@@ -377,3 +381,3 @@ }

function sortColumn(sortDirection) {
columnData.sort(sortDirection, {
column.toBeSorted.sort(sortDirection, {
numeric: !isAlphaSort,

@@ -405,6 +409,6 @@ ignorePunctuation: !isPunctSort,

function updateTable(tableProperties) {
const { tableRows, columnData, isFileSize } = tableProperties;
const { tableRows, column, isFileSize } = tableProperties;
for (let [i, tr] of tableRows.entries()) {
if (isFileSize) {
tr.innerHTML = fileSizeColumnTextAndRow[columnData[i]];
tr.innerHTML = fileSizeColumnTextAndRow[column.toBeSorted[i]];
let fileSizeInBytesHTML = tr

@@ -417,4 +421,4 @@ .querySelectorAll("td")

// Remove the unique identifyer for duplicate values(#number).
columnData[i] = columnData[i].replace(/#[0-9]*/, "");
const fileSize = parseFloat(columnData[i]);
column.toBeSorted[i] = column.toBeSorted[i].replace(/#[0-9]*/, "");
const fileSize = parseFloat(column.toBeSorted[i]);
let prefixes = ["", "Ki", "Mi", "Gi", "Ti", "Pi"];

@@ -443,3 +447,3 @@ let replaced = false;

} else if (!isFileSize) {
tr.outerHTML = columnIndexAndTableRow[columnData[i]];
tr.outerHTML = columnIndexAndTableRow[column.toBeSorted[i]];
}

@@ -450,3 +454,9 @@ }

th.addEventListener("click", function () {
const [columnData, colSpanData, colSpanSum] = [[], {}, {}];
timesClickedColumn += 1;
const column = {
// column used for sorting; better name?
toBeSorted: [],
span: {},
spanSum: {},
};

@@ -460,5 +470,7 @@ const visibleTableRows = Array.prototype.filter.call(

getColSpanData(sortableTable, column);
const isDataAttribute = th.classList.contains("data-sort");
if (isDataAttribute) {
sortDataAttributes(visibleTableRows, columnData);
sortDataAttributes(visibleTableRows, column);
}

@@ -468,3 +480,3 @@

if (isFileSize) {
sortFileSize(visibleTableRows, columnData);
sortFileSize(visibleTableRows, column);
}

@@ -474,3 +486,3 @@

if (isTimeSort) {
sortByRuntime(visibleTableRows, columnData);
sortByRuntime(visibleTableRows, column);
}

@@ -483,7 +495,7 @@

if (isSortDateMonthDayYear) {
sortDates("mdy", visibleTableRows, columnData);
sortDates("mdy", visibleTableRows, column);
} else if (isSortDateYearMonthDay) {
sortDates("ymd", visibleTableRows, columnData);
sortDates("ymd", visibleTableRows, column);
} else if (isSortDateDayMonthYear) {
sortDates("dmy", visibleTableRows, columnData);
sortDates("dmy", visibleTableRows, column);
}

@@ -496,8 +508,5 @@

timesClickedColumn += 1;
getColSpanData(sortableTable, colSpanData, colSpanSum);
const tableProperties = {
tableRows: visibleTableRows,
columnData,
column,
isFileSize,

@@ -509,4 +518,2 @@ isSortDateDayMonthYear,

isTimeSort,
colSpanData,
colSpanSum,
};

@@ -513,0 +520,0 @@ getTableData(tableProperties);

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