diff --git a/browser-extensions/chrome/manifest.json b/browser-extensions/chrome/manifest.json index 251c72e..63632da 100644 --- a/browser-extensions/chrome/manifest.json +++ b/browser-extensions/chrome/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 3, "author": "Lee Wannacott", "name": "table-sort-js", - "version": "1.17.0", + "version": "1.17.1", "description": "Makes tables sortable using table-sort-js: https://github.com/LeeWannacott/table-sort-js", "icons": { "48": "icons/t.png" }, "browser_action": { diff --git a/browser-extensions/chrome/table-sort-js.zip b/browser-extensions/chrome/table-sort-js.zip index 43adff3..0517282 100644 Binary files a/browser-extensions/chrome/table-sort-js.zip and b/browser-extensions/chrome/table-sort-js.zip differ diff --git a/browser-extensions/chrome/table-sort.js b/browser-extensions/chrome/table-sort.js index a9a7e31..af0e6ab 100644 --- a/browser-extensions/chrome/table-sort.js +++ b/browser-extensions/chrome/table-sort.js @@ -17,13 +17,10 @@ Instructions: function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) { 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]; } const [getTagTable] = getHTMLTables(); @@ -35,12 +32,9 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) { } 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]); sortableTable.insertBefore(createTableHead, sortableTable.firstChild); } @@ -49,8 +43,8 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) { if (sortableTable.getElementsByTagName("thead").length === 0) { createMissingTableHead(sortableTable); 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 { return sortableTable.querySelectorAll("tbody"); } @@ -85,8 +79,8 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) { 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; inferableClasses[key].count++; } @@ -114,21 +108,21 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) { rows: [], headers: [], }; + for (let index of table.theads.keys()) { + table.headers.push(table.theads.item(index).querySelectorAll("th")); + } for (let index of table.bodies.keys()) { if (table.bodies.item(index) == null) { return; } - table.headers.push(table.theads.item(index).querySelectorAll("th")); table.rows.push(table.bodies.item(index).querySelectorAll("tr")); } - table.hasClass = { noClassInfer: sortableTable.classList.contains("no-class-infer"), cellsSort: sortableTable.classList.contains("cells-sort"), tableArrows: sortableTable.classList.contains("table-arrows"), rememberSort: sortableTable.classList.contains("remember-sort"), }; - for ( let headerIndex = 0; headerIndex < table.theads.length; @@ -244,19 +238,10 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) { const regexMinutesAndSeconds = /^(\d+h)?\s?(\d+m)?\s?(\d+s)?$/i; let columnOfTd = ""; // 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); let [minutesInSeconds, hours, seconds] = [0, 0, 0]; let timeinSeconds = columnOfTd; diff --git a/browser-extensions/firefox/manifest.json b/browser-extensions/firefox/manifest.json index 5efa850..06df0a9 100644 --- a/browser-extensions/firefox/manifest.json +++ b/browser-extensions/firefox/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 2, "author": "Lee Wannacott", "name": "table-sort-js", - "version": "1.17.0", + "version": "1.17.1", "description": "Makes tables sortable using table-sort-js: https://github.com/LeeWannacott/table-sort-js", "icons": { "48": "icons/t.png" }, "browser_action": { diff --git a/browser-extensions/firefox/table-sort-js.zip b/browser-extensions/firefox/table-sort-js.zip index 91c195d..8ba0ca5 100644 Binary files a/browser-extensions/firefox/table-sort-js.zip and b/browser-extensions/firefox/table-sort-js.zip differ diff --git a/browser-extensions/firefox/table-sort.js b/browser-extensions/firefox/table-sort.js index a9a7e31..af0e6ab 100644 --- a/browser-extensions/firefox/table-sort.js +++ b/browser-extensions/firefox/table-sort.js @@ -17,13 +17,10 @@ Instructions: function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) { 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]; } const [getTagTable] = getHTMLTables(); @@ -35,12 +32,9 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) { } 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]); sortableTable.insertBefore(createTableHead, sortableTable.firstChild); } @@ -49,8 +43,8 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) { if (sortableTable.getElementsByTagName("thead").length === 0) { createMissingTableHead(sortableTable); 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 { return sortableTable.querySelectorAll("tbody"); } @@ -85,8 +79,8 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) { 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; inferableClasses[key].count++; } @@ -114,21 +108,21 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) { rows: [], headers: [], }; + for (let index of table.theads.keys()) { + table.headers.push(table.theads.item(index).querySelectorAll("th")); + } for (let index of table.bodies.keys()) { if (table.bodies.item(index) == null) { return; } - table.headers.push(table.theads.item(index).querySelectorAll("th")); table.rows.push(table.bodies.item(index).querySelectorAll("tr")); } - table.hasClass = { noClassInfer: sortableTable.classList.contains("no-class-infer"), cellsSort: sortableTable.classList.contains("cells-sort"), tableArrows: sortableTable.classList.contains("table-arrows"), rememberSort: sortableTable.classList.contains("remember-sort"), }; - for ( let headerIndex = 0; headerIndex < table.theads.length; @@ -244,19 +238,10 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) { const regexMinutesAndSeconds = /^(\d+h)?\s?(\d+m)?\s?(\d+s)?$/i; let columnOfTd = ""; // 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); let [minutesInSeconds, hours, seconds] = [0, 0, 0]; let timeinSeconds = columnOfTd; diff --git a/npm/package.json b/npm/package.json index 4c9ce6b..86a78e8 100644 --- a/npm/package.json +++ b/npm/package.json @@ -1,6 +1,6 @@ { "name": "table-sort-js", - "version": "1.17.0", + "version": "1.17.1", "description": "A JavaScript client-side HTML table sorting library with no dependencies required.", "license": "MIT", "repository": "LeeWannacott/table-sort-js", diff --git a/npm/table-sort.js b/npm/table-sort.js index a9a7e31..af0e6ab 100644 --- a/npm/table-sort.js +++ b/npm/table-sort.js @@ -17,13 +17,10 @@ Instructions: function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) { 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]; } const [getTagTable] = getHTMLTables(); @@ -35,12 +32,9 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) { } 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]); sortableTable.insertBefore(createTableHead, sortableTable.firstChild); } @@ -49,8 +43,8 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) { if (sortableTable.getElementsByTagName("thead").length === 0) { createMissingTableHead(sortableTable); 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 { return sortableTable.querySelectorAll("tbody"); } @@ -85,8 +79,8 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) { 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; inferableClasses[key].count++; } @@ -114,21 +108,21 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) { rows: [], headers: [], }; + for (let index of table.theads.keys()) { + table.headers.push(table.theads.item(index).querySelectorAll("th")); + } for (let index of table.bodies.keys()) { if (table.bodies.item(index) == null) { return; } - table.headers.push(table.theads.item(index).querySelectorAll("th")); table.rows.push(table.bodies.item(index).querySelectorAll("tr")); } - table.hasClass = { noClassInfer: sortableTable.classList.contains("no-class-infer"), cellsSort: sortableTable.classList.contains("cells-sort"), tableArrows: sortableTable.classList.contains("table-arrows"), rememberSort: sortableTable.classList.contains("remember-sort"), }; - for ( let headerIndex = 0; headerIndex < table.theads.length; @@ -244,19 +238,10 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) { const regexMinutesAndSeconds = /^(\d+h)?\s?(\d+m)?\s?(\d+s)?$/i; let columnOfTd = ""; // 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); let [minutesInSeconds, hours, seconds] = [0, 0, 0]; let timeinSeconds = columnOfTd; diff --git a/test/order-by-desc.test.js b/test/order-by-desc.test.js index 4181949..5e21725 100644 --- a/test/order-by-desc.test.js +++ b/test/order-by-desc.test.js @@ -3,7 +3,7 @@ const createTestTable = require("./table"); test("Alpha - Capitalized: order-by-desc", () => { expect( createTestTable( - { col0: {td: ["Echo", "Alpha", "Bravo", "Charlie", "Delta"] }}, + { col0: { td: ["Echo", "Alpha", "Bravo", "Charlie", "Delta"] } }, { classTags: "order-by-desc", } @@ -14,7 +14,7 @@ test("Alpha - Capitalized: order-by-desc", () => { test("Alpha - Lowercase: order-by-desc ", () => { expect( createTestTable( - { col0: {td: ["echo", "alpha", "bravo", "charlie", "delta"] }}, + { col0: { td: ["echo", "alpha", "bravo", "charlie", "delta"] } }, { classTags: "order-by-desc", } @@ -24,14 +24,17 @@ test("Alpha - Lowercase: order-by-desc ", () => { test("Numerical: order-by-desc", () => { expect( - createTestTable({ col0: {td:[5, 3, 4, 1, 2] }}, { classTags: "order-by-desc" }) + createTestTable( + { col0: { td: [5, 3, 4, 1, 2] } }, + { classTags: "order-by-desc" } + ) ).toStrictEqual({ col0: ["5", "4", "3", "2", "1"] }); }); test("Alphanumeric: order-by-desc", () => { expect( createTestTable( - { col0:{td: ["Alpha1", "Echo5", "Bravo2", "Charlie3", "Delta4"] }}, + { col0: { td: ["Alpha1", "Echo5", "Bravo2", "Charlie3", "Delta4"] } }, { classTags: "order-by-desc", } @@ -44,7 +47,11 @@ test("Alphanumeric: order-by-desc", () => { test("Dates: order-by-desc", () => { expect( createTestTable( - { col0: {td: ["1979/9/6", "2008/4/9", "1879/12/16", "1978/4/6", "1978/4/16"] }}, + { + col0: { + td: ["1979/9/6", "2008/4/9", "1879/12/16", "1978/4/6", "1978/4/16"], + }, + }, { classTags: "order-by-desc" } ) ).toStrictEqual({ @@ -55,7 +62,7 @@ test("Dates: order-by-desc", () => { test("Money: order-by-desc", () => { expect( createTestTable( - { col0: {td: ["$29", "$93", "$84", "$20", "$58"] }}, + { col0: { td: ["$29", "$93", "$84", "$20", "$58"] } }, { classTags: "order-by-desc", } @@ -66,7 +73,7 @@ test("Money: order-by-desc", () => { test("Empty cells sort at the end: order-by-desc", () => { expect( createTestTable( - { col0: {td: ["Echo", "", "Bravo", "", "Alpha"] }}, + { col0: { td: ["Echo", "", "Bravo", "", "Alpha"] } }, { classTags: "order-by-desc", } @@ -78,18 +85,20 @@ test("Order by file-size: file-size order-by-desc", () => { expect( createTestTable( { - col0: {td:[ - "10MB", - "10GB", - "10TB", - "10B", - "10MiB", - "10TiB", - "10Kib", - "10KB", - "10GiB", - ], - }}, + col0: { + td: [ + "10MB", + "10GB", + "10TB", + "10B", + "10MiB", + "10TiB", + "10Kib", + "10KB", + "10GiB", + ], + }, + }, { classTags: "order-by-desc file-size-sort" } ) ).toStrictEqual({ @@ -110,7 +119,7 @@ test("Order by file-size: file-size order-by-desc", () => { test("Floating point numbers: order-by-desc", () => { expect( createTestTable( - { col0: {td:[6.23, 0.25, 3.15, 9.09, 0.35] }}, + { col0: { td: [6.23, 0.25, 3.15, 9.09, 0.35] } }, { classTags: "order-by-desc", } @@ -121,7 +130,7 @@ test("Floating point numbers: order-by-desc", () => { test("Release Versions: order-by-desc", () => { expect( createTestTable( - { col0: {td: ["4.0.1", "3.0.2", "4.1.0", "3.0.4", "4.2.0"] }}, + { col0: { td: ["4.0.1", "3.0.2", "4.1.0", "3.0.4", "4.2.0"] } }, { classTags: "order-by-desc", } @@ -133,16 +142,18 @@ test("data-sort: example days of week - reversed", () => { expect( createTestTable( { - col0: {td:[ - "Saturday", - "Wednesday", - "Sunday", - "Friday", - "Thursday", - "Tuesday", - "Monday", - ], - }}, + col0: { + td: [ + "Saturday", + "Wednesday", + "Sunday", + "Friday", + "Thursday", + "Tuesday", + "Monday", + ], + }, + }, { classTags: "data-sort order-by-desc" } ) ).toStrictEqual({ @@ -162,14 +173,16 @@ test("visible-tr-sort: example sort only visible trs", () => { expect( createTestTable( { - col0: {td:[ - "row1", // invisible - "row2", - "row3", // invisible - "row4", - "row5", - ], - }}, + col0: { + td: [ + "row1", // invisible + "row2", + "row3", // invisible + "row4", + "row5", + ], + }, + }, { classTags: "order-by-desc" }, { invisibleIndex: [0, 2] } ) @@ -179,7 +192,7 @@ test("visible-tr-sort: example sort only visible trs", () => { test("onload-sort: testing that it sorts without a click from user", () => { expect( createTestTable( - { col0: {td: [5, 3, 4, 1, 2] }}, + { col0: { td: [5, 3, 4, 1, 2] } }, { classTags: "order-by-desc onload-sort" } ) ).toStrictEqual({ col0: ["5", "4", "3", "2", "1"] }); @@ -189,8 +202,8 @@ test("order-by-desc Remember-sort: Sorting cols without rememeber-sort class.", expect( createTestTable( { - col0: {td: ["charlie", "alpha", "beta"]}, - col1: {td: ["carrie", "doris", "fisher"]}, + col0: { td: ["charlie", "alpha", "beta"] }, + col1: { td: ["carrie", "doris", "fisher"] }, }, { classTags: "order-by-desc", @@ -210,8 +223,8 @@ test("order-by-desc Remember-sort: Sorting cols with rememeber-sort class.", () expect( createTestTable( { - col0: {td:["charlie", "alpha", "beta"]}, - col1: {td:["carrie", "doris", "fisher"]}, + col0: { td: ["charlie", "alpha", "beta"] }, + col1: { td: ["carrie", "doris", "fisher"] }, }, { classTags: "order-by-desc", diff --git a/test/table.test.js b/test/table.test.js index 5c3fae3..41d9721 100644 --- a/test/table.test.js +++ b/test/table.test.js @@ -5,7 +5,7 @@ const createTestTable = require("./table"); test("Alpha - Capitalized ", () => { expect( createTestTable( - { col0: {td: ["Echo", "Alpha", "Bravo", "Charlie", "Delta"]} }, + { col0: { td: ["Echo", "Alpha", "Bravo", "Charlie", "Delta"] } }, { classTags: "", } @@ -16,7 +16,7 @@ test("Alpha - Capitalized ", () => { test("Alpha - Lowercase", () => { expect( createTestTable( - { col0: {td:["echo", "alpha", "bravo", "charlie", "delta"]} }, + { col0: { td: ["echo", "alpha", "bravo", "charlie", "delta"] } }, { classTags: "", } @@ -26,14 +26,14 @@ test("Alpha - Lowercase", () => { test("Numerical", () => { expect( - createTestTable({ col0: {td: [5, 3, 4, 1, 2]} }, { classTags: "" }) + createTestTable({ col0: { td: [5, 3, 4, 1, 2] } }, { classTags: "" }) ).toStrictEqual({ col0: ["1", "2", "3", "4", "5"] }); }); test("Alphanumeric: natural sort", () => { expect( createTestTable( - { col0: {td:["Alpha1", "Echo5", "Bravo2", "Charlie3", "Delta4"]} }, + { col0: { td: ["Alpha1", "Echo5", "Bravo2", "Charlie3", "Delta4"] } }, { classTags: "", } @@ -46,7 +46,11 @@ test("Alphanumeric: natural sort", () => { test("Dates", () => { expect( createTestTable( - { col0: {td:["1979/9/6", "2008/4/9", "1879/12/16", "1978/4/6", "1978/4/16"]} }, + { + col0: { + td: ["1979/9/6", "2008/4/9", "1879/12/16", "1978/4/6", "1978/4/16"], + }, + }, { classTags: "" } ) ).toStrictEqual({ @@ -57,7 +61,7 @@ test("Dates", () => { test("Money", () => { expect( createTestTable( - { col0: {td: ["$29", "$93", "$84", "$20", "$58"]} }, + { col0: { td: ["$29", "$93", "$84", "$20", "$58"] } }, { classTags: "" } ) ).toStrictEqual({ col0: ["$20", "$29", "$58", "$84", "$93"] }); @@ -66,7 +70,7 @@ test("Money", () => { test("Empty cells sort at the end.", () => { expect( createTestTable( - { col0: {td: ["Echo", "", "Bravo", "", "Alpha"]} }, + { col0: { td: ["Echo", "", "Bravo", "", "Alpha"] } }, { classTags: "" } ) ).toStrictEqual({ col0: ["Alpha", "Bravo", "Echo", "", ""] }); @@ -75,7 +79,21 @@ test("Empty cells sort at the end.", () => { test("Order by file-size: file-size", () => { expect( createTestTable( - { col0: {td:[ "10MB", "10GB", "10TB", "10B", "10MiB", "10TiB", "10Kib", "10KB", "10GiB", ]}}, + { + col0: { + td: [ + "10MB", + "10GB", + "10TB", + "10B", + "10MiB", + "10TiB", + "10Kib", + "10KB", + "10GiB", + ], + }, + }, { classTags: "file-size-sort" } ) ).toStrictEqual({ @@ -98,7 +116,7 @@ test("Order by file-size: file-size", () => { test("Alpha - lower & upper", () => { expect( createTestTable( - { col0:{td: ["AlPhA", "bRaVo", "EcHo", "ChArLiE", "dElTa"] }}, + { col0: { td: ["AlPhA", "bRaVo", "EcHo", "ChArLiE", "dElTa"] } }, { classTags: "", } @@ -108,14 +126,19 @@ test("Alpha - lower & upper", () => { test("Floating point numbers", () => { expect( - createTestTable({ col0: {td: [6.23, 0.25, 3.15, 9.09, 0.35]} }, { classTags: "" }) + createTestTable( + { col0: { td: [6.23, 0.25, 3.15, 9.09, 0.35] } }, + { classTags: "" } + ) ).toStrictEqual({ col0: ["0.25", "0.35", "3.15", "6.23", "9.09"] }); }); test("Release Versions", () => { expect( createTestTable( - { col0: {td: ["4.18.0", "3.0.2", "4.1.0", "3.0.18", "4.2.0", "4.17.1"] }}, + { + col0: { td: ["4.18.0", "3.0.2", "4.1.0", "3.0.18", "4.2.0", "4.17.1"] }, + }, { classTags: "", } @@ -129,15 +152,17 @@ test("data-sort: example days of week", () => { expect( createTestTable( { - col0: {td:[ - "Saturday", - "Wednesday", - "Sunday", - "Friday", - "Thursday", - "Tuesday", - "Monday", - ],} + col0: { + td: [ + "Saturday", + "Wednesday", + "Sunday", + "Friday", + "Thursday", + "Tuesday", + "Monday", + ], + }, }, { classTags: "data-sort" } ) @@ -158,16 +183,18 @@ test("data-sort clicked twice: example days of week", () => { expect( createTestTable( { - col0: {td: [ - "Saturday", - "Wednesday", - "Sunday", - "Friday", - "Thursday", - "Tuesday", - "Monday", - ], - }}, + col0: { + td: [ + "Saturday", + "Wednesday", + "Sunday", + "Friday", + "Thursday", + "Tuesday", + "Monday", + ], + }, + }, { classTags: "data-sort" }, { colsToClick: [0, 0], @@ -189,7 +216,7 @@ test("data-sort clicked twice: example days of week", () => { test("disable-sort: disable sorting on a column", () => { expect( createTestTable( - { col0: {td: ["row2", "row1", "row4", "row3"]} }, + { col0: { td: ["row2", "row1", "row4", "row3"] } }, { classTags: "disable-sort", } @@ -200,7 +227,7 @@ test("disable-sort: disable sorting on a column", () => { test("alpha-sort: sort alphabetically as opposed to natural sorting", () => { expect( createTestTable( - { col0: {td: ["z2", "z11", "z89", "z82", "z8"]} }, + { col0: { td: ["z2", "z11", "z89", "z82", "z8"] } }, { classTags: "alpha-sort", } @@ -211,7 +238,7 @@ test("alpha-sort: sort alphabetically as opposed to natural sorting", () => { test("punc-sort: sort involving punctuation - nat sort", () => { expect( createTestTable( - { col0: {td: ["row2", "*row1", "-row4", "-row3", "#row3"]}}, + { col0: { td: ["row2", "*row1", "-row4", "-row3", "#row3"] } }, { classTags: "punct-sort", }, @@ -226,8 +253,8 @@ test("testing that multiple columns works", () => { expect( createTestTable( { - col0: {td: ["charlie", "alpha", "beta"]}, - col1:{td: ["doris", "carrie", "fisher"]}, + col0: { td: ["charlie", "alpha", "beta"] }, + col1: { td: ["doris", "carrie", "fisher"] }, }, { classTags: "", @@ -245,7 +272,7 @@ test("testing that multiple columns works", () => { test("onload-sort: testing that it sorts without a click from user", () => { expect( createTestTable( - { col0: {td:["echo", "alpha", "bravo", "charlie", "delta"] }}, + { col0: { td: ["echo", "alpha", "bravo", "charlie", "delta"] } }, { classTags: "onload-sort", } @@ -257,8 +284,8 @@ test("Clicking multiple times (>2) doesn't break sorting", () => { expect( createTestTable( { - col0: {td: ["charlie", "alpha", "beta"]}, - col1: {td: ["doris", "carrie", "fisher"]}, + col0: { td: ["charlie", "alpha", "beta"] }, + col1: { td: ["doris", "carrie", "fisher"] }, }, { classTags: "", @@ -277,8 +304,8 @@ test("Sorting columns without rememeber-sort ", () => { expect( createTestTable( { - col0:{td: ["charlie", "alpha", "beta"]}, - col1: {td:["doris", "carrie", "fisher"]}, + col0: { td: ["charlie", "alpha", "beta"] }, + col1: { td: ["doris", "carrie", "fisher"] }, }, { classTags: "", @@ -298,8 +325,8 @@ test("Remember-sort: Sorting cols that have the rememeber-sort class.", () => { expect( createTestTable( { - col0: {td: ["charlie", "alpha", "beta"]}, - col1: {td:["doris", "carrie", "fisher"]}, + col0: { td: ["charlie", "alpha", "beta"] }, + col1: { td: ["doris", "carrie", "fisher"] }, }, { classTags: "", @@ -319,8 +346,8 @@ test("Checking ", () => { expect( createTestTable( { - col0: {td: ["charlie", "alpha", "beta"]}, - col1: {td: ["doris", "carrie", "fisher"]}, + col0: { td: ["charlie", "alpha", "beta"] }, + col1: { td: ["doris", "carrie", "fisher"] }, }, { classTags: "", @@ -340,20 +367,22 @@ test("runtime-sort", () => { expect( createTestTable( { - col0: {td:[ - "2m 52s", - "1h 20m 10s", - "3s", - "11h 10m 10s", - "7s", - "11m 40s", - "36s", - "1h 10m 10s", - "9m 44s", - "1m 36s", - "41s", - ], - }}, + col0: { + td: [ + "2m 52s", + "1h 20m 10s", + "3s", + "11h 10m 10s", + "7s", + "11m 40s", + "36s", + "1h 10m 10s", + "9m 44s", + "1m 36s", + "41s", + ], + }, + }, { classTags: "runtime-sort", }, @@ -382,18 +411,20 @@ test("dates-dmy-sort: UK style dd/mm/yyyy; delim . or / or -", () => { expect( createTestTable( { - col0: {td: [ - "17/6/1978", - "18.10.2027", - "10-12-2017", - "13/12/2017", - "4.9.2008", - "2.3.1879", - "22.3.1879", - "8/6/1978", - "4/6/1978", - ], - }}, + col0: { + td: [ + "17/6/1978", + "18.10.2027", + "10-12-2017", + "13/12/2017", + "4.9.2008", + "2.3.1879", + "22.3.1879", + "8/6/1978", + "4/6/1978", + ], + }, + }, { classTags: "dates-dmy-sort" } ) ).toStrictEqual({ @@ -415,15 +446,17 @@ test("dates-mdy-sort: US style mm/dd/yyyy; delim . or / or -", () => { expect( createTestTable( { - col0: {td: [ - "1-14-1992", - "1.13.1992", - "4.30.2008", - "1/20/1992", - "10-12-2017", - "2/14/1992", - ], - }}, + col0: { + td: [ + "1-14-1992", + "1.13.1992", + "4.30.2008", + "1/20/1992", + "10-12-2017", + "2/14/1992", + ], + }, + }, { classTags: "dates-mdy-sort" } ) ).toStrictEqual({ @@ -442,15 +475,17 @@ test("dates-mdy-sort US style overrides inferred class dates-dmy-sort:", () => { expect( createTestTable( { - col0: {td: [ - "1-14-1992", - "1.13.1992", - "4.30.2008", - "1/20/1992", - "10-12-2017", - "2/14/1992", - ], - }}, + col0: { + td: [ + "1-14-1992", + "1.13.1992", + "4.30.2008", + "1/20/1992", + "10-12-2017", + "2/14/1992", + ], + }, + }, { classTags: "dates-mdy-sort dates-dmy-sort" } ) ).toStrictEqual({ @@ -469,7 +504,9 @@ test("dates-ymd-sort: ISO 8601 style yyyy/mm/dd; delim . or / or -", () => { expect( createTestTable( { - col0: {td: ["2023/09/6", "2023-03-9", "2023.12.16", "2023/4/6", "2023/4/32"]}, + col0: { + td: ["2023/09/6", "2023-03-9", "2023.12.16", "2023/4/6", "2023/4/32"], + }, }, { classTags: "dates-ymd-sort" } ) @@ -482,7 +519,7 @@ test("Sort decimal numbers", () => { expect( createTestTable( { - col0: {td: ["0.1", "0.2", "0.3", "0.11", "0.13", "0.13", "0.14"]}, + col0: { td: ["0.1", "0.2", "0.3", "0.11", "0.13", "0.13", "0.14"] }, }, { classTags: "numeric-sort" } ) @@ -495,7 +532,7 @@ test("Sort all combination positive, negative numbers with parenthesis as well", expect( createTestTable( { - col0: {td:["1.05", "-2.3", "-3", "1", "-6", "(1.4)", "14"]}, + col0: { td: ["1.05", "-2.3", "-3", "1", "-6", "(1.4)", "14"] }, }, { classTags: "numeric-sort" } ) @@ -508,19 +545,21 @@ test("Sort all combination of negative and positive integers and decimal numbers expect( createTestTable( { - col0: {td:[ - "1.05", - "-2.3", - "-3", - "1", - "-6", - "", - "(0.5)", - "1a", - "b", - "(c)", - "{1}", - ]}, + col0: { + td: [ + "1.05", + "-2.3", + "-3", + "1", + "-6", + "", + "(0.5)", + "1a", + "b", + "(c)", + "{1}", + ], + }, }, { classTags: "numeric-sort" } ) @@ -545,7 +584,7 @@ test("default behavior without cells-sort (tr's move when sorted)", () => { expect( createTestTable( { - col0: {td: ["8", "2", "3", "4", "5", "6", "0", "1", "7"]}, + col0: { td: ["8", "2", "3", "4", "5", "6", "0", "1", "7"] }, }, { classTags: "" }, // note this isn't an actual class just used for testing purposes @@ -570,7 +609,7 @@ test("cells-sort table class (tr's stay in place, but td's are sorted)", () => { expect( createTestTable( { - col0: {td: ["8", "2", "3", "4", "5", "6", "0", "1", "7"]}, + col0: { td: ["8", "2", "3", "4", "5", "6", "0", "1", "7"] }, }, { classTags: "" }, { tableTags: "cells-sort", trClasses: "test" } @@ -590,30 +629,29 @@ test("cells-sort table class (tr's stay in place, but td's are sorted)", () => { }); }); - -// +// // test("colspan", () => { - // expect( - // createTestTable( - // { - // col0: {td:["8", "2", "3", "4", "5", "6", "0", "1", "7"]}, - // col1: {td:["8", "2", "3", "4", "5", "6", "0", "1", "7"]}, - // col2: {td:["8", "2", "3", "4", "5", "6", "0", "1", "7"]}, - // }, - // { classTags: "data-sort" }, - // { tableTags: "tr-sort", trClasses: "test" } - // ) - // ).toStrictEqual({ - // col0: [ - // '