table-sort-js
Advanced tools
Comparing version 1.10.2 to 1.11.2
{ | ||
"name": "table-sort-js", | ||
"version": "1.10.2", | ||
"version": "1.11.2", | ||
"description": "A JavaScript client-side HTML table sorting library with no dependencies required.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -56,2 +56,3 @@ ![table-sort-js](https://img.shields.io/npm/v/table-sort-js) | ||
| "file-size-sort" | Sort file sizes(B->TiB) uses the binary prefix. (e.g KiB) | | ||
| "runtime-sort" | Sorts runtime in minutes and seconds e.g (1m 20s). Useful for sorting the GitHub actions Run time column... | | ||
| "disable-sort" | Disallow sorting the table by this specific column. | | ||
@@ -58,0 +59,0 @@ | "alpha-sort" | Sort alphabetically (z11,z2); default is [natural sort](https://en.wikipedia.org/wiki/Natural_sort_order) (z2,z11). | |
@@ -125,2 +125,28 @@ /* | ||
function sortByRuntime(tableRows, columnData) { | ||
for (let [i, tr] of tableRows.entries()) { | ||
const regexMinutesAndSeconds = /^(\d+m)\s?(\d+s)$/i; | ||
let columnOfTd = tr | ||
.querySelectorAll("td") | ||
.item(columnIndex).textContent; | ||
let match = columnOfTd.match(regexMinutesAndSeconds); | ||
let minutesInSeconds, | ||
seconds, | ||
timeinSeconds = [0, 0, 0]; | ||
if (match) { | ||
const regexMinutes = match[1]; | ||
if (regexMinutes) { | ||
minutesInSeconds = Number(regexMinutes.replace("m", "")) * 60; | ||
} | ||
const regexSeconds = match[2]; | ||
if (regexSeconds) { | ||
seconds = Number(regexSeconds.replace("s", "")); | ||
} | ||
timeinSeconds = minutesInSeconds + seconds; | ||
} | ||
columnData.push(`${timeinSeconds}#${i}`); | ||
columnIndexAndTableRow[columnData[i]] = tr.innerHTML; | ||
} | ||
} | ||
let [timesClickedColumn, columnIndexesClicked] = [0, []]; | ||
@@ -156,2 +182,3 @@ | ||
isFileSize, | ||
isTimeSort, | ||
isDataAttribute, | ||
@@ -176,3 +203,3 @@ colSpanData, | ||
} | ||
if (!isFileSize && !isDataAttribute) { | ||
if (!isFileSize && !isDataAttribute && !isTimeSort) { | ||
columnData.push(`${tdTextContent}#${i}`); | ||
@@ -313,2 +340,7 @@ columnIndexAndTableRow[`${tdTextContent}#${i}`] = tr.innerHTML; | ||
const isTimeSort = th.classList.contains("runtime-sort"); | ||
if (isTimeSort) { | ||
sortByRuntime(visibleTableRows, columnData); | ||
} | ||
const isRememberSort = sortableTable.classList.contains("remember-sort"); | ||
@@ -327,2 +359,3 @@ if (!isRememberSort) { | ||
isDataAttribute, | ||
isTimeSort, | ||
colSpanData, | ||
@@ -329,0 +362,0 @@ colSpanSum, |
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
19517
346
64