diff --git a/README.md b/README.md
index 4f08254..0acc86a 100644
--- a/README.md
+++ b/README.md
@@ -61,12 +61,12 @@ Examples on using table-sort-js with frontend frameworks such as [React.js](http
-| <th> classes | Description |
-| ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------- |
-| "data-sort" | Sort by [data attributes](https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes), e.g <td data-sort="42">. Useful for doing custom sorts. |
-| "dates-mdy-sort" | Sorts dates in US style mm/dd/yyyy format;. e.g (12/28/2023). Can use "/" or "-" as separator. Overides inferred "dates-dmy-sort" class. |
-| "onload-sort" | Sort column on loading of the page. Simulates a click from the user. (can only sort onload for one column) |
-| "disable-sort" | Disallow sorting the table by this specific column. |
+| <th> classes | Description |
+| ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| "data-sort" | Sort by [data attributes](https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes), e.g <td data-sort="42">. Useful for doing custom sorts. |
+| "dates-mdy-sort" | Sorts dates in US style mm/dd/yyyy format;. e.g (12/28/2023). Can use "/" or "-" as separator. Overides inferred "dates-dmy-sort" class. |
+| "onload-sort" | Sort column on loading of the page. Simulates a click from the user. (can only sort onload for one column) |
+| "disable-sort" | Disallow sorting the table by this specific column. |
diff --git a/browser-extensions/chrome/manifest.json b/browser-extensions/chrome/manifest.json
index 2268f05..49e8ee5 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.18.0",
+ "version": "1.18.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 435b1f8..c04a81d 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 455c4d2..1a9a2c0 100644
--- a/browser-extensions/chrome/table-sort.js
+++ b/browser-extensions/chrome/table-sort.js
@@ -55,57 +55,61 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
}
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;
- // 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+)?)$/; doesn't handle commas
- const numericRegex =
- /^-?(?:\d{1,3}(?:[',]\d{3})*(?:\.\d+)?|\d+(?:\.\d+)?(?:[',]\d{3})*?)$/;
- const inferableClasses = {
- runtime: { regexp: runtimeRegex, class: "runtime-sort", count: 0 },
- filesize: { regexp: fileSizeRegex, class: "file-size-sort", count: 0 },
- dmyDates: { regexp: dmyRegex, class: "dates-dmy-sort", count: 0 },
- ymdDates: { regexp: ymdRegex, class: "dates-ymd-sort", count: 0 },
- numericRegex: { regexp: numericRegex, class: "numeric-sort", count: 0 },
- };
- let classNameAdded = false;
- let regexNotFoundCount = 0;
- const threshold = Math.ceil(tableRows.length / 2);
- for (let tr of tableRows) {
- if (regexNotFoundCount >= threshold) {
- break;
- }
- 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 !== undefined) {
- if (tableColumn.innerText.match(classRegexp)) {
- foundMatch = true;
- inferableClasses[key].count++;
+ try {
+ 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;
+ // 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+)?)$/; doesn't handle commas
+ const numericRegex =
+ /^-?(?:\d{1,3}(?:[',]\d{3})*(?:\.\d+)?|\d+(?:\.\d+)?(?:[',]\d{3})*?)$/;
+ const inferableClasses = {
+ runtime: { regexp: runtimeRegex, class: "runtime-sort", count: 0 },
+ filesize: { regexp: fileSizeRegex, class: "file-size-sort", count: 0 },
+ dmyDates: { regexp: dmyRegex, class: "dates-dmy-sort", count: 0 },
+ ymdDates: { regexp: ymdRegex, class: "dates-ymd-sort", count: 0 },
+ numericRegex: { regexp: numericRegex, class: "numeric-sort", count: 0 },
+ };
+ let classNameAdded = false;
+ let regexNotFoundCount = 0;
+ const threshold = Math.ceil(tableRows.length / 2);
+ for (let tr of tableRows) {
+ if (regexNotFoundCount >= threshold) {
+ break;
+ }
+ 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 !== undefined) {
+ if (tableColumn.innerText.match(classRegexp)) {
+ foundMatch = true;
+ inferableClasses[key].count++;
+ }
+ }
+ if (inferableClasses[key].count >= threshold) {
+ th.classList.add(inferableClasses[key].class);
+ classNameAdded = true;
+ break;
}
}
- if (inferableClasses[key].count >= threshold) {
- th.classList.add(inferableClasses[key].class);
- classNameAdded = true;
+ if (classNameAdded) {
break;
}
+ if (!foundMatch) {
+ regexNotFoundCount++;
+ continue;
+ }
}
- if (classNameAdded) {
- break;
- }
- if (!foundMatch) {
- regexNotFoundCount++;
- continue;
- }
+ } catch (e) {
+ console.log(e);
}
}
diff --git a/browser-extensions/firefox/manifest.json b/browser-extensions/firefox/manifest.json
index 354896d..e9af1a3 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.18.0",
+ "version": "1.18.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 5a70363..efd4576 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 455c4d2..1a9a2c0 100644
--- a/browser-extensions/firefox/table-sort.js
+++ b/browser-extensions/firefox/table-sort.js
@@ -55,57 +55,61 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
}
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;
- // 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+)?)$/; doesn't handle commas
- const numericRegex =
- /^-?(?:\d{1,3}(?:[',]\d{3})*(?:\.\d+)?|\d+(?:\.\d+)?(?:[',]\d{3})*?)$/;
- const inferableClasses = {
- runtime: { regexp: runtimeRegex, class: "runtime-sort", count: 0 },
- filesize: { regexp: fileSizeRegex, class: "file-size-sort", count: 0 },
- dmyDates: { regexp: dmyRegex, class: "dates-dmy-sort", count: 0 },
- ymdDates: { regexp: ymdRegex, class: "dates-ymd-sort", count: 0 },
- numericRegex: { regexp: numericRegex, class: "numeric-sort", count: 0 },
- };
- let classNameAdded = false;
- let regexNotFoundCount = 0;
- const threshold = Math.ceil(tableRows.length / 2);
- for (let tr of tableRows) {
- if (regexNotFoundCount >= threshold) {
- break;
- }
- 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 !== undefined) {
- if (tableColumn.innerText.match(classRegexp)) {
- foundMatch = true;
- inferableClasses[key].count++;
+ try {
+ 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;
+ // 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+)?)$/; doesn't handle commas
+ const numericRegex =
+ /^-?(?:\d{1,3}(?:[',]\d{3})*(?:\.\d+)?|\d+(?:\.\d+)?(?:[',]\d{3})*?)$/;
+ const inferableClasses = {
+ runtime: { regexp: runtimeRegex, class: "runtime-sort", count: 0 },
+ filesize: { regexp: fileSizeRegex, class: "file-size-sort", count: 0 },
+ dmyDates: { regexp: dmyRegex, class: "dates-dmy-sort", count: 0 },
+ ymdDates: { regexp: ymdRegex, class: "dates-ymd-sort", count: 0 },
+ numericRegex: { regexp: numericRegex, class: "numeric-sort", count: 0 },
+ };
+ let classNameAdded = false;
+ let regexNotFoundCount = 0;
+ const threshold = Math.ceil(tableRows.length / 2);
+ for (let tr of tableRows) {
+ if (regexNotFoundCount >= threshold) {
+ break;
+ }
+ 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 !== undefined) {
+ if (tableColumn.innerText.match(classRegexp)) {
+ foundMatch = true;
+ inferableClasses[key].count++;
+ }
+ }
+ if (inferableClasses[key].count >= threshold) {
+ th.classList.add(inferableClasses[key].class);
+ classNameAdded = true;
+ break;
}
}
- if (inferableClasses[key].count >= threshold) {
- th.classList.add(inferableClasses[key].class);
- classNameAdded = true;
+ if (classNameAdded) {
break;
}
+ if (!foundMatch) {
+ regexNotFoundCount++;
+ continue;
+ }
}
- if (classNameAdded) {
- break;
- }
- if (!foundMatch) {
- regexNotFoundCount++;
- continue;
- }
+ } catch (e) {
+ console.log(e);
}
}
diff --git a/npm/README.md b/npm/README.md
index 37ca0b9..0acc86a 100644
--- a/npm/README.md
+++ b/npm/README.md
@@ -61,12 +61,12 @@ Examples on using table-sort-js with frontend frameworks such as [React.js](http
-| <th> classes | Description |
-| ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------- |
-| "data-sort" | Sort by [data attributes](https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes), e.g <td data-sort="42"> |
-| "dates-mdy-sort" | Sorts dates in US style mm/dd/yyyy format;. e.g (12/28/2023). Can use "/" or "-" as separator. Overides inferred "dates-dmy-sort" class. |
-| "onload-sort" | Sort column on loading of the page. Simulates a click from the user. (can only sort onload for one column) |
-| "disable-sort" | Disallow sorting the table by this specific column. |
+| <th> classes | Description |
+| ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| "data-sort" | Sort by [data attributes](https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes), e.g <td data-sort="42">. Useful for doing custom sorts. |
+| "dates-mdy-sort" | Sorts dates in US style mm/dd/yyyy format;. e.g (12/28/2023). Can use "/" or "-" as separator. Overides inferred "dates-dmy-sort" class. |
+| "onload-sort" | Sort column on loading of the page. Simulates a click from the user. (can only sort onload for one column) |
+| "disable-sort" | Disallow sorting the table by this specific column. |
diff --git a/npm/package.json b/npm/package.json
index 880a314..0a910a8 100644
--- a/npm/package.json
+++ b/npm/package.json
@@ -1,6 +1,6 @@
{
"name": "table-sort-js",
- "version": "1.18.0",
+ "version": "1.18.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 455c4d2..1a9a2c0 100644
--- a/npm/table-sort.js
+++ b/npm/table-sort.js
@@ -55,57 +55,61 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
}
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;
- // 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+)?)$/; doesn't handle commas
- const numericRegex =
- /^-?(?:\d{1,3}(?:[',]\d{3})*(?:\.\d+)?|\d+(?:\.\d+)?(?:[',]\d{3})*?)$/;
- const inferableClasses = {
- runtime: { regexp: runtimeRegex, class: "runtime-sort", count: 0 },
- filesize: { regexp: fileSizeRegex, class: "file-size-sort", count: 0 },
- dmyDates: { regexp: dmyRegex, class: "dates-dmy-sort", count: 0 },
- ymdDates: { regexp: ymdRegex, class: "dates-ymd-sort", count: 0 },
- numericRegex: { regexp: numericRegex, class: "numeric-sort", count: 0 },
- };
- let classNameAdded = false;
- let regexNotFoundCount = 0;
- const threshold = Math.ceil(tableRows.length / 2);
- for (let tr of tableRows) {
- if (regexNotFoundCount >= threshold) {
- break;
- }
- 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 !== undefined) {
- if (tableColumn.innerText.match(classRegexp)) {
- foundMatch = true;
- inferableClasses[key].count++;
+ try {
+ 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;
+ // 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+)?)$/; doesn't handle commas
+ const numericRegex =
+ /^-?(?:\d{1,3}(?:[',]\d{3})*(?:\.\d+)?|\d+(?:\.\d+)?(?:[',]\d{3})*?)$/;
+ const inferableClasses = {
+ runtime: { regexp: runtimeRegex, class: "runtime-sort", count: 0 },
+ filesize: { regexp: fileSizeRegex, class: "file-size-sort", count: 0 },
+ dmyDates: { regexp: dmyRegex, class: "dates-dmy-sort", count: 0 },
+ ymdDates: { regexp: ymdRegex, class: "dates-ymd-sort", count: 0 },
+ numericRegex: { regexp: numericRegex, class: "numeric-sort", count: 0 },
+ };
+ let classNameAdded = false;
+ let regexNotFoundCount = 0;
+ const threshold = Math.ceil(tableRows.length / 2);
+ for (let tr of tableRows) {
+ if (regexNotFoundCount >= threshold) {
+ break;
+ }
+ 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 !== undefined) {
+ if (tableColumn.innerText.match(classRegexp)) {
+ foundMatch = true;
+ inferableClasses[key].count++;
+ }
+ }
+ if (inferableClasses[key].count >= threshold) {
+ th.classList.add(inferableClasses[key].class);
+ classNameAdded = true;
+ break;
}
}
- if (inferableClasses[key].count >= threshold) {
- th.classList.add(inferableClasses[key].class);
- classNameAdded = true;
+ if (classNameAdded) {
break;
}
+ if (!foundMatch) {
+ regexNotFoundCount++;
+ continue;
+ }
}
- if (classNameAdded) {
- break;
- }
- if (!foundMatch) {
- regexNotFoundCount++;
- continue;
- }
+ } catch (e) {
+ console.log(e);
}
}