table-sort-js
Advanced tools
Comparing version 1.20.0 to 1.21.0
{ | ||
"name": "table-sort-js", | ||
"version": "1.20.0", | ||
"version": "1.21.0", | ||
"description": "A JavaScript client-side HTML table sorting library with no dependencies required.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -24,9 +24,9 @@ ![npm version](https://img.shields.io/npm/v/table-sort-js) | ||
```javascript | ||
<script src="https://cdn.jsdelivr.net/npm/table-sort-js/table-sort.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/table-sort-js/table-sort.min.js"></script> | ||
``` | ||
Or Minified (smaller size, but harder to debug!): | ||
Or non-minified version (larger size, but easier to debug!): | ||
```javascript | ||
<script src="https://cdn.jsdelivr.net/npm/table-sort-js/table-sort.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/table-sort-js/table-sort.js"></script> | ||
``` | ||
@@ -76,3 +76,4 @@ | ||
| ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | | ||
| "numeric-sort" | Sorts numbers including decimals - Positive, Negative (in both minus and parenthesis representations) | | ||
| "numeric-sort" | Sorts numbers including decimals - Positive, Negative (in both minus and parenthesis representations). | | ||
| | Supports common currencies e.g ($£€¥) and percentage signs e.g (0.39%) | | ||
| "dates-dmy-sort" | Sorts dates in dd/mm/yyyy format. e.g (18/10/1995). Can use "/" or "-" as separator. | | ||
@@ -79,0 +80,0 @@ | "dates-ymd-sort" | Sorts dates in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) yyyy/mm/dd format. e.g (2021/10/28). Use "/" or "-" as separator. | |
@@ -67,5 +67,5 @@ /* | ||
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})*?)$/; | ||
/^-?(?:[$£€¥₩₽₺₣฿₿Ξξ¤¿\u20A1\uFFE0]\d{1,3}(?:[',]\d{3})*(?:\.\d+)?|\d+(?:\.\d+)?(?:[',]\d{3})*?)(?:%?)$/; | ||
const inferableClasses = { | ||
@@ -95,7 +95,8 @@ runtime: { regexp: runtimeRegex, class: "runtime-sort", count: 0 }, | ||
let classRegexp = inferableClasses[key].regexp; | ||
if (tableColumn.innerText !== undefined) { | ||
if (tableColumn.innerText.match(classRegexp)) { | ||
foundMatch = true; | ||
inferableClasses[key].count++; | ||
} | ||
let columnOfTd = testingTableSortJS | ||
? tableColumn.textContent | ||
: tableColumn.innerText; | ||
if (columnOfTd !== undefined && columnOfTd.match(classRegexp)) { | ||
foundMatch = true; | ||
inferableClasses[key].count++; | ||
} | ||
@@ -346,3 +347,3 @@ if (inferableClasses[key].count >= threshold) { | ||
str = str.slice(0, str.indexOf("#")); | ||
if (str.match(/^\((\d+(?:\.\d+)?)\)$/)) { | ||
if (str.match(/^\(-?(\d+(?:\.\d+)?)\)$/)) { | ||
num = -1 * Number(str.slice(1, -1)); | ||
@@ -364,7 +365,9 @@ } else { | ||
function handleNumbers(str1, str2) { | ||
let num1, num2; | ||
str1 = str1.replaceAll(",", ""); | ||
str2 = str2.replaceAll(",", ""); | ||
num1 = parseNumberFromString(str1); | ||
num2 = parseNumberFromString(str2); | ||
const matchCurrencyCommaAndPercent = /[$£€¥₩₽₺₣฿₿Ξξ¤¿\u20A1\uFFE0,% ]/g; | ||
str1 = str1.replace(matchCurrencyCommaAndPercent, ""); | ||
str2 = str2.replace(matchCurrencyCommaAndPercent, ""); | ||
const [num1, num2] = [ | ||
parseNumberFromString(str1), | ||
parseNumberFromString(str2), | ||
]; | ||
@@ -371,0 +374,0 @@ if (!isNaN(num1) && !isNaN(num2)) { |
30427
591
93