Skip to content

Commit 38e9c54

Browse files
npm release 1.18.1; fix optional chaining being used that breaks babel loader.
1 parent dfd454b commit 38e9c54

File tree

10 files changed

+165
-153
lines changed

10 files changed

+165
-153
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ Examples on using table-sort-js with frontend frameworks such as [React.js](http
6161

6262
<br>
6363

64-
| &lt;th&gt; classes | Description |
65-
| ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------- |
66-
| "data-sort" | Sort by [data attributes](https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes), e.g &lt;td data-sort="42"&gt;. Useful for doing custom sorts. |
67-
| "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. |
68-
| "onload-sort" | Sort column on loading of the page. Simulates a click from the user. (can only sort onload for one column) |
69-
| "disable-sort" | Disallow sorting the table by this specific column. |
64+
| &lt;th&gt; classes | Description |
65+
| ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
66+
| "data-sort" | Sort by [data attributes](https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes), e.g &lt;td data-sort="42"&gt;. Useful for doing custom sorts. |
67+
| "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. |
68+
| "onload-sort" | Sort column on loading of the page. Simulates a click from the user. (can only sort onload for one column) |
69+
| "disable-sort" | Disallow sorting the table by this specific column. |
7070

7171
<br>
7272

browser-extensions/chrome/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"manifest_version": 3,
33
"author": "Lee Wannacott",
44
"name": "table-sort-js",
5-
"version": "1.18.0",
5+
"version": "1.18.1",
66
"description": "Makes tables sortable using table-sort-js: https://github.com/LeeWannacott/table-sort-js",
77
"icons": { "48": "icons/t.png" },
88
"browser_action": {
-4 Bytes
Binary file not shown.

browser-extensions/chrome/table-sort.js

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -55,57 +55,61 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
5555
}
5656

5757
function inferSortClasses(tableRows, columnIndex, column, th) {
58-
const runtimeRegex = /^(\d+h)?\s?(\d+m)?\s?(\d+s)?$/i;
59-
const fileSizeRegex = /^([.0-9]+)\s?(B|KB|KiB|MB|MiB|GB|GiB|TB|TiB)/i;
60-
// Don't infer dates with delimiter "."; as could capture semantic version numbers.
61-
const dmyRegex = /^(\d\d?)[/-](\d\d?)[/-]((\d\d)?\d\d)/;
62-
const ymdRegex = /^(\d\d\d\d)[/-](\d\d?)[/-](\d\d?)/;
63-
// const numericRegex = /^(?:\(\d+(?:\.\d+)?\)|-?\d+(?:\.\d+)?)$/; doesn't handle commas
64-
const numericRegex =
65-
/^-?(?:\d{1,3}(?:[',]\d{3})*(?:\.\d+)?|\d+(?:\.\d+)?(?:[',]\d{3})*?)$/;
66-
const inferableClasses = {
67-
runtime: { regexp: runtimeRegex, class: "runtime-sort", count: 0 },
68-
filesize: { regexp: fileSizeRegex, class: "file-size-sort", count: 0 },
69-
dmyDates: { regexp: dmyRegex, class: "dates-dmy-sort", count: 0 },
70-
ymdDates: { regexp: ymdRegex, class: "dates-ymd-sort", count: 0 },
71-
numericRegex: { regexp: numericRegex, class: "numeric-sort", count: 0 },
72-
};
73-
let classNameAdded = false;
74-
let regexNotFoundCount = 0;
75-
const threshold = Math.ceil(tableRows.length / 2);
76-
for (let tr of tableRows) {
77-
if (regexNotFoundCount >= threshold) {
78-
break;
79-
}
80-
const tableColumn = tr
81-
.querySelectorAll("td")
82-
.item(
83-
column.span[columnIndex] === 1
84-
? column.spanSum[columnIndex] - 1
85-
: column.spanSum[columnIndex] - column.span[columnIndex]
86-
);
87-
let foundMatch = false;
88-
for (let key of Object.keys(inferableClasses)) {
89-
let classRegexp = inferableClasses[key].regexp;
90-
if (tableColumn?.innerText !== undefined) {
91-
if (tableColumn.innerText.match(classRegexp)) {
92-
foundMatch = true;
93-
inferableClasses[key].count++;
58+
try {
59+
const runtimeRegex = /^(\d+h)?\s?(\d+m)?\s?(\d+s)?$/i;
60+
const fileSizeRegex = /^([.0-9]+)\s?(B|KB|KiB|MB|MiB|GB|GiB|TB|TiB)/i;
61+
// Don't infer dates with delimiter "."; as could capture semantic version numbers.
62+
const dmyRegex = /^(\d\d?)[/-](\d\d?)[/-]((\d\d)?\d\d)/;
63+
const ymdRegex = /^(\d\d\d\d)[/-](\d\d?)[/-](\d\d?)/;
64+
// const numericRegex = /^(?:\(\d+(?:\.\d+)?\)|-?\d+(?:\.\d+)?)$/; doesn't handle commas
65+
const numericRegex =
66+
/^-?(?:\d{1,3}(?:[',]\d{3})*(?:\.\d+)?|\d+(?:\.\d+)?(?:[',]\d{3})*?)$/;
67+
const inferableClasses = {
68+
runtime: { regexp: runtimeRegex, class: "runtime-sort", count: 0 },
69+
filesize: { regexp: fileSizeRegex, class: "file-size-sort", count: 0 },
70+
dmyDates: { regexp: dmyRegex, class: "dates-dmy-sort", count: 0 },
71+
ymdDates: { regexp: ymdRegex, class: "dates-ymd-sort", count: 0 },
72+
numericRegex: { regexp: numericRegex, class: "numeric-sort", count: 0 },
73+
};
74+
let classNameAdded = false;
75+
let regexNotFoundCount = 0;
76+
const threshold = Math.ceil(tableRows.length / 2);
77+
for (let tr of tableRows) {
78+
if (regexNotFoundCount >= threshold) {
79+
break;
80+
}
81+
const tableColumn = tr
82+
.querySelectorAll("td")
83+
.item(
84+
column.span[columnIndex] === 1
85+
? column.spanSum[columnIndex] - 1
86+
: column.spanSum[columnIndex] - column.span[columnIndex]
87+
);
88+
let foundMatch = false;
89+
for (let key of Object.keys(inferableClasses)) {
90+
let classRegexp = inferableClasses[key].regexp;
91+
if (tableColumn.innerText !== undefined) {
92+
if (tableColumn.innerText.match(classRegexp)) {
93+
foundMatch = true;
94+
inferableClasses[key].count++;
95+
}
96+
}
97+
if (inferableClasses[key].count >= threshold) {
98+
th.classList.add(inferableClasses[key].class);
99+
classNameAdded = true;
100+
break;
94101
}
95102
}
96-
if (inferableClasses[key].count >= threshold) {
97-
th.classList.add(inferableClasses[key].class);
98-
classNameAdded = true;
103+
if (classNameAdded) {
99104
break;
100105
}
106+
if (!foundMatch) {
107+
regexNotFoundCount++;
108+
continue;
109+
}
101110
}
102-
if (classNameAdded) {
103-
break;
104-
}
105-
if (!foundMatch) {
106-
regexNotFoundCount++;
107-
continue;
108-
}
111+
} catch (e) {
112+
console.log(e);
109113
}
110114
}
111115

browser-extensions/firefox/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"manifest_version": 2,
33
"author": "Lee Wannacott",
44
"name": "table-sort-js",
5-
"version": "1.18.0",
5+
"version": "1.18.1",
66
"description": "Makes tables sortable using table-sort-js: https://github.com/LeeWannacott/table-sort-js",
77
"icons": { "48": "icons/t.png" },
88
"browser_action": {
-4 Bytes
Binary file not shown.

browser-extensions/firefox/table-sort.js

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -55,57 +55,61 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
5555
}
5656

5757
function inferSortClasses(tableRows, columnIndex, column, th) {
58-
const runtimeRegex = /^(\d+h)?\s?(\d+m)?\s?(\d+s)?$/i;
59-
const fileSizeRegex = /^([.0-9]+)\s?(B|KB|KiB|MB|MiB|GB|GiB|TB|TiB)/i;
60-
// Don't infer dates with delimiter "."; as could capture semantic version numbers.
61-
const dmyRegex = /^(\d\d?)[/-](\d\d?)[/-]((\d\d)?\d\d)/;
62-
const ymdRegex = /^(\d\d\d\d)[/-](\d\d?)[/-](\d\d?)/;
63-
// const numericRegex = /^(?:\(\d+(?:\.\d+)?\)|-?\d+(?:\.\d+)?)$/; doesn't handle commas
64-
const numericRegex =
65-
/^-?(?:\d{1,3}(?:[',]\d{3})*(?:\.\d+)?|\d+(?:\.\d+)?(?:[',]\d{3})*?)$/;
66-
const inferableClasses = {
67-
runtime: { regexp: runtimeRegex, class: "runtime-sort", count: 0 },
68-
filesize: { regexp: fileSizeRegex, class: "file-size-sort", count: 0 },
69-
dmyDates: { regexp: dmyRegex, class: "dates-dmy-sort", count: 0 },
70-
ymdDates: { regexp: ymdRegex, class: "dates-ymd-sort", count: 0 },
71-
numericRegex: { regexp: numericRegex, class: "numeric-sort", count: 0 },
72-
};
73-
let classNameAdded = false;
74-
let regexNotFoundCount = 0;
75-
const threshold = Math.ceil(tableRows.length / 2);
76-
for (let tr of tableRows) {
77-
if (regexNotFoundCount >= threshold) {
78-
break;
79-
}
80-
const tableColumn = tr
81-
.querySelectorAll("td")
82-
.item(
83-
column.span[columnIndex] === 1
84-
? column.spanSum[columnIndex] - 1
85-
: column.spanSum[columnIndex] - column.span[columnIndex]
86-
);
87-
let foundMatch = false;
88-
for (let key of Object.keys(inferableClasses)) {
89-
let classRegexp = inferableClasses[key].regexp;
90-
if (tableColumn?.innerText !== undefined) {
91-
if (tableColumn.innerText.match(classRegexp)) {
92-
foundMatch = true;
93-
inferableClasses[key].count++;
58+
try {
59+
const runtimeRegex = /^(\d+h)?\s?(\d+m)?\s?(\d+s)?$/i;
60+
const fileSizeRegex = /^([.0-9]+)\s?(B|KB|KiB|MB|MiB|GB|GiB|TB|TiB)/i;
61+
// Don't infer dates with delimiter "."; as could capture semantic version numbers.
62+
const dmyRegex = /^(\d\d?)[/-](\d\d?)[/-]((\d\d)?\d\d)/;
63+
const ymdRegex = /^(\d\d\d\d)[/-](\d\d?)[/-](\d\d?)/;
64+
// const numericRegex = /^(?:\(\d+(?:\.\d+)?\)|-?\d+(?:\.\d+)?)$/; doesn't handle commas
65+
const numericRegex =
66+
/^-?(?:\d{1,3}(?:[',]\d{3})*(?:\.\d+)?|\d+(?:\.\d+)?(?:[',]\d{3})*?)$/;
67+
const inferableClasses = {
68+
runtime: { regexp: runtimeRegex, class: "runtime-sort", count: 0 },
69+
filesize: { regexp: fileSizeRegex, class: "file-size-sort", count: 0 },
70+
dmyDates: { regexp: dmyRegex, class: "dates-dmy-sort", count: 0 },
71+
ymdDates: { regexp: ymdRegex, class: "dates-ymd-sort", count: 0 },
72+
numericRegex: { regexp: numericRegex, class: "numeric-sort", count: 0 },
73+
};
74+
let classNameAdded = false;
75+
let regexNotFoundCount = 0;
76+
const threshold = Math.ceil(tableRows.length / 2);
77+
for (let tr of tableRows) {
78+
if (regexNotFoundCount >= threshold) {
79+
break;
80+
}
81+
const tableColumn = tr
82+
.querySelectorAll("td")
83+
.item(
84+
column.span[columnIndex] === 1
85+
? column.spanSum[columnIndex] - 1
86+
: column.spanSum[columnIndex] - column.span[columnIndex]
87+
);
88+
let foundMatch = false;
89+
for (let key of Object.keys(inferableClasses)) {
90+
let classRegexp = inferableClasses[key].regexp;
91+
if (tableColumn.innerText !== undefined) {
92+
if (tableColumn.innerText.match(classRegexp)) {
93+
foundMatch = true;
94+
inferableClasses[key].count++;
95+
}
96+
}
97+
if (inferableClasses[key].count >= threshold) {
98+
th.classList.add(inferableClasses[key].class);
99+
classNameAdded = true;
100+
break;
94101
}
95102
}
96-
if (inferableClasses[key].count >= threshold) {
97-
th.classList.add(inferableClasses[key].class);
98-
classNameAdded = true;
103+
if (classNameAdded) {
99104
break;
100105
}
106+
if (!foundMatch) {
107+
regexNotFoundCount++;
108+
continue;
109+
}
101110
}
102-
if (classNameAdded) {
103-
break;
104-
}
105-
if (!foundMatch) {
106-
regexNotFoundCount++;
107-
continue;
108-
}
111+
} catch (e) {
112+
console.log(e);
109113
}
110114
}
111115

npm/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ Examples on using table-sort-js with frontend frameworks such as [React.js](http
6161

6262
<br>
6363

64-
| &lt;th&gt; classes | Description |
65-
| ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------- |
66-
| "data-sort" | Sort by [data attributes](https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes), e.g &lt;td data-sort="42"&gt; |
67-
| "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. |
68-
| "onload-sort" | Sort column on loading of the page. Simulates a click from the user. (can only sort onload for one column) |
69-
| "disable-sort" | Disallow sorting the table by this specific column. |
64+
| &lt;th&gt; classes | Description |
65+
| ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
66+
| "data-sort" | Sort by [data attributes](https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes), e.g &lt;td data-sort="42"&gt;. Useful for doing custom sorts. |
67+
| "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. |
68+
| "onload-sort" | Sort column on loading of the page. Simulates a click from the user. (can only sort onload for one column) |
69+
| "disable-sort" | Disallow sorting the table by this specific column. |
7070

7171
<br>
7272

npm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "table-sort-js",
3-
"version": "1.18.0",
3+
"version": "1.18.1",
44
"description": "A JavaScript client-side HTML table sorting library with no dependencies required.",
55
"license": "MIT",
66
"repository": "LeeWannacott/table-sort-js",

npm/table-sort.js

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -55,57 +55,61 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
5555
}
5656

5757
function inferSortClasses(tableRows, columnIndex, column, th) {
58-
const runtimeRegex = /^(\d+h)?\s?(\d+m)?\s?(\d+s)?$/i;
59-
const fileSizeRegex = /^([.0-9]+)\s?(B|KB|KiB|MB|MiB|GB|GiB|TB|TiB)/i;
60-
// Don't infer dates with delimiter "."; as could capture semantic version numbers.
61-
const dmyRegex = /^(\d\d?)[/-](\d\d?)[/-]((\d\d)?\d\d)/;
62-
const ymdRegex = /^(\d\d\d\d)[/-](\d\d?)[/-](\d\d?)/;
63-
// const numericRegex = /^(?:\(\d+(?:\.\d+)?\)|-?\d+(?:\.\d+)?)$/; doesn't handle commas
64-
const numericRegex =
65-
/^-?(?:\d{1,3}(?:[',]\d{3})*(?:\.\d+)?|\d+(?:\.\d+)?(?:[',]\d{3})*?)$/;
66-
const inferableClasses = {
67-
runtime: { regexp: runtimeRegex, class: "runtime-sort", count: 0 },
68-
filesize: { regexp: fileSizeRegex, class: "file-size-sort", count: 0 },
69-
dmyDates: { regexp: dmyRegex, class: "dates-dmy-sort", count: 0 },
70-
ymdDates: { regexp: ymdRegex, class: "dates-ymd-sort", count: 0 },
71-
numericRegex: { regexp: numericRegex, class: "numeric-sort", count: 0 },
72-
};
73-
let classNameAdded = false;
74-
let regexNotFoundCount = 0;
75-
const threshold = Math.ceil(tableRows.length / 2);
76-
for (let tr of tableRows) {
77-
if (regexNotFoundCount >= threshold) {
78-
break;
79-
}
80-
const tableColumn = tr
81-
.querySelectorAll("td")
82-
.item(
83-
column.span[columnIndex] === 1
84-
? column.spanSum[columnIndex] - 1
85-
: column.spanSum[columnIndex] - column.span[columnIndex]
86-
);
87-
let foundMatch = false;
88-
for (let key of Object.keys(inferableClasses)) {
89-
let classRegexp = inferableClasses[key].regexp;
90-
if (tableColumn?.innerText !== undefined) {
91-
if (tableColumn.innerText.match(classRegexp)) {
92-
foundMatch = true;
93-
inferableClasses[key].count++;
58+
try {
59+
const runtimeRegex = /^(\d+h)?\s?(\d+m)?\s?(\d+s)?$/i;
60+
const fileSizeRegex = /^([.0-9]+)\s?(B|KB|KiB|MB|MiB|GB|GiB|TB|TiB)/i;
61+
// Don't infer dates with delimiter "."; as could capture semantic version numbers.
62+
const dmyRegex = /^(\d\d?)[/-](\d\d?)[/-]((\d\d)?\d\d)/;
63+
const ymdRegex = /^(\d\d\d\d)[/-](\d\d?)[/-](\d\d?)/;
64+
// const numericRegex = /^(?:\(\d+(?:\.\d+)?\)|-?\d+(?:\.\d+)?)$/; doesn't handle commas
65+
const numericRegex =
66+
/^-?(?:\d{1,3}(?:[',]\d{3})*(?:\.\d+)?|\d+(?:\.\d+)?(?:[',]\d{3})*?)$/;
67+
const inferableClasses = {
68+
runtime: { regexp: runtimeRegex, class: "runtime-sort", count: 0 },
69+
filesize: { regexp: fileSizeRegex, class: "file-size-sort", count: 0 },
70+
dmyDates: { regexp: dmyRegex, class: "dates-dmy-sort", count: 0 },
71+
ymdDates: { regexp: ymdRegex, class: "dates-ymd-sort", count: 0 },
72+
numericRegex: { regexp: numericRegex, class: "numeric-sort", count: 0 },
73+
};
74+
let classNameAdded = false;
75+
let regexNotFoundCount = 0;
76+
const threshold = Math.ceil(tableRows.length / 2);
77+
for (let tr of tableRows) {
78+
if (regexNotFoundCount >= threshold) {
79+
break;
80+
}
81+
const tableColumn = tr
82+
.querySelectorAll("td")
83+
.item(
84+
column.span[columnIndex] === 1
85+
? column.spanSum[columnIndex] - 1
86+
: column.spanSum[columnIndex] - column.span[columnIndex]
87+
);
88+
let foundMatch = false;
89+
for (let key of Object.keys(inferableClasses)) {
90+
let classRegexp = inferableClasses[key].regexp;
91+
if (tableColumn.innerText !== undefined) {
92+
if (tableColumn.innerText.match(classRegexp)) {
93+
foundMatch = true;
94+
inferableClasses[key].count++;
95+
}
96+
}
97+
if (inferableClasses[key].count >= threshold) {
98+
th.classList.add(inferableClasses[key].class);
99+
classNameAdded = true;
100+
break;
94101
}
95102
}
96-
if (inferableClasses[key].count >= threshold) {
97-
th.classList.add(inferableClasses[key].class);
98-
classNameAdded = true;
103+
if (classNameAdded) {
99104
break;
100105
}
106+
if (!foundMatch) {
107+
regexNotFoundCount++;
108+
continue;
109+
}
101110
}
102-
if (classNameAdded) {
103-
break;
104-
}
105-
if (!foundMatch) {
106-
regexNotFoundCount++;
107-
continue;
108-
}
111+
} catch (e) {
112+
console.log(e);
109113
}
110114
}
111115

0 commit comments

Comments
 (0)