Skip to content

Commit

Permalink
Add bitcoin and ethereum currency signs.
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeWannacott committed Mar 30, 2024
1 parent c316566 commit f06002c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
21 changes: 10 additions & 11 deletions public/table-sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
const dmyRegex = /^(\d\d?)[/-](\d\d?)[/-]((\d\d)?\d\d)/;
const ymdRegex = /^(\d\d\d\d)[/-](\d\d?)[/-](\d\d?)/;
const numericRegex =
/^-?(?:[$£€¥₩₽₺₣¤¿\u20A1\uFFE0]\d{1,3}(?:[',]\d{3})*(?:\.\d+)?|\d+(?:\.\d+)?(?:[',]\d{3})*?)$/;
/^-?(?:[$£€¥₩₽₺₣฿₿Ξξ¤¿\u20A1\uFFE0]\d{1,3}(?:[',]\d{3})*(?:\.\d+)?|\d+(?:\.\d+)?(?:[',]\d{3})*?)$/;


const inferableClasses = {
runtime: { regexp: runtimeRegex, class: "runtime-sort", count: 0 },
Expand All @@ -92,11 +93,11 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
for (let key of Object.keys(inferableClasses)) {
let classRegexp = inferableClasses[key].regexp;
let columnOfTd = testingTableSortJS
? tableColumn.textContent
: tableColumn.innerText;
if (columnOfTd !== undefined && columnOfTd.match(classRegexp)) {
foundMatch = true;
inferableClasses[key].count++;
? tableColumn.textContent
: tableColumn.innerText;
if (columnOfTd !== undefined && columnOfTd.match(classRegexp) ) {
foundMatch = true;
inferableClasses[key].count++;
}
if (inferableClasses[key].count >= threshold) {
th.classList.add(inferableClasses[key].class);
Expand Down Expand Up @@ -359,13 +360,10 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
}

function handleNumbers(str1, str2) {
const currencyAndComma = /[$£€¥₩₽₺₣¤¿\u20A1\uFFE0, ]/g;
const currencyAndComma = /[$£€¥₩₽₺₣฿₿Ξξ¤¿\u20A1\uFFE0, ]/g
str1 = str1.replace(currencyAndComma, "");
str2 = str2.replace(currencyAndComma, "");
const [num1, num2] = [
parseNumberFromString(str1),
parseNumberFromString(str2),
];
const [num1, num2] = [parseNumberFromString(str1),parseNumberFromString(str2)];

if (!isNaN(num1) && !isNaN(num2)) {
return num1 - num2;
Expand Down Expand Up @@ -566,6 +564,7 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
}
timesClickedColumn += 1;


const hasThClass = {
dataSort: th.classList.contains("data-sort"),
fileSize: th.classList.contains("file-size-sort"),
Expand Down
4 changes: 2 additions & 2 deletions test/table.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ test("numeric-sort - various currency", () => {
"-£481,177",
"$2.01",
"$2.11",
"$2.21",
"฿2.21",
"-£1,976,799",
"£2,265",
"(£420,252)",
Expand All @@ -661,7 +661,7 @@ test("numeric-sort - various currency", () => {
"-¥2.02",
"$2.01",
"$2.11",
"$2.21",
"฿2.21",
"$4.64",
"£2,265",
"£2,038,720",
Expand Down

0 comments on commit f06002c

Please sign in to comment.