table-sort-js
Advanced tools
Comparing version 1.17.0 to 1.18.0
{ | ||
"name": "table-sort-js", | ||
"version": "1.17.0", | ||
"version": "1.18.0", | ||
"description": "A JavaScript client-side HTML table sorting library with no dependencies required.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -20,9 +20,6 @@ /* | ||
function getHTMLTables() { | ||
if (testingTableSortJS === true) { | ||
const getTagTable = domDocumentWindow.getElementsByTagName("table"); | ||
return [getTagTable]; | ||
} else { | ||
const getTagTable = document.getElementsByTagName("table"); | ||
return [getTagTable]; | ||
} | ||
const getTagTable = !testingTableSortJS | ||
? document.getElementsByTagName("table") | ||
: domDocumentWindow.getElementsByTagName("table"); | ||
return [getTagTable]; | ||
} | ||
@@ -39,8 +36,5 @@ | ||
function createMissingTableHead(sortableTable) { | ||
let createTableHead; | ||
if (testingTableSortJS === true) { | ||
createTableHead = domDocumentWindow.createElement("thead"); | ||
} else { | ||
createTableHead = document.createElement("thead"); | ||
} | ||
let createTableHead = !testingTableSortJS | ||
? document.createElement("thead") | ||
: domDocumentWindow.createElement("thead"); | ||
createTableHead.appendChild(sortableTable.rows[0]); | ||
@@ -54,4 +48,4 @@ sortableTable.insertBefore(createTableHead, sortableTable.firstChild); | ||
if (sortableTable.querySelectorAll("tbody").length > 1) { | ||
// Why index 1?; I don't remember | ||
return sortableTable.querySelectorAll("tbody")[1]; | ||
// don't select empty tbody that the browser creates | ||
return sortableTable.querySelectorAll("tbody:not(:nth-child(2))"); | ||
} else { | ||
@@ -66,9 +60,11 @@ return sortableTable.querySelectorAll("tbody"); | ||
function inferSortClasses(tableRows, columnIndex, th) { | ||
function inferSortClasses(tableRows, columnIndex, column, th) { | ||
const runtimeRegex = /^(\d+h)?\s?(\d+m)?\s?(\d+s)?$/i; | ||
const fileSizeRegex = /^([.0-9]+)\s?(B|KB|KiB|MB|MiB|GB|GiB|TB|TiB)/i; | ||
// Doesn't infer dates with delimiter "."; as could capture semantic version numbers. | ||
// Don't infer dates with delimiter "."; as could capture semantic version numbers. | ||
const dmyRegex = /^(\d\d?)[/-](\d\d?)[/-]((\d\d)?\d\d)/; | ||
const ymdRegex = /^(\d\d\d\d)[/-](\d\d?)[/-](\d\d?)/; | ||
const numericRegex = /^(?:\(\d+(?:\.\d+)?\)|-?\d+(?:\.\d+)?)$/; | ||
// const numericRegex = /^(?:\(\d+(?:\.\d+)?\)|-?\d+(?:\.\d+)?)$/; doesn't handle commas | ||
const numericRegex = | ||
/^-?(?:\d{1,3}(?:[',]\d{3})*(?:\.\d+)?|\d+(?:\.\d+)?(?:[',]\d{3})*?)$/; | ||
const inferableClasses = { | ||
@@ -88,8 +84,14 @@ runtime: { regexp: runtimeRegex, class: "runtime-sort", count: 0 }, | ||
} | ||
const tableColumn = tr.querySelectorAll("td").item(columnIndex); | ||
const tableColumn = tr | ||
.querySelectorAll("td") | ||
.item( | ||
column.span[columnIndex] === 1 | ||
? column.spanSum[columnIndex] - 1 | ||
: column.spanSum[columnIndex] - column.span[columnIndex] | ||
); | ||
let foundMatch = false; | ||
for (let key of Object.keys(inferableClasses)) { | ||
let classRegexp = inferableClasses[key].regexp; | ||
if (tableColumn.innerText) { | ||
if (tableColumn.innerText.match(classRegexp) !== null) { | ||
if (tableColumn?.innerText !== undefined) { | ||
if (tableColumn.innerText.match(classRegexp)) { | ||
foundMatch = true; | ||
@@ -122,2 +124,5 @@ inferableClasses[key].count++; | ||
}; | ||
for (let index of table.theads.keys()) { | ||
table.headers.push(table.theads.item(index).querySelectorAll("th")); | ||
} | ||
for (let index of table.bodies.keys()) { | ||
@@ -127,6 +132,4 @@ if (table.bodies.item(index) == null) { | ||
} | ||
table.headers.push(table.theads.item(index).querySelectorAll("th")); | ||
table.rows.push(table.bodies.item(index).querySelectorAll("tr")); | ||
} | ||
table.hasClass = { | ||
@@ -138,3 +141,2 @@ noClassInfer: sortableTable.classList.contains("no-class-infer"), | ||
}; | ||
for ( | ||
@@ -146,2 +148,4 @@ let headerIndex = 0; | ||
let columnIndexesClicked = []; | ||
const column = { span: {}, spanSum: {} }; | ||
getColSpanData(table.headers[headerIndex], column); | ||
for (let [columnIndex, th] of table.headers[headerIndex].entries()) { | ||
@@ -151,3 +155,3 @@ if (!th.classList.contains("disable-sort")) { | ||
if (!table.hasClass.noClassInfer) { | ||
inferSortClasses(table.rows[headerIndex], columnIndex, th); | ||
inferSortClasses(table.rows[headerIndex], columnIndex, column, th); | ||
} | ||
@@ -257,15 +261,6 @@ makeEachColumnSortable( | ||
// TODO: github actions runtime didn't like textContent, tests didn't like innerText? | ||
if (testingTableSortJS) { | ||
columnOfTd = column.getColumn( | ||
tr, | ||
column.spanSum, | ||
column.span | ||
).textContent; | ||
} else { | ||
columnOfTd = column.getColumn( | ||
tr, | ||
column.spanSum, | ||
column.span | ||
).innerText; | ||
} | ||
columnOfTd = column.getColumn(tr, column.spanSum, column.span); | ||
columnOfTd = testingTableSortJS | ||
? columnOfTd.textContent | ||
: columnOfTd.innerText; | ||
let match = columnOfTd.match(regexMinutesAndSeconds); | ||
@@ -366,2 +361,4 @@ let [minutesInSeconds, hours, seconds] = [0, 0, 0]; | ||
let num1, num2; | ||
str1 = str1.replaceAll(",", ""); | ||
str2 = str2.replaceAll(",", ""); | ||
num1 = parseNumberFromString(str1); | ||
@@ -446,13 +443,5 @@ num2 = parseNumberFromString(str2); | ||
} | ||
let fileSizeInBytesHTML = column.getColumn( | ||
tr, | ||
column.spanSum, | ||
column.span | ||
).outerHTML; | ||
const fileSizeInBytesText = column.getColumn( | ||
tr, | ||
column.spanSum, | ||
column.span | ||
).textContent; | ||
let getColumnTd = column.getColumn(tr, column.spanSum, column.span); | ||
let fileSizeInBytesHTML = getColumnTd.outerHTML; | ||
const fileSizeInBytesText = getColumnTd.textContent; | ||
const fileSize = column.toBeSorted[i].replace(/#[0-9]*/, ""); | ||
@@ -459,0 +448,0 @@ let prefixes = ["", "Ki", "Mi", "Gi", "Ti", "Pi"]; |
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
29505
576