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

table-sort-js

Package Overview
Dependencies
Maintainers
1
Versions
50
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.7.9 to 1.8.0

2

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

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

@@ -91,2 +91,3 @@ /*

function sortFileSize(tableRows, columnData) {
// Handle filesize sorting (e.g KB, MB, GB, TB) - Turns data into KiB.
const numberWithUnitType =

@@ -158,2 +159,4 @@ /[.0-9]+(\s?B|\s?KB|\s?KiB|\s?MB|\s?MiB|\s?GB|\s?GiB|T\s?B|\s?TiB)/i;

function rememberSort(timesClickedColumn, columnIndexesClicked) {
// Check if user has clicked different column from the first column if
// yes reset times clicked.
columnIndexesClicked.push(columnIndex);

@@ -172,3 +175,18 @@ if (timesClickedColumn === 1 && columnIndexesClicked.length > 1) {

function getTableData(tableRows, columnData, isFileSize, isDataAttribute) {
function getColSpanData(sortableTable, colSpanData, colSpanSum) {
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;
});
}
function getTableData(
tableRows,
columnData,
isFileSize,
isDataAttribute,
colSpanData,
colSpanSum
) {
for (let [i, tr] of tableRows.entries()) {

@@ -178,3 +196,8 @@ // inner text for column we click on

.querySelectorAll("td")
.item(columnIndex).textContent;
.item(
colSpanData[columnIndex] === 1
? colSpanSum[columnIndex] - 1
: colSpanSum[columnIndex] - colSpanData[columnIndex]
).textContent;
if (tdTextContent.length === 0) {

@@ -337,3 +360,5 @@ tdTextContent = "";

const columnData = [];
// To make it work even if there is a tr with display: none; in the table, only the tr that is currently displayed is subject to sorting.
const colSpanData = {};
const colSpanSum = {};
const visibleTableRows = Array.prototype.filter.call(

@@ -347,4 +372,2 @@ tableBody.querySelectorAll("tr"),

let isDataAttribute = th.classList.contains("data-sort");
// Check if using data-sort attribute; if so sort by value of data-sort
// attribute.
if (isDataAttribute) {

@@ -355,3 +378,2 @@ sortDataAttributes(visibleTableRows, columnData);

let isFileSize = th.classList.contains("file-size");
// Handle filesize sorting (e.g KB, MB, GB, TB) - Turns data into KiB.
if (isFileSize) {

@@ -361,4 +383,2 @@ sortFileSize(visibleTableRows, columnData);

// Checking if user has clicked different column from the first column if
// yes reset times clicked.
let isRememberSort = sortableTable.classList.contains("remember-sort");

@@ -371,3 +391,12 @@ if (!isRememberSort) {

getTableData(visibleTableRows, columnData, isFileSize, isDataAttribute);
getColSpanData(sortableTable, colSpanData, colSpanSum);
// TODO: refactor function to take object.
getTableData(
visibleTableRows,
columnData,
isFileSize,
isDataAttribute,
colSpanData,
colSpanSum
);
updateTable(visibleTableRows, columnData, isFileSize);

@@ -374,0 +403,0 @@ });

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